create a function that generates a binary offset carrier wave modulation in matlab

Here's an implementation of a Matlab function that generates a binary offset carrier wave modulation:

main.m
function [modulated_signal] = gen_boc_modulation(bits, fc, fd, Fs)
% Generates a binary offset carrier wave modulation
% bits: sequence of binary data, 1s and 0s
% fc: carrier frequency
% fd: data frequency
% Fs: sampling frequency
% modulated_signal: the modulated signal

t = 0 : 1/Fs : length(bits)/fd;
boc_signal = sign(cos(2*pi*fc*t) + bits.*cos(2*pi*(fc-fd)*t));
modulated_signal = (boc_signal + 1)/2;
408 chars
12 lines

To use the function, simply call it with the appropriate input arguments:

main.m
bits = [1 0 0 1 0 1 1 0 1 1]; % binary data (e.g., message to transmit)
fc = 1000; % carrier frequency
fd = 10; % data frequency
Fs = 10000; % sampling frequency

modulated_signal = gen_boc_modulation(bits, fc, fd, Fs);
220 chars
7 lines

The modulated_signal output variable contains the resulting modulated signal. Note that this implementation assumes binary data (1s and 0s), and uses a BOC modulation technique that combines a cosine wave with a version modulated by the data sequence.

gistlibby LogSnag