checking linear or nonlinear system in MATLAB

The input and output relation of a given system y(n)=Ax(n)+B, where y(n) is the output and x(n) is the input. We have to check if the system is linear or nonlinear.
MATLAB Code:
clc;
n=0:40;
a=2;
b=-3;
A=5;
B=6;
x1=cos(2*pi*.1*n);
x2=cos(2*pi*.5*n);
y=A.*(a.*x1+b.*x2)+B;
subplot(3,1,1);
stem(n,y);
yt=A.*(a.*x1+b.*x2)+a.*B+b.*B;
subplot(3,1,2);
stem(n,yt);
d=y-yt;
subplot(3,1,3);
stem(n,d);
axis([0 40 -10 20]);

Output:


Figure:1


Conclusion:A linear system is one that satisfies the superposition principles. Simply stated, the principle of superposition requires that the responses of the systems to a weighted sum of signal be equal to the corresponding weighted sum of the responses (outputs) of the systems to each of the individual input signals. Hence we have the following definition of linearity.
Here from the figure1 we first plotted the linear combination of input and then plotted the linear combination of output and then plotted the difference.The difference between them is not zero or not equal.So the system is nonlinear.

No comments:

Post a Comment