Sine wave with increasing frequencies in Matlab

7.9k Views Asked by At

In my opinion, the following code should produce a sine wave that has a frequency of $2\text{Hz}$ at $t=20$, but when I count the periods between $t=19$ and $t=20$, I count more than 3 periods. What am I doing wrong?

clear all, close all, clc;
t=linspace(0,20,10000);
y=sin(2*pi*(1+(5/100)*t).*t);
plot(t,y);
hold on;

My plot:

2

There are 2 best solutions below

2
On BEST ANSWER

The argument of sine function represents the phase of the wave. In general, to find the frequency of the wave at time 't', you have to differentiate it wrt 't'.

f = (1/2*pi) * d/dt (phase).

However for the phase that linearly varies with time, i.e., frequency being independent of time, you can just divide it by 't'.

f = (1/2*pi) * (1/t) * (phase).

4
On

If you look carefully at

y=sin(2*pi*(1+(5/100)*t).*t);

you'll see that the variable $t$ appears to the second power. You've graphed a section of $$ y = \sin(C t^2) $$ rather than $$ y = \sin(C t). $$

Looking closely at your picture, you can see that the spacing of the "humps" changes from left to right, so what you've shown can't possibly be a true sinusoid.

General matlab debugging hint: it's so easy to do stuff -- especially big stuff, like building large matrices, or functions represented by 100,000 samples --- that it's easy to delude yourself into thinking you must have done it right. Always write your code so that you can look at corresponding small cases during debugging -- 20 samples of a function of low frequency rather than 20,000 samples of a high-freq function, or the 2 x 2 output matrix from a small example rather than the 200 x 200 output from a large one.