How to convert time domain to frequency domain using FFT

조회 수: 7 (최근 30일)
Sanketh Shetty
Sanketh Shetty 2020년 5월 27일
댓글: Leen Mazen 2021년 10월 24일
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
KSSV
KSSV 2020년 5월 27일
Thanks is accepting the answer.
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