Monday, August 8, 2011

EC 6120 and EC 5102 DSP MATLAB PROGRAMS DAY 3

STABILITY CHECK OF AN LTI SYSTEM WITH IF-ELSE FOR INF=106

clear all; clc; close all

num=[1 0.8];

den=[1 1.5 .9];

%den=[1 1.5 0.9];% stable

%den=[1 1.5 9];% unstable

N=200;

h=impz(num,den,N+1);

sum=0;

n=0:N;

for k=1:N+1

sum=sum+h(k);

if abs(sum)>10^6;

disp('UNSTABLE LTI SYSTEM');

break

end

if abs(h(k))<10^(-6);

disp('STABLE LTI SYSTEM');

break

end

if k==N+1;

disp('STABLE LTI SYSTEM');

end

end

stem(n,h); grid;

disp('Total Sum of impulses ='),

disp(sum)

LINEARITY PROPERY OF A LTI SYSTEM

clear all; clc; close all

%Linearity property of 2 sequences

n=0:40; a=2; b=-3;

x1=cos(2*pi*0.1*n);

x2=cos(2*pi*0.4*n);

x=a*x1+b*x2;

ic=[0 0];% initially relaxed

%ic=[0 2];% initially not relaxed

num=[2.2403 2.4908 2.2403];

den=[1 -0.4 0.75];

y1=filter(num,den,x1,ic);

y2=filter(num,den,x2,ic);

y=filter(num,den,x,ic);

yt=a*y1+b*y2;

d=y-yt;

if abs(sum(sum(d)))<10^(-3)

disp('LTI SYSTEM IS LINEAR')

else

disp('LTI SYSTEM IS NON-LINEAR')

end

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

subplot(3,1,2), stem(n,yt); grid

subplot(3,1,3), stem(n,d); grid

TIME SHIFT-INVARIANCE PROPERY OF A LTI SYSTEM

clear all; clc; close all

%Linearity property of 2 sequences

n=0:40;D=10;

x=3*cos(2*pi*0.1*n)-2*cos(2*pi*0.4*n);

xd=[zeros(1,D) x];

num=[2.2403 2.4908 2.2403];

den=[1 -0.4 0.75];

ic=[0 0];% initially relaxed

%ic=[0 2];% initially not relaxed

y=filter(num,den,x,ic);

yd=filter(num,den,xd,ic);

d=y-yd(1+D:41+D);

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

subplot(3,1,2),stem(yd),grid;

subplot(3,1,3),stem(d),grid;

if abs(sum(sum(d)))<10^(-3)

disp('LTI SYSTEM IS TIME-SHIFT INVARIANT')

else

disp('LTI SYSTEM IS TIME-SHIFT VARIANT')

end

CONVOLUTION PROCESS CLARIFICATION USING FOR LOOP AND IF–ELSE CASES

clear all; clc; close all

% comparison of convolution without command with convolution using the

% 'conv' command to clarify the convolution process

x=[1 4 2 4 1 1];

h=[1 2 3 4 5];

len1=length(x);

len2=length(h);

len=len1+len2-1;

a=fliplr(h);

for i=1:len

c(i)=0;

for j=1:len1

if j>i

continue;

end

if(len2-i+j)<=0

continue;

end

c(i)=c(i)+(x(j)*a(len2-i+j));

end

end

k=1:len;

conv_op1=c(1:len)

subplot(2,1,1),stem(k,conv_op1);

title('Without using "conv" command')

conv_op2=conv(x,h)% uses the filter command internally

subplot(2,1,2),stem(k,conv_op2)

No comments: