I will start out by noting that this is a homework assignment. I'm not asking for anyone to do the assignment for me and I will demonstrate that I've been doing work here, but I've run into an issue that I can't seem to figure out. I am new to MATLAB, so that could be related to some of my issues.
I am attempting to perform MFSK on a given set of data using MATLAB. I am running into an issue when trying to calculate the actual signals. When I attempt to find the arccos() I am given strange results (including what appear to be imaginary numbers) that I can't plot. I will provide these results after my code.
I am given the following data:
10 01 01 01 10 10 01 11
I am to create four (M = 4) signals with
fc = 5 KHz and fd = 500 Hz.
To create the four (M = 4) signals, I am to use equation 7.3, which can be seen here:
Finally, I am to sample the FSK signal representing the two-bit pattern and plot the samples. Assume a time period of 1 ms for each symbol.
What I have done so far: Based on equation 7.3 I have initialized fc, fd, and M. I loop from 1 to 4 (inclusive) and calculate fi. This results in four values: 3500, 4500, 5500, 6500. As per my understanding, '00' should correspond to 3500, '01' to 4500, '10' to 5500, and '11' to 6500.
Using these values, I can now apply them to equation 7.3. I loop through the FSK signal (mfsk) and for each two-bit sample I run equation 7.3. This is the Acos(2 * pi * fi * t) equation. Based on my understanding, if the current sample is '01' I would use 4500, for instance.
This method is giving me strange results that I do not understand.
My code is as follows:
mfsk = {'10', '01', '01', '01', '10', '10', '01', '11'};
fc = 5000;
fd = 500;
M = 4;
fi = [];
%Equation 7.3 used to create 4 M=4 signals
%fi(1) = '00', %fi(2) = '01', %fi(3) = '10', %fi(4) = '11'
for i = 1:4
fi = [fi, fc + ((2 * i) - 1 - M) * fd];
end
mfskSample = [];
for t = 1:8
if char(mfsk(t)) == '00'
mfskSample = [mfskSample, acosd(2 * pi * fi(1) * t)];
elseif char(mfsk(t)) == '01'
mfskSample = [mfskSample, acosd(2 * pi * fi(2) * t)];
elseif char(mfsk(t)) == '10'
mfskSample = [mfskSample, acosd(2 * pi * fi(3) * t)];
else
mfskSample = [mfskSample, acosd(2 * pi * fi(4) * t)];
end
end
Results:
mfskSample =
1.0e+02 *
Columns 1 through 6
0.0000 + 6.3848i 0.0000 + 6.6669i 0.0000 + 6.8993i 0.0000 + 7.0641i 0.0000 + 7.3069i 0.0000 + 7.4114i
Columns 7 through 8
0.0000 + 7.3847i 0.0000 + 7.6719i
Any help is appreciated and thank you for your time.
There are two major problems with your program.
cos
instead of acosd
. But I believe you were trying to type the amplitude mentioned in the book. Here is some code that may satisfy your need....
mfsk = {'10', '01', '01', '01', '10', '10', '01', '11'};
nfsk = length(mfsk); % length of mfsk string
fc = 5000;
fd = 500;
M = 4;
%Equation 7.3 used to create 4 M=4 signals
%fi(1) = '00', %fi(2) = '01', %fi(3) = '10', %fi(4) = '11'
fi = fc + ((2 * (1:M) ) - 1 - M) * fd;
tbit = 5e-3; % time per fsk bit [seconds]
nbit = tbit*fc*5; % # data points in one fsk bit, including Nyquist factor
tSample = linspace(0,nfsk*tbit, 1+nfsk*nbit);
% find frequency fi for every time points
freqSample = 0*tSample;
for nn = 1:nfsk
nCurrentBit = (1+(nn-1)*nbit) : (nn*nbit);
switch char(mfsk(nn))
case '00'
fCurrentBit = fi(1);
case '01'
fCurrentBit = fi(2);
case '10'
fCurrentBit = fi(3);
case '11'
fCurrentBit = fi(4);
otherwise % wrong mfsk code
fCurrentBit = 0;
end
freqSample(nCurrentBit) = fCurrentBit;
end
freqSample(end) = freqSample(end-1);
% evaluate carrier signal on each time point
A = 1; % amplitude
mfskSample = cos(2*pi * freqSample .* tSample);
plot(tSample, mfskSample)