How to plot a sinc function correctly?
Show older comments
I am generating a rectangular pulse using a piecewise function on Matlab. I have listened to some advice to use a normalization coefficient and the amplitude appears correct now. However, my issue is that it seems that my Fourier Transform plot is squished at the origin. Can someone point out where did I go wrong? Thank you for taking the time.
My Code:
% Sampling Frequency
fs=1000;
% Time Variables of Piece-wise functions
t1=-1:1/fs:-0.5;
t2=-0.5:1/fs:0.5;
t3=0.5:1/fs:1;
% Evaluations of each time intervals
y1 = zeros(size(t1));
y2 = ones(size(t2));
y3 = zeros(size(t3));
% Combination of the time variables and functions
t=[t1 t2 t3];
f=[y1 y2 y3];
% Plot the rectangular pulse
figure(1);
subplot(1,2,1);
plot(t,f);
% Fourier Transform Plot
subplot(1,2,2);
% Frequency Domain between -10 and 10 using the size of the function (f).
freq=linspace(-10,10,size(f,2));
% Fourier Transform with normalizing coefficient (1/fs).
ft=fftshift(fft(f))./(fs);
plot(freq,abs(ft));
Accepted Answer
More Answers (0)
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

