fft
6 views (last 30 days)
Show older comments
A very fundamental doubt... I have a a signal as a 2xN array. The first row contains the time instants at which samples have been taken and the second row contains the data values at those sampling instants. Now when i take the fft of the data values, how do i map the corresponding time values in frequency domain. As in, i wish to plot the fft vs frequeny. How do i obtain the frequency axis?
code which i have used
Fs=500; L=length(sym_signal); y=sym_signal(7,:); NFFT = 2^nextpow2(L); % Next power of 2 from length of y Y = fft(y,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1); plot(f(1:100),2*(abs(Y(1:100))));
The Fs which i have used is obtained by finding the reciprocal time interval between two consecutive time values. Is this the correct way of doing it?
3 Comments
Ashish Uthama
on 6 Jul 2011
Please consider using a more descriptive title and formatting the code.
Are you saying that your sampling is not uniform? A naive approach might be to resample/interpolate the data to obtain uniform sampling (and thus, a constant Ts). This will introduce some artifacts, and I am sure there are better ways.
Accepted Answer
Paulo Silva
on 5 Jul 2011
%Your data 2xN
t=1:0.001:10;
data=[t;sin(2*pi*50*t)+2*randn(size(t))];
%notice the sin+noise, noise added just for fun
Ts = data(1,2)-data(1,1); % Sample time
Fs = 1/Ts; % Sampling frequency
L = numel(t); % Length of signal
y = data(2,:); % data from signal
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
figure %create another figure for the other plot
% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
2 Comments
Ashish Uthama
on 6 Jul 2011
Paulo, my guess is that the user has non-uniform sampling, or something like:
t =[ 1 2 3 5 6 8 10..]
More Answers (0)
See Also
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!