spectral analysis of time versus signal data using FFT
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
2one
am 21 Jun. 2012
Beantwortet: Muhammad Zeeshan Ahmed Khan
am 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 Kommentare
Akzeptierte Antwort
Wayne King
am 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.
Weitere Antworten (2)
Wayne King
am 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 Kommentare
Muhammad Zeeshan Ahmed Khan
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!