How to convert time domain to frequency domain using FFT

8 visualizzazioni (ultimi 30 giorni)
I have the data in time domain. I want to convert it into frequency domain. Can someone please provide a code for the sam? Thankyou. It will be a great help

Risposta accettata

KSSV
KSSV il 27 Mag 2020
Modificato: KSSV il 27 Mag 2020
data = importdata("before test.txt") ;
t = data(:,1) ;
amp = data(:,2) ;
dt = unique(diff(t)) ; % time step
Fs = 1/dt ; % sampling frequency
L = length(t) ;
Y = fft(amp) ;
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
subplot(121)
plot(t,amp) ;
xlabel('time')
ylabel('amp')
%
subplot(122)
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
  5 Commenti
Leen Mazen
Leen Mazen il 24 Ott 2021
Dear KSSV
Thanks for code , but could you please explain below (p1 and p2):
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
what is the required to use it ?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by