Matlab fft function

Posted by CTZStef on Stack Overflow See other posts from Stack Overflow or by CTZStef
Published on 2012-09-30T02:04:11Z Indexed on 2012/09/30 3:37 UTC
Read the original article Hit count: 219

Filed under:
|
|

The code below is from the Matlab 2011a help about fft function. I think there is a problem here : why do they multiply t(1:50) by Fs, and then say it's time in millisecond ? Certainly, it happens to be true in this very particular case, but change the value of Fs to, say, 2000, and it won't work anymore, obviously because of this factor of 2. Right ? Quite misleading, isn't it ? What do I miss ?

Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 1000;                     % Length of signal
t = (0:L-1)*T;                % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); 
y = x + 2*randn(size(t));     % Sinusoids plus noise
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)')

Clearer with this :

fs = 2000;          % Sampling frequency
T = 1 / fs;         % Sample time
L = 1000;           % Length of signal
t2 = (0:L-1)*T;     % Time vector
f = 50;             % signal frequency
s2 = sin(2*pi*f*t2);
figure, plot(fs*t2(1:50),s2(1:50)); % NOT good
figure, plot(t2(1:50),s2(1:50));    % good

© Stack Overflow or respective owner

Related posts about matlab

Related posts about fft