DFT of time domain for step function

2019-09-08 19:31发布

问题:

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.