本文介绍了Matlab中简单正弦波的傅立叶变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试显示简单的正弦波的频谱,因为我们知道固定频率的单个正弦波必须在其频谱的峰值上,所以我编写了这段代码,但是我无法得到一个峰值,这是我的代码中的错误之处:

I try to show spectrum of simple sin wave as we know a single sin wave with fixed frequency must have on peak in its spectrum I write this code but I can't get this one peak what is wrong in my code:

clc
nsteps=200;%number of signal elements in time domain
i=sqrt(-1);
NFREQS=100;%number of elements in frequency domain
ddx=1e-9;
dt=ddx/(6e8);%separation between each time domain elements
lambdai=150e-9;
lambdaf=500e-9;
freqi=3e8/lambdai;
freqf=3e8/lambdaf;
freq=zeros(1,NFREQS);
for j=1:NFREQS
freq(j)=freqi-j*(freqi-freqf)/NFREQS;%desired frequency domain
end
arg=2*pi*freq*dt;
et=zeros(nsteps,1);
    for j=1:nsteps
       et(j)=sin(2*pi*3e15*j*dt);%sin wave in time domain
    end
e=zeros(NFREQS,1);
for n=1:NFREQS
for j=1:nsteps
 e(n)=e(n)+et(j)*exp(-i*arg(n)*n);%sin wave in frequency domain
end
end
lambda=linspace(lambdai,lambdaf,NFREQS);
plot(lambda,abs(e))

推荐答案

此处的重点是使用window函数.结果代码如下:

The key point in here is using window function. The resulted code is this:

clc
clear
nsteps=40000;
i=sqrt(-1);
Sc=0.5;
ddx=1e-9;
dt=ddx*Sc/(3e8);
lambdai=100e-9;
lambdaf=700e-9;
lambda=lambdai:1e-9:lambdaf;
[m,NFREQS]=size(lambda);

    freq=3e8./lambda;
et=zeros(nsteps,1);
    for j=1:nsteps
       et(j)=sin(2*pi*3e8/(300e-9)*dt*j);%sin wave in time domain
    end
    w=blackman(nsteps);%window function for periodic functions
    for j=1:nsteps
        et(j)=et(j)*w(j);
    end
    e=zeros(1,NFREQS);
    for n=1:NFREQS
        for j=1:nsteps
            e(n)=e(n)+et(j)*exp(-i*2*pi*freq(n)*dt*j);
        end
    end
   plot(lambda,abs(e))

结果是:

这篇关于Matlab中简单正弦波的傅立叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 01:58