nlong=1024; xlong=zeros(1,nlong); hlong=xlong; n1=6; n2=8; x=ones(1,n1); alfa=0.5; h=alfa.^(0:n2-1); for i=1:n1, xlong(i)=x(i); end for i=1:n2, hlong(i)=h(i); end y=conv(x,h); Xlong=fft(xlong); Hlong=fft(hlong); x1=[x zeros(1,max(0,n2-n1))]; h1=[h zeros(1,max(0,n1-n2))]; X1=fft(x1); H1=fft(h1); Y1=X1.*H1; Y=fft(y); Ylong=Xlong.*Hlong; figure(1); gh1=subplot(1,3,1); xflong=(-pi:2*pi/length(Xlong):pi-2*pi/length(Xlong))+pi; set(gh1,'Xlim',[0,6.28]); hold on plot(xflong,abs(Xlong),'k'); title('X(\Omega)'); xlabel('\Omega'); gh2=subplot(1,3,2); hflong=(-pi:2*pi/length(Hlong):pi-2*pi/length(Hlong))+pi; set(gh2,'Xlim',[0,6.28]); hold on plot(hflong,abs(Hlong),'k'); title('H(\Omega)'); xlabel('\Omega'); gh3=subplot(1,3,3); yflong=(-pi:2*pi/length(Ylong):pi-2*pi/length(Ylong))+pi; set(gh3,'Xlim',[0,6.28]); hold on plot(yflong,abs(Ylong),'k'); title('Y(\Omega), (*) N=8, (+) N=13, (o) N=16'); xlabel('\Omega'); subplot(1,3,1); x1f=(-pi:2*pi/length(X1):pi-2*pi/length(X1))+pi; stem(x1f,abs(X1),'r*'); subplot(1,3,2); h1f=(-pi:2*pi/length(H1):pi-2*pi/length(H1))+pi; stem(h1f,abs(H1),'r:*'); subplot(1,3,3); y1f=(-pi:2*pi/length(Y1):pi-2*pi/length(Y1))+pi; stem(y1f,abs(Y1),'r:*'); yf=(-pi:2*pi/length(Y):pi-2*pi/length(Y))+pi; stem(yf,abs(Y),'b:+'); figure(2); ghf2=stem(0:length(y)-1,y,'k:'); hold on xlabel('n'); ylabel('y[n]'); y1=ifft(Y1); stem(0:length(y1)-1,abs(y1),'r:*'); n3 = pow2(nextpow2(n1+n2-1)); % Transform length x3=[x zeros(1,n3-n1)]; h3=[h zeros(1,n3-n2)]; X3=fft(x3); H3=fft(h3); Y3=X3.*H3; y3=ifft(Y3); figure(1); subplot(1,3,1); x3f=(-pi:2*pi/length(X3):pi-2*pi/length(X3))+pi; stem(x3f,abs(X3),'k:o'); subplot(1,3,2); h3f=(-pi:2*pi/length(H3):pi-2*pi/length(H3))+pi; stem(h3f,abs(H3),'k:o'); subplot(1,3,3); y3f=(-pi:2*pi/length(Y3):pi-2*pi/length(Y3))+pi; stem(y3f,abs(Y3),'k:o'); figure(2); stem(0:length(y3)-1,y3,'b:+'); set(gca,'Ylim',[0,ceil(max(max(y),max(max(y1),max(abs(y3)))))]); title('(+) convoluzione, (*) DFT N=8, (o) DFT N=16');