Search code examples
matlabfrequencytrigonometry

Generating a variable frequency sine wave in Matlab


Title kind of says it all and it seems straightforward, but I am having difficulties.

I would like to create a sine wave that decays in frequency exponentially at a power that I input. I have tried a bunch of different things and I either get gibberish, or what I believe is called an acoustic beat?

Gibberish example

In this example the array multiplier goes from 1->4. When I plot cos(70000000*t) and cos(4*70000000*t) both plots look fine, but the plot in the code below just looks like noise.

t = 1:.0000000004:1.0000004;
multiplier = linspace(1,2,1001).^-2;
reference_signal = cos(700000000*t.*multiplier);
plot(reference_signal)

Beat Example https://i.sstatic.net/IfZnE.jpg

t = 1:.0000000004:1.0000004;
mult = linspace(1,3,1001);
plot(cos(700000000*t.*mult));

Does anyone have any thoughts on how I might create an array that represents a sinewave that is smoothly decaying in frequency exponentially?

Many Thanks


Solution

  • I think your problem is one of sampling - your sampling frequency is too low for the signal you are trying to represent.

    I suggest that you debug by explicitly computing

    freq = 7E8/(2*pi);
    t = 1 + linspace(0, 4E-7, 1001);
    multiplier = linspace(1,2,1001).^2;
    omega_t = 2*pi*freq*t.*multiplier;
    d_omega_t = diff(omega_t);
    plot(d_omega_t);
    

    If d_omega_t becomes greater than pi, you know you have an aliasing problem- you need at least two points per cycle to reproduce a waveform faithfully (Nyquist theorem). This can be solved by using a higher sampling frequency (more points), or a lower frequency.

    As it is, your multipliers of 1 and 4 look OK because the aliasing that is going on is constant - so you don't notice it is a problem.

    update

    I just ran the above with and without the +1 in the time variable - and it makes a big difference. The delta between two adjacent values is

    2*pi*freq*(1 + t(n) - t(n-1)) * (mult(n) - mult(n-1))
    2*pi*freq*(mult(n) - mult(n-1) + (t(n)-t(n-1)) * (mult(n)-mult(n-1))
    

    This is a very large value because 2*pifreq(multi(n)-mult(n-1)) is a very large value.

    When you leave out the +1 and do

    t = linspace(0, 4E-7, 1001);
    multiplier = linspace(1,2,1001).^-2;
    

    things behave themselves as expected - the plot ends up looking like:

    enter image description here