To define the frequency range when we use FFT

조회 수: 16 (최근 30일)
Pouyan Msgn
Pouyan Msgn 2021년 4월 12일
댓글: Star Strider 2021년 4월 13일
In my code, I've solved a differential equation numerically, now the goal is to use FFT and plot it in order to find the phase frequency of the original equation. I dont know how to define the frequency intervall to plot the Fourier transform of the equation.
clc
clear all
V0=5; b=0.1;
zc=1; k=1; z0=31; Q=10; Om=6;
Z0=(z0-zc)/zc;
v0=4*b*V0/(k*zc*zc);
f=@(t,y) [y(2) -y(1)+Z0-(y(2)/(Q))+v0*(exp(-4*b*y(1))-exp(-2*b*y(1)))+2*cos(Om*t)]';
y0=[0 0];
t=[0 300];
[T,Y]=ode45(f,t,y0,odeset('RelTol',1e-10));
plot(T,Y(:,1),'b')
grid on
xlabel('Time')
ylabel('Amplitude')
F=fft(Y(:,1)/length(Y(:,1)));
F=abs(F);
fq=1./T;
figure
plot(fq,F)
grid on
But I'm sure my fq is not correct! How should I define it ?!

채택된 답변

Star Strider
Star Strider 2021년 4월 12일
First, change ‘t’ to:
t=linspace(0, 300, 600); % Needs To Be Regularly-Spaced
then for a two-sided Fourier transform:
Ts = mean(diff(T));
Fs = 1/Ts;
Fn = Fs/2;
Fv2 = linspace(-Fn, Fn, numel(T));
figure
plot(Fv2, fftshift(F))
grid
or for a one-sided Fourier transform:
Fv = linspace(0, 1, fix(size(Y,1)/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, F(Iv))
grid
.
  댓글 수: 4
Pouyan Msgn
Pouyan Msgn 2021년 4월 13일
what is Fc?
Star Strider
Star Strider 2021년 4월 13일
I assume you mean ‘Fv’.
That is the frequency vector for the one-sided fft. The ‘Iv’ vector are the matching indices into ‘F’. (The ‘Fv2’ vector is the frequency vector for the two-sided fft plot. It does not need an index vector.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by