How to convert time domain to frequency domain using FFT

7 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2020-5-27
编辑:KSSV 2020-5-27
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 个评论
Leen Mazen
Leen Mazen 2021-10-24
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 ?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by