[Edit: Fix spelling mistakes; no changes to equations or to code.]
your code is good. The unexpected result is due to the math. Consider the following example. I will describe an approach to synthesizing a signal. The approach yields a signal whose frequency increases twice as much as expected. Then I will explain the reason.
I want to generate a sinusoidal signal that starts with frequency f=100 Hz and increases linearly to 200 Hz in 1 second. My mathematical model of the signal is
, where f is a linearly increasing function of time:
. In this case I want f0=100 Hz and k=100 Hz/s, so that the frequency is 200 Hz after 1 second has passed. subplot(211), plot(t,x,'-r'); grid on; xlabel('Time (s)');
subplot(223), plot(t,x,'-r'); grid on; xlabel('Time (s)'); xlim([0 .01])
subplot(224), plot(t,x,'-r'); grid on; xlabel('Time (s)'); xlim([.99 1])
Examination of the two bottom plots shows that the signal frequency is 100 Hz at t=0, as expected, and the frequency is 300 Hz when t=1, which was NOT expected. I expected the frequency to be 200 Hz at t=1.
The explanation for the unexpected result is as follows:
The frequency of a sinusoidal signal equals the rate of change of phase.
where fm is the measured frequency in cycles/s and
is the instantaneous phase, in radians: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1791360/image.png)
In this case,
. Therefore
. Therefore the measured frequency at time t is Note the factor of 2 in the right-most equation above. This factor of 2 explains why the frequency goes up by 200 Hz in 1 second, when we only expected it to go up by 100 Hz.
The explanation above also explains your situation, in which the measured frequency of the signal increases twice as fast as you expected.