[Math] Sine wave with increasing frequencies in Matlab

MATLABtrigonometry

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:

Best Answer

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.

Related Question