Something that arises occasionally is that you have a vector of frequencies f, and you want to generate a frequency modulated signal with that frequency. For example, maybe you have a vector of frequency versus time for a shaft, and you are trying to generate a simulated vibration profile that tracks with speed. Your first temptation is going to be sig=sin(2 * pi * f * t), but that will not work. Try the following quick example in matlab: Fs = 1000; t = 0:(1/Fs):10; freq= 6+(t/5).^2; sig = sin( 2 * pi * freq .* t); figure; plot(t, sig); xlim([9.8 10]). You can easily see that freq(end) is 6+(10/5)^2=10, so you'd expect that the last cycle would have a period of 100ms, but in fact it's more like 55ms, which is much too fast.
Here is why: if we have a continuous function f (t), what we really want to plot is sin((t)). How do we get from f (t) to (t)? The answer is not multiply by t, but integrate with respect to time. In other words (t) = 2f ()d. Now, if f (t) = f0, where f0 is a constant, then we have simply (t) = 2f0d = 2f0d = 2f0t. So if our frequency is constant, we can just multiply by t, but if it is non-constant, we have to integrate.
Here's the matlab code you want to use: theta = cumtrapz( t, freq); sig2 = sin( 2 * pi * theta); figure; plot(t, sig2); xlim([9.8 10]). You can see this now gives the expected period for the last cycle.
/' $I