100 likes | 169 Views
>> x=stepseq(0,-5,49)-stepseq(10,-5,49);stem(-5:49,x); title('x(n)'). >>h=[zeros(1,5),0.9.^(0:49)];stem(-5:49,h); title('h(n)'). >> y=[zeros(1,5),10*(1-0.9.^(1:9)),10*(1-0.9^10)*0.9.^(0:40)]; stem(-5:49,y);title('y(n)'). >> nx=-3:3;x=[3,11,7,0,-1,4,2];nh=-1:4;h=[2,3,0,-5,2,1];
E N D
>> x=stepseq(0,-5,49)-stepseq(10,-5,49);stem(-5:49,x); title('x(n)') >>h=[zeros(1,5),0.9.^(0:49)];stem(-5:49,h); title('h(n)')
>> y=[zeros(1,5),10*(1-0.9.^(1:9)),10*(1-0.9^10)*0.9.^(0:40)]; stem(-5:49,y);title('y(n)')
>> nx=-3:3;x=[3,11,7,0,-1,4,2];nh=-1:4;h=[2,3,0,-5,2,1]; >> subplot(2,1,1); stem(nx,x);axis([-5,5,-5.5,11.5]);title('x(n)') >> subplot(2,1,2); stem(nh,h);axis([-5,5,-5.5,11.5]);title('h(n)')
>> [h1,nh1]=sigfold(h,nh);[h2,nh2]=sigshift(h1,nh1,-1); >> subplot(2,1,1); stem(nx,x);axis([-5,5,-5.5,11.5]);title('x(k)') >> subplot(2,1,2); stem(nh2,h2);axis([-5,5,-5.5,11.5]);title('h(-1-k)') >> [y,n]=sigmult(x,nx,h2,nh2); >> sum(y) ans = 6
>> [h2,nh2]=sigshift(h1,nh1,2); >> subplot(2,1,1); stem(nx,x);axis([-5,5,-5.5,11.5]);title('x(k)') >> subplot(2,1,2); stem(nh2,h2);axis([-5,5,-5.5,11.5]);title('h(2-k)') >> [y,n]=sigmult(x,nx,h2,nh2); >> sum(y) ans = 41
Convolution in MATLAB y=conv(x,h) * CONV computes the convolution between two finite sequences >> y=conv(x,h) y = 6 31 47 6 -51 -5 41 18 -22 -3 8 2
function [y,ny]=conv_m(x,nx,h,nh) %Modifeid convolution routine for signal processing nyb=nx(1)+nh(1); nye=nx(end)+nh(end); ny=nyb:nye; y=conv(x,h); >> [y,ny]=conv_m(x,nx,h,nh) y = 6 31 47 6 -51 -5 41 18 -22 -3 8 2 ny = -4 -3 -2 -1 0 1 2 3 4 5 6 7
y=filter(b,a,x) b=[b0,b1,…,bM]; a=[a0,a1,…,aN] >> b=[1]; a=[1,-1,0.9]; >> x=stepsep(0,-20,120); s=filter(b,a,x); >> n=-20:120; stem(n,s); title('step response')
>> x=stepseq(0,-5,49)-stepseq(10,-5,49); >> b=[1];a=[1,-0.9];y1=filter(b,a,x); >> y2=[zeros(1,5),10*(1-0.9.^(1:9)),10*(1-0.9^10)*0.9.^(0:40)]; >> n=-5:49; >> subplot(2,1,1); stem(n,y1); title('result via using filter') >> subplot(2,1,2); stem(n,y2); title('result via manual convolution')
h=impz(b,a,n) n: sample indices >> b=[1,2];a=[1,-3,-4]; >> n=0:30; h1=impz(b,a,n); >> h2=-0.2*(-1).^n+1.2*4.^n; >> stem(n,h1'-h2); title('h1(n)-h2(n)')