Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ASS 2

1.c

Linearity:

clc;clear all;close all

B=[1.2503 2.2368 2.5689];A=[1 -0.435 0.5];

N=1:50;

x1=sin(2*pi*0.02*N);

x2=sin(2*pi*0.01*N);

y1=filter(B,A,x1);

y2=filter(B,A,x2);

y3=filter(B,A,x1+x2);

subplot(311);stem(N,y1+y2);title('Sum of transformed signals-3');grid on;

subplot(312);stem(N,y3);title('transform of summed signals-3');grid on;

AY=[-5 5];

subplot(313);stem(N,y3-(y1+y2));ylim(AY);title('difference-3');grid on;

Time Inv:

clc;clear all;close all

%B=[0.5 -2 5];A=[1];

%B=[0 0 -6]; A=[1];

B=[1.2503 2.2368 2.5689]; A=[1 -0.435 0.5];

N=1:50;

x1=sin(2*pi*0.02*N);

y1=filter(B,A,x1);

y1=[0 y1];

y2=filter(B,A,[0 x1]);

N=1:51;

subplot(311);stem(N,y1);title('Sum of transformed signals tiv-3');grid on;

subplot(312);stem(N,y2);title('transform of summed signals tiv-3');grid on;

AY=[-5 5];
subplot(313);stem(N,y2-y1);ylim(AY);title('difference tiv-3');grid on;

2.

Linearity:

clc ;clear all;close all;

B=input('Enter constant, b : ');

A=input('Enter coefficient of x(n), a: ');

N=1:50;

x1=sin(2*pi*0.02*N);

x2=sin(2*pi*0.01*N);

y1(1:50)=A*x1(1:50)+ B;

y2(1:50)=A*x2(1:50)+ B;

x3=x1+x2;

y3(1:50)=A*x3(1:50)+ B;

N=1:50;

N=1:50;

subplot(311);stem(N,y2+y1),title('sum of transformed signal-lin-q2');grid on;

subplot(312);stem(N,y3);title('transformed of summed signal-lin-q2');grid on;

subplot(313);stem(N,y3-(y1+y2));title('difference-lin-q2');grid on;

Time Inv:

B=input('Enter constant, b : ');

A=input('Enter coefficient of x(n), a: ');

N=1:50;

x1=sin(2*pi*0.02*N);

y1=A*x1+ B;

y1=[0 0 y1];

x1=[0 0 x1];

y2=A*x1+ B;
N=1:52;

subplot(311);stem(N,y1),title('shift of transformed signal-tiv-q2');grid on;

subplot(312);stem(N,y2);title('transformed of shifted signal-tiv-q2');grid on;

subplot(313);stem(N,y2-y1);title('difference-tiv-q2');grid on;

3.

Lin:

clc;clear all; close all;

B=input('Enter coefficient of x(n), b : ');

A=input('Enter coefficient of y(n-1), a : ');

N=1:50;

x1=sin(2*pi*0.02*N);x1=[0 x1];

x2=sin(2*pi*0.01*N);x2=[0 x2];

y1=[zeros(1,51)];

y2=y1;y3=y1;%y4=y1;

y1(2:51)=A*y1(1:50)+ B*x1(2:51);

y2(2:51)=A*y2(1:50)+ B*x2(2:51);

x3=x1+x2;

y3(2:51)=A*y3(1:50)+ B*x3(2:51);

%N=1:50;

% y4(N+1)=A*y4(N)+ B*x1(N+1);

% y4=[0 0 y4];

% x2=[0 0 x1];y5=[0 0 y1];

% y5(N+3)=A*y5(N+1)+ B*x2(N+3);

N=1:51;

subplot(311);stem(N,y1+y2),title('sum of transformed signal-lin-q3');xlabel('time');

ylabel('amplitude');grid on;

subplot(312);stem(N,y3);title('transformed of summed signal-lin-q3');xlabel('time');


ylabel('amplitude');grid on;

Ay=[-5 5];

subplot(313);stem(N,y3-y1-y2);title('difference-lin-q3');grid on;

Time Inv:

clc;clear all; close all;

B=5;

A=3;

N=1:50;

x1=sin(2*pi*0.02*N);x1=[0 x1];

%x2=sin(2*pi*0.01*N);x2=[0 x2];

y3=[zeros(1,51)];

y2=y3;y1=y3;

N=1:50;

y1(N+1)=A*y1(N)+ B*x1(N+1);

y1=[0 0 y1];

x2=[0 0 x1];y2=[0 0 y3];

y2(N+3)=A*y2(N+1)+ B*x2(N+3);

N=1:53;

subplot(311);stem(N,y1),title('sum of transformed signal-tiv-q3');xlabel('time');

ylabel('amplitude');grid on;

subplot(312);stem(N,y2);title('transformed of summed signal-tiv-q3');xlabel('time');

ylabel('amplitude');grid on;

Ay=[-5 5];

subplot(313);stem(N,y2-y1);title('difference-tiv-q3');grid on;

4.a
clc;
clear all;
close all;
x=[1 2 3 4];
h=[1 1 1 1];
N=length(x)+length(h)-1;
y1=conv(x,h);
subplot(311) ;
stem(x) ;

subplot(312) ;
stem(h) ;

subplot(313) ;
stem(y1) ;

4.b
clc;
clear all;
close all;

x=[3 1 2 1];
n1 = -2:1:1 ;

h=[1 1 1];
n2=0:1:2 ;

n=-2:1:8 ;

N=length(x)+length(h)-1;
x1=[x zeros(1,N-length(x))] ;
h1=[h zeros(1,N-length(h))] ;
y=[zeros(1,N)] ;
y=conv(x1,h1);
ax=[-2 3] ;
subplot(311) ;
stem(n1,x) ;

subplot(312) ;
stem(n2,h) ;

subplot(313) ;
stem(n,y) ;
xlim(ax) ;

5.i
clc;
clear all ;
close all ;

x=[1 2 3 4]; h=[1 1 1 1];


k=length(x);j=length(h);
N=k+j-1;
hrev=fliplr(h);
y=zeros(1,N);
x=[zeros(1,N-k) x];
hrev=[hrev zeros(1,N-j)];
subplot(311);stem(0:N-1,x);

for m=1:7
y(m)=sum(x(1:N).*hrev(1:N));
hrev=[zeros(1) hrev];
subplot(312),stem(-3:3,hrev(1:N));
subplot(313),stem(0:N-1,y)
pause(1);
end

5.ii

6.

clc;
clear all;
close all;

x=[3,2,1,1];
n1=-2:1:1;
l1=length(x);

h=[1,1,1];
n2=0:1:2;
l2=length(h);

l3=l1+l2-1;
n=-2:1:3 ;
x1=[x zeros(1,l3-l1)];
h1=[h zeros(1,l3-l2)];
y=[zeros(1,l3)];

for i=1:l3
for j=1:i
y(i)=y(i)+x1(j)*h1(i-j+1) ;

end
end

%y=ifft(fft(x,l3).*(fft(h,l3))) ; //fast fourier transformation

subplot(3,1,1)
stem(n1,x);
%xlim(l3) ;
xlabel('time');
ylabel('amplitude');
title('Signal 1');
grid on;

subplot(3,1,2)
stem(n2,h);
xlabel('time');
ylabel('amplitude');
title('Signal 2');
grid on;

subplot(3,1,3)
stem(n,y);

xlabel('time');
ylabel('amplitude');
title('Convulated Signal');
grid on;

7.
clc;
clear all;
close all ;

syms n w a ;
x=0.5^n;
y=ztrans(x);
pretty(y) ;

x=exp(1i*w*n);
y=ztrans(x);
pretty(y) ;

x=sin(w*n);
y=ztrans(x);
pretty(y) ;

x=a^n*(cos(w*n));
y=ztrans(x);
pretty(y) ;
8.
9.

You might also like