MATLAB CODE FOR LINEARITY, STABILITY & CAUSALITY



MATLAB PROGRAM TO CHECK LINEARITY, STABILITY & CAUSALITY OF ANY SYSTEM


AIM

Write a MATLAB program to find whether the given systems are linear, stable and causal.
1. y(n) = x(n) – 0.9y(n-1)
2. y(n) = exp x(n)
THEORY

A system is linear if and only if T [a1x1[n] + a2x2n]] = a1T [x1[n]] + a2T [x2[n]], for any arbitrary constants a1 and a2.  Let x[n] be bounded input sequence and h[n] be impulse response of the system and y[n], the output sequence. Necessary and sufficient boundary condition for stability is8n = -8|h[n]| < 8. Causal system is a system where the output depends on past or current inputs but not on the future inputs. The necessary condition is h[n] = 0; < 0, where h[n] is the impulse response.

ALGORITHM

1. Start
2. Input the coefficients of x(n) and y(n)
3. Generate random signals x1 and x2.
4. Check for linearity using filter function of the given system and display 
5. Generate impulse signal.
6. Check for causality using filter function of the given system and display 
7. Obtain the absolute value of impulse response and check for the stability of the system and display.
8. Stop

MATLAB FUNCTIONS USED

• RAND: Uniformly distributed pseudo random numbers. R=RAND (N) returns an N-by-N matrix containing pseudo-random values drawn from a uniform distribution on the unit interval. RAND (M , N)or RAND([M, N]) returns an M-by-N matrix.
• DISP: Display array. DISP(X) displays the array, without printing the array name. In all other ways it‟s the same as leaving the semicolon of  an expression except that empty arrays don‟t display.
• ABS: Absolute value. ABS(X) is the absolute value of the elements of X.
• SUM: Sum of elements. S=SUM(X) is the sum of the elements of the vector X.

PROGRAM

%Program to find linearity of system 1
clc
clear all
close all
 % System 1
% Linearity
b = [1 0];
a = [1 0.9];
 x1 = rand (1,10);
x2 = rand (1,10);
y2 = filter (b, a, 2.*x1);
y5 = filter (b, a,2.* x2);
y = filter (b, a, x1);
y0 = filter (b, a, x2);
y6 = y2+y5;
y7 = y+y0;
if (y6-y7 ~= 0)
disp (' Linear ')
else
disp (' Non Linear ')
end;
 % Causality--------%%%
  n= -10:1:10;
x = [zeros(1,10) 1 zeros(1,10)];
 y1 = filter (a, b, x);
subplot (2, 1, 1);
stem (n1,y1);
xlabel (' Samples ');
ylabel (' Amplitude ');
 % Stability
 T = abs (y1);
 t = sum (T);
if (t < 1000)
disp (' Stable ')
else
disp (' Unstable ')
end;
%System
 % 1
 %  Linearity
  y8 = exp (x2);
 y9 = exp ( x3);
 y10 = 5*y8+5*y9;
 y11 = exp(5*x2+5*x3);
if (y11-y10~=0)
disp (' 2Linear ')
else
disp (' 2Non Linear ')
end;
% 2
 % Causality
 Y8= exp (x);
subplot (2, 1, 2);
stem (n1,y8);
xlabel (' Samples ');
ylabel (' Amplitude ');
 % 3 % Stability
 T1= abs (y8);
 t1 = sum (T1);
if (t1 < 1000)
disp (' 2Stable ')
else
disp (' 2Unstable ')
end;
Next PostNewer Post Previous PostOlder Post Home
Post a Comment