How to convert time domain to frequency domain using FFT

7 visualizaciones (últimos 30 días)
Sanketh Shetty
Sanketh Shetty el 27 de Mayo de 2020
Comentada: Leen Mazen el 24 de Oct. de 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

Respuesta aceptada

KSSV
KSSV el 27 de Mayo de 2020
Editada: KSSV el 27 de Mayo de 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 comentarios
KSSV
KSSV el 27 de Mayo de 2020
Thanks is accepting the answer.
Leen Mazen
Leen Mazen el 24 de Oct. de 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 ?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by