Effacer les filtres
Effacer les filtres

fft

1 vue (au cours des 30 derniers jours)
Aishanou
Aishanou le 5 Juil 2011
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 commentaires
Aishanou
Aishanou le 5 Juil 2011
Thanks...however my data is taken from experimental results and not generated as sinusoidal function(with or without noise) of time values. Yet, i got the answer for obtaining Fs. Thanks once again.
Ashish Uthama
Ashish Uthama le 6 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Paulo Silva
Paulo Silva le 5 Juil 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 commentaires
Ashish Uthama
Ashish Uthama le 6 Juil 2011
Paulo, my guess is that the user has non-uniform sampling, or something like:
t =[ 1 2 3 5 6 8 10..]
Paulo Silva
Paulo Silva le 6 Juil 2011
in that case he just need to use the interp function

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by