matlabmodulation

MFSK (Multilevel Frequency-Shift Keying) in MATLAB


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:

Equation 7.3

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.


Solution

  • There are two major problems with your program.

    1. The cosine function in Matlab is cos instead of acosd. But I believe you were trying to type the amplitude mentioned in the book.
    2. Consider Nyquist sampling theorem. You carrier frequency is 5k Hz, so your maximum time interval to evaluate the signal si(t) is 0.2 ms. This will ensure you can see complete sinusoidal waves of the carrier. However in order to observe the mfsk codes, you also have to ensure each mfsk bit lasts for enough time; in my case in order to observe it visually I would set the bit length as several complete cycles for the modulating (difference) frequency. Therefore, within the time for a single mfsk bit, there would be several modulation signal cycles and hundreds of carrier signals.

    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)
    

    sample output