Sinc function doesnt look good
Show older comments
Hello so I have the code below :
clear all;
clc;
Fs = 100;
Ts = 1/Fs;
t=-1:Ts:1;
%u(t-0.5)
step = zeros(size(t));
step(t>0.5) = -1;
figure
grid
subplot(3,2,1)
plot(t,step)
title ('u(t-0.5)')
%u(t+0.5)
step2 = zeros(size(t));
step2(t>-0.5)= 1;
grid
subplot(3,2,2)
plot(t,step2)
title ('u(t+0.5)')
xt=step2+step;
dt = 1/100;
grid
subplot(3,1,3)
plot(t,xt)
title ('u(t+0.5)-u(t-0.5)')
y = conv(xt,xt)*dt;
t3 = -2 :Ts:2;
grid
figure
subplot(2,1,1)
plot(t3,y)
title('first convo')
z = conv (y,xt )*dt;
t4= -3:Ts:3;
dw=1/100;
grid
subplot(2,1,2)
plot(t4,z)
title('second convo')
q = conv(z,xt)*dt;
t5 = -4:Ts:4;
grid
figure
plot(t5,q)
title('third convo')
nfft1=length(xt)*32;
XT=fft(xt,nfft1)*dw;
XT=fftshift(XT);
F=-Fs/2:Fs/nfft1:Fs/2-Fs/nfft1;
grid
figure
plot(F,abs(XT));
title('xt in freq')
nfft2=length(y)*32;
Y = fft(y,nfft2)*dw;
Y = fftshift(Y);
F=-Fs/2:Fs/nfft2:Fs/2-Fs/nfft2;
grid
figure
plot(F,abs(Y))
title('first convolution in freq')
nfft3=length(z)*32;
Z=fft(z,nfft3)*dw;
Z=fftshift(Z);
F=-Fs/2:Fs/nfft3:Fs/2-Fs/nfft3;
grid
figure
plot(F,abs(Z))
title('second convolution in freq')
nfft4=length(q)*32;
Q=fft(q,nfft4)*dw;
Q=fftshift(Q);
F=-Fs/2:Fs/nfft4:Fs/2-Fs/nfft4;
grid
figure
plot(F,abs(Q))
title('third convolution in freq')
XT is a sinc function as it turned out on paper but when I plot it it doesnt look like a sinc function . Is the code wrong or is it right and that's how it's supposed to look ?
Answers (0)
Categories
Find more on Mathematics 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!