## Presentation on theme: "function[y,n]=sigadd(x1,n1,x2,n2)"— Presentation transcript:

%n1:index vector for x1 %n2:index vector for x2 n=min(min(n1),min(n2)):max(max(n1),max(n2));%duration of y(n) y1=zeros(1,length(n)); y2=y1; %initialization y1(find((n>=min(n1))&(n<=max(n1))))=x1; %x1 with duration of y y2(find((n>=min(n2))&(n<=max(n2))))=x2; %x2 with duration of y y=y1+y2;

>> x1=[1 1 1]; >> n1=[2 3 4]; >> x2=[2 2 2]; >> n2=[4 5 6]; >> [y,n]=sigadd(x1,n1,x2,n2) y = n =

function[y,n]=sigmult(x1,n1,x2,n2)
%n1:index vector for x1 %n2:index vector for x2 n=min(min(n1),min(n2)):max(max(n1),max(n2));%duration of y(n) y1=zeros(1,length(n)); y2=y1; %initialization y1(find((n>=min(n1))&(n<=max(n1))))=x1; %x1 with duration of y y2(find((n>=min(n2))&(n<=max(n2))))=x2; %x2 with duration of y y=y1.*y2;

>> [y,n]=sigmult(x1,n1,x2,n2)
n =

function [y,n]=sigshift(x,m,k)
%implements y(n)=x(n-k) %m: index vector for x n=m+k;y=x; >> xn=0:20;x=stepseq(0,0,20); >> [y,yn]=sigshift(x,xn,5); >> subplot(2,1,1),stem(xn,x),title('u(n)'),axis([0 30,0,1]) >> subplot(2,1,2),stem(yn,y),title('u(n-5)'),axis([0 30,0,1])

function [y,n]=sigfold(x,n)
%implements y(n)=x(-n) y=fliplr(x); n=-fliplr(n); >> xn=0:6;x=rampseq(0,0,6); >> [y,yn]=sigfold(x,xn); >> subplot(2,1,1),stem(xn,x),title('ur(n)'),axis([-10,10 ,0,6]) >> subplot(2,1,2),stem(yn,y),title('ur(-n)'),axis([-10,10 ,0,6])

>> n=-2:10;x=[1:7, 6:-1:1];
>> [x11,n11]=sigfold(x,n);[x11,n11]=sigshift(x11,n11,3); >>[x12,n12]=sigshift(x,n,2);[x12,n12]=sigmult(x,n,x12,n12); >> [x1,n1]=sigadd(x11,n11,x12,n12); >> stem(n1,x1)

N=7 >> x=[ ]; >> n=-6:14; >> stem(n,[x x x])

function [xe,xo,l]=evenodd(x,n)
%Real signal decomposition into even and odd parts if any(imag(x)~=0) error('x is not a real signal') end [y,m]=sigfold(x,n); [xe,l]=sigadd(x,n,y,m);xe=xe/2; [xo]=sigadd(x,n,-y,m);xo=xo/2;

>> n=[0:10];x=stepseq(0,0,10)-stepseq(10,0,10);
>> [xe,xo,m]=evenodd(x,n); >> subplot(2,2,1); stem(n,x);title('X(n)'); axis([-10,10,0,1.2]) >> subplot(2,2,2); stem(m,xe);title('Xe(n)'); axis([-10,10,0,1.2]) >> subplot(2,2,4); stem(m,xo);title('Xo(n)'); axis([-10,10,-0.6,0.6])

>> nx=-3:3;X=[1:7];[Y,ny]=sigfold(X,nx);
>> [Y1,ny1]=sigshift(Y,ny,1); >> [X1,nx1]=sigshift(X,nx,1);[Y2,ny2]=sigfold(X1,nx1); >> subplot(2,1,1); stem(ny1,Y1); title('y(n-1)');axis([-4,4,0,8]) >> subplot(2,1,2); stem(ny2,Y2); title('y(n,1)');axis([-4,4,0,8]) y(n)=x(-n) is TIME VARIANT

Similar presentations