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.