如何使用快速傅里叶变换对于MATLAB中的复杂值

时间:2016-03-18 09:20:38

标签: matlab

我解决了微分方程,其解是时域中的复数值。我必须用fft将其转换为频域。我在MATLAB中使用了fft。但答案是不正确的。我不知道如何选择我的频率间隔。时域在-10到60之间,步数为1000.

    function r=fur()
     clc
     clear
     format long
     a =-10;             %tmin
   b=60;               %tmax
   m =1000;             % number of steps
   t=zeros(1,m);
   y=zeros(1,m);


    t(1)=a;            %boundary condition
    y(1)=0;            %boundary condition
    t0=0.01;
    h=(b-a)/m;

for j=1:m
    T=t(j); Y=y(j);
    k1=h*Fun(T,Y);
    k2=h*Fun(T+h/2,Y+k1/2);
    k3=h*Fun(T+h/2,Y+k2/2);
    k4=h*Fun(T+h,Y+k3);
    y(j+1)=Y+(k1+2*k2+2*k3+k4)/6;
    t(j+1)=a+h*(j);
end
% real_y = real(y);
% imag_y = imag(y);
y;


%% Fast Fourier Transformation for  P(W)


NFFT=length(y);
fs=2*pi/h;
X=fftshift(fft(y,NFFT));
fVals=(0:NFFT-1)*fs/NFFT;

figure(1)
plot(fVals,abs(X),'-b');
title('Fast Fourier Transform');         
xlabel('Frequency (THz)')        
ylabel('p(w)');

hold on 



%% Fast Fourier Transformation for  E(W)

NFFT=length(y);

fs=2*pi/h;
Z=fftshift(fft(Et(t,t0), NFFT));
fVals=(0:NFFT-1)*fs/NFFT;


figure (2)
plot(fVals,abs(Z),'-r');
title('Fast Fourier Transform');         
xlabel('Frequency (THz)')        
ylabel('E(w)');
hold on

%% linear suscebtibility

f=X./Z;
f_imag=imag(f);
f_real=real(f);
fVal=(0:NFFT-1)*fs/NFFT;

figure(3)
plot(fVal,f_real,'-r');
title('total part of susceptibility');       
xlabel('Frequency (THz)')        
ylabel('Kappa(w)');
hold on

figure(4);
plot(fVals,f_imag,'-r');
title('imaginary part of susceptibility');       
xlabel('Frequency (THz)')        
ylabel('kappa(w)');
hold on

这是Fun.m

function F=Fun(t,y)
format long
E_g=1.52;   %binding energy for the GaAs
gamma=0.1*E_g;
t0=0.01;%This is a damping operator
k=1;
F=-i*((((k^2)-i*gamma)*y)-Et(t,t0));%F=-i*((-i*gamma)*y-1/2);;

这是Et.m

function e=Et(t,t0)
format long
t0=0.1;
e=(1/2)*(exp(-(t/t0).^2));
end

我非常感谢回答我。

0 个答案:

没有答案