matlab - DFT of time domain for step function -
i have been working on dft in matlab recently, here code in matlab. part of code has problem, sampling wrong??? i'll grateful if answer 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 , shift center 0 figure (2) plot(linspace(-10,10,length(y_freqdomain)),z) xlabel('sample number') ylabel('amplitude') title('using matlab fft command') grid axis([-.3,.3,0,1000]);
meanwhile, have 2 question code: 1- step function @ 0 time, has magnitude of 1/2, want step function @ 0 time 0 instead of 1/2,( such rectangle shape), don't know how correct it??? 2- when dft, should use "shift fft" always???? if give me advice code thankful.
heaviside step function
matlab define step function 1/2
x=0
(see http://de.mathworks.com/help/symbolic/heaviside.html?refresh=true), if wish otherwise define own function, maybe here?
mystep = @(x) sign(max(x, 0));
fftshift
no don't have use fftshift always, depends on want do. in principle, fft not suited signals step function (if want frequency analysis, in particular case, recommend analytical ft!). there many side effects (i don't want go field right now) , fftshift 1 of tools deal those. read doc (doc fftshift
) , learn more ft in general.
Comments
Post a Comment