spectral analysis of time versus signal data using FFT
14 views (last 30 days)
Show older comments
2one
on 21 Jun 2012
Answered: Muhammad Zeeshan Ahmed Khan
on 3 Jan 2022
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
Accepted Answer
Wayne King
on 21 Jun 2012
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.
More Answers (2)
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
Muhammad Zeeshan Ahmed Khan
on 3 Jan 2022
TRY THESE OPTIONS
rng('default')
fs = 256; % sample frequency (Hz)
t = 0:1/fs:10-1/fs; % 10 second span time vector
x = Q1data;
y = fft(x);
n = length(x); % number of samples
f = (0:n-1)*(fs/n); % frequency range
power = abs(y).^2/n; % power of the DFT
figure;
plot(f,power)
xlabel('Frequency')
ylabel('Power')
y0 = fftshift(y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
figure;
plot(f0,power0)
xlabel('Frequency')
ylabel('Power')
m = length(Q1data); % original sample length
n = pow2(nextpow2(m)); % transform length
y = fft(Q1data,n); % DFT of signal
f = (0:n-1)*(fs/n)/10;
power = abs(y).^2/n;
figure;
plot(f(1:floor(n/2)),power(1:floor(n/2)))
xlabel('Frequency')
ylabel('Power')
0 Comments
See Also
Categories
Find more on Spectral Measurements 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!