0% found this document useful (0 votes)
8 views2 pages

Code Lab 4

Code_Lab_4

Uploaded by

abbasmiry83
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Code Lab 4

Code_Lab_4

Uploaded by

abbasmiry83
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

function [y,ny]=TT(x,n)

[x1,n1]=sigshift(x,n,1);
[y,ny] = sigadd(3.4*x,n,6.7*x1,n1);

end

%%

close all
clear
clc

%% 1. Linearity and Non-Linearity

clear
clc
close all
n = 1:40;
a = 2;b = -3;

% Input Signal

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

% Weighted Output
[y1,ny1]=TT(x1,n);
[y2,ny2]=TT(x2,n);
[y,ny] = sigadd(a*y1,ny1,b*y2,ny2);

% Weighted Input
[x3,n3] = sigadd(a*x1,n,b*x2,n);
[yt,nt] = TT(x3,n3) ;

% Difference Signal
[err,ne] = sigadd(yt,nt,-y,ny);

% Plot the outputs and the difference signal


subplot(3,1,1)
stem(ny,y);
ylabel('Amplitude');
title('Weighted Output: a \cdot y_{1}[n] + b \cdot y_{2}[n]' );
subplot(3,1,2)
stem(nt,yt);
ylabel('Amplitude');
title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdotx_{2}[n]' );
subplot(3,1,3)
stem(ne,err);
xlabel('Time index n');ylabel('Amplitude');
title('Difference Signal');

%% 2. Time-Invariant and Time-Varying Systems

n = 1:40;
D = 20;

% Input Signal

a = 22;b = -2;
x = a*sin(2*pi*0.1*n) + b*cos(2*pi*0.4*n);

% Output Signal to dealy input y=T(x(n-D))

[xd,nd]=sigshift(x,n,D);
[yxd,nxd]=TT(xd,nd);

% Dealy Output Signal y(n-D)

[y,ny]=TT(x,n);
[yd,nyd]=sigshift(y,ny,D);

% Compute the difference output e[n]

[err,ne] = sigadd(yd,nyd,-yxd,nxd);

subplot(3,1,1)
stem(nxd,yxd);
ylabel('mplitude');
title('Output Signal to dealy input y=T(x(n-D))' );grid;
subplot(3,1,2)
stem(nyd,yd );
ylabel('Amplitude');
title(['Dealy Output Signal y(n-D)'])
subplot(3,1,3)
stem(ne,err);
xlabel('Time index n'); ylabel('Amplitude');
title('Difference Signal');grid;

You might also like