DFT of time domain for step function

北慕城南 提交于 2019-12-14 03:23:05

问题


I have been working on DFT in Matlab recently, here is my code in Matlab. which part of my code has problem, my sampling is wrong??? I'll be grateful if you answer my question:

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]);

meanwhile, I have 2 question about this code: 1- my step function at 0 time, has magnitude of 1/2, but i want my step function at 0 time be 0 instead of 1/2,( such as rectangle shape), but i don't know how to correct it??? 2- when we do DFT, should we use "shift FFT" always???? if you give me your advice about this code i will be really thankful.


回答1:


Heaviside Step Function

MATLAB does define the step function with 1/2 for x=0 (see http://de.mathworks.com/help/symbolic/heaviside.html?refresh=true), if you wish otherwise you could define your own function, maybe like this here?

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

fftshift

No you don't have to use fftshift always, that really depends on what exactly you want to do. In principle, the fft is not very suited for signals like the step function (if you want to do some frequency analysis, in that particular case, I recommend to do analytical ft!). There are many side effects (I don't want to go into that field right now) and fftshift is one of the tools to help deal with those. Read the doc (doc fftshift) and learn more about the ft in general.



来源:https://stackoverflow.com/questions/30838907/dft-of-time-domain-for-step-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!