步进功能的时域DFT

时间:2015-06-15 06:49:43

标签: matlab matlab-figure

我最近在Matlab上开始使用DFT,这是我在Matlab中的代码。我的代码的哪一部分有问题,我的采样是错误的???如果你回答我的问题,我将不胜感激:

dt = 0.01;      %sampling time interval
Fs = 1/dt;       %sampling rate
t = 0:dt:45;     %Time vector
t0 = 5;          %duration of applied stress
N = length(t);   %number of sample points
y_timedomain = heaviside(t)-heaviside(t-t0);     %the step function
figure (1)
plot(y_timedomain)
axis([-100,1000,-0.2,1.2]);
y_freqDomain=abs(fft(y_timedomain));     % fft of step funcion, y(t)
z = fftshift(y_freqDomain);              % DFT and shift center to zero
figure (2)
plot(linspace(-10,10,length(y_freqDomain)),z)
xlabel('Sample Number')
ylabel('Amplitude')
title('Using the Matlab fft command')
grid
axis([-.3,.3,0,1000]);

同时,我有2个关于此代码的问题: 1-我的步进功能在0时,具有1/2的幅度,但我希望我的步进功能在0时为0而不是1/2,(例如矩形),但我不知道如何纠正它??? 2-当我们进行DFT时,我们应该使用"移位FFT"总是???? 如果你给我你对这段代码的建议,我将非常感激。

1 个答案:

答案 0 :(得分:0)

Heaviside Step Function

MATLAB确实使用1/2x=0定义了阶梯函数(参见http://de.mathworks.com/help/symbolic/heaviside.html?refresh=true),如果您希望自己可以定义自己的函数,可能就像这样吗?

mystep = @(x) sign(max(x, 0));

<强> fftshift

不,你不必总是使用fftshift,这实际上取决于你想要做什么。原则上,fft不太适合步进功能之类的信号(如果你想做一些频率分析,在这种特殊情况下,我建议做分析ft!)。有很多副作用(我现在不想进入那个领域)而fftshift是帮助处理这些问题的工具之一。阅读文档(doc fftshift)并了解有关ft的更多信息。