MATLAB Answers

2one
0

spectral analysis of time versus signal data using FFT

Asked by 2one
on 21 Jun 2012
Hi, I have data for time (x) and signal (y) which i've read into an matrix:
time = squeeze(input(1,:)); signal = squeeze(input(2,:));
How can I perform a FFT on this matix data?

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Wayne King
on 21 Jun 2012
 Accepted Answer

It looks like from your squeeze() commands that time and signal are both just row vectors: 1xN
Do you really have a matrix here?
If signal is just a row vector (or column), then just
signalDFT = fft(signal);
gives you the discrete Fourier transform.
If you use fft() on a matrix, it will naturally take the DFT of each column. You don't want to take the Fourier transform of the time vector, that is not going to give you anything useful.
If you really want a time-frequency analysis (spectral information with some time localization), then use spectrogram on the signal vector.

  1 Comment

Thanks, yes you're right.
input(:,:) = fscanf(fid1, '%g %g',[2 inf]);
The initial signal had a sampling freq of 2 Hz and a time from 0 to 200 s.
to calculate the power spectral density i did:
N=401;
Fs = 2.0:
Y = fft(signal, N)
Pyy = Y*conj(Y)/N
f = Fs/N*(0:(N/2)-1);
plot(f, Pyy);
Is this correct?

Sign in to comment.


Answer by Wayne King
on 21 Jun 2012

You don't need to specify N as an input to fft()
Fs = 2;
Y = fft(signal);
Pyy = abs(Y).^2/length(signal);
For the odd length input, make your frequency vector:
freq = 0:Fs/length(x):Fs/2;
Pyy = Pyy(1:round(length(signal)/2));
plot(freq,10*log10(Pyy))
xlabel('Hz'); ylabel('dB/Hz');
Do you have the Signal Processing Toolbox? If so you can just do:
[Pxx,F] = periodogram(signal,[],length(signal),2);
plot(F,10*log10(Pxx))

  0 Comments

Sign in to comment.