spectral analysis of time versus signal data using FFT
19 views (last 30 days)
Show older comments
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?
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)
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));
Do you have the Signal Processing Toolbox? If so you can just do:
[Pxx,F] = periodogram(signal,,length(signal),2);
Muhammad Zeeshan Ahmed Khan on 3 Jan 2022
TRY THESE OPTIONS
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
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
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;
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!