FM Octave Script

Discussion in 'Wireless & RF Design' started by PsySc0rpi0n, Jan 14, 2016.

  1. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Hi everyone...

    I'm trying to find a way to display 3 plots with different time bases so that the modulation can be observed!

    I mean, I want to modulate a carrier signal by a message signal using FM technique but as the message signal frequency is a few thousand times lower than the carrier frequency, I'm not being able to plot the 3 signals, message, carrier and modulated signals in a way that we can observe the modulation effect.

    The signals are:

    m (t) = sin (2*π*fm*t) V, where fm = 10kHz

    c (t) = sin (2*π*fc*t) V, where fc = 10MHz

    The modulated signal is:

    upload_2016-1-14_22-57-42.png

    But I'm using another equation that I suppose to be equivalent to that one!

    y = vc*sin(2*pi*fc*t+m.*sin(2*pi*fM*t));

    the result is this:

    upload_2016-1-14_23-21-9.png


    I don't like any of the results... Not even the message signal looks like a sin wave... Also the amplitude is weird I don't know why!

    If I use lower values, like fm = 8Hz, fc = 100 Hz and modulation index of 10 (same as before) I get a lot better results...

    upload_2016-1-14_23-22-59.png

    Why is this? Why can't I use the script for higher values for frequencies?

    clc
    clear all
    close all

    t = 0:0.001:1; %upto 1000 samples

    vm = input('Enter Amplitude (Message) = ');
    vc = input('Enter Amplitude (Carrier) = ');
    fM = input('Enter Message frequency = ');
    fC = input('Enter Carrier frequency = ');
    m = input('Enter Modulation Index = ');

    msg = vm*sin(2*pi*fM*t);
    subplot(3,1,1); %plotting message signal
    plot(t,msg);
    xlabel('Time');
    ylabel('Amplitude');
    title('Message ');
    grid on;

    carrier = vc*sin(2*pi*fC*t);
    subplot(3,1,2); %plotting carrier signal
    plot(t,carrier);
    xlabel('Time');
    ylabel('Amplitude');
    title('Carrier Signal');
    grid on;

    y = vc*sin(2*pi*fC*t+m.*sin(2*pi*fM*t));
    subplot(3,1,3);%plotting FM (Frequency Modulated) signal
    plot(t,y);
    xlabel('Time');
    ylabel('Amplitude');
    title('FM Signal');
    grid on;
     
  2. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    I think you need a smaller time step at the frequencies of interest.
    Also noticed you have "m." Instead of "m" in your modulation formula.
     
  3. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Hum, I can change the 'm.' to 'm' but I think it changes nothing.

    Regarding the time base being smaller, I think I already tried it but then I'll get an error of vector's sizes mismatch...

    Can you edit the code and change the time base and then I'll try it? Maybe I tried it the wrong way.
     
  4. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    I can't edit your script, but at the top you define your time steps like this:
    t = 0:0.001:1
    Try this instead:
    t = 0:0.0001:1 Or t = 0:0.00001:1
     
  5. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    I meant you to copy my code, edit it and post you version here! But let me try that despite the fact that I think I already tried that but then I had problems of vector's sizes mismatches!
     
  6. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    on second thought, you could try this:
    t = 0:0.00000001:0.001

    this will give you ten cycles of the modulation frequency, which should be more than enough to see the modulation in action. And each carrier frequency cycle will get ten time steps.
     
  7. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3

    But I need to have 't' and 'tdisp' with the same number of elements or the error "vector's sizes mismatches"!!!
     
  8. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    Ok, but I don't see tdisp in the script. What am I missing?
     
  9. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Ok, this is the best I got so far, but I still don't like at all the Carrier wave form at all, don't know why... That looks like noise and noise only!

    upload_2016-1-15_19-55-46.png

    clc
    clear all
    close all

    vm = input('Enter Amplitude (Message) = ');
    vc = input('Enter Amplitude (Carrier) = ');
    fM = input('Enter Message frequency = ');
    fC = input('Enter Carrier frequency = ');
    m = input('Enter Modulation Index = ');

    t = [0:5/fC:5/fM]; %upto 1000 samples

    msg = vm*sin(2*pi*fM*t);
    subplot(3,1,1);
    plot(t,msg);%plotting message signal
    xlabel('Time');
    ylabel('Amplitude');
    title('Message ');
    grid on;

    carrier = vc*sin(2*pi*fC*t);
    subplot(3,1,2);
    plot(t,carrier); %plotting carrier signal
    xlabel('Time');
    ylabel('Amplitude');
    title('Carrier Signal');
    grid on;

    y = vc*sin(2*pi*fC*t+m*sin(2*pi*fM*t));
    subplot(3,1,3);
    plot(t,y); %plotting FM (Frequency Modulated) signal
    xlabel('Time');
    ylabel('Amplitude');
    title('FM Signal');
    grid on;
     
  10. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3

    Yes, you're right... That variable is in another script... Because I was trying to use 2 different time bases. One to the math and one other to the plots but that way I was getting errors of vector's sizes mismatches!


    Right now I just don't like the carrier wave form!
     
  11. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    I'm convinced that what you're seeing is a too slow sampling rate on the carrier signal. The carrier has a period of 10e-6 seconds, or 10 microseconds. Your new script has a time step of only 50 microseconds. So you're only sampling once every five cycles. That's why the plots start out so small. After a number of samples, a bit of rounding error puts the samples at a slightly different place on the carrier wave, so the amplitude goes up a bit. Then after another number of samples it happens again.
    So the only way to fix it is to decrease the time step to get perhaps ten samples per carrier wave period, alternatively, scale your frequencies to be lower, like a 10 kHz carrier and a 10 Hz modulation.
    I recommend t = [0:1/(10*fC):5/fM]
     
    Last edited: Jan 15, 2016
  12. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3

    I think I see the problem, but the weird is that the modulated signal looks good using the same time base!

    So, you say to use a different time base for the carrier and the modulated signal, yes? I can try your suggestion! Let me see what does it turns out!
     
  13. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    I think you misunderstand. I'm suggesting one time base for everything, but I believe the high speed signal drives the time step requirement. So if you have 10 time steps per each carrier cycle, you'll get 10,000 time steps for each modulation signal cycle, which is more than enough.
     
  14. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Ok, this one is done... Thanks...

    I'm now working on ASK scripts!
     
Loading...