How to convert time domain to frequency domain using FFT

7 Ansichten (letzte 30 Tage)
Sanketh Shetty
Sanketh Shetty am 27 Mai 2020
Kommentiert: Leen Mazen am 24 Okt. 2021
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

Akzeptierte Antwort

KSSV
KSSV am 27 Mai 2020
Bearbeitet: KSSV am 27 Mai 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 Kommentare
KSSV
KSSV am 27 Mai 2020
Thanks is accepting the answer.
Leen Mazen
Leen Mazen am 24 Okt. 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 ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by