Lab task outputs:-
Output of P1_1:-
Output of P1_2:-
Digital Signal Processing Lab Page 1
Output of P1_3:-
Output of P1_4:-
Digital Signal Processing Lab Page 2
Output of P1_5:-
Output of P1_6:-
Digital Signal Processing Lab Page 3
Output of P1_7:-
Output of P1_8:- when M=4,
Digital Signal Processing Lab Page 4
Answer no. 01):-
Code in command window:-
%program P1_8
%Generte the input signal
n=0:100;
s1=cos(2*pi*0.05*n);
s2=cos(2*pi*0.47*n);
x=s1+s2;
M=input('Desired length of filter=');
num=ones(1,M);
y=filter(num,1,x)/M;
subplot(221);
plot(n,s1);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('signal #1');
grid on;
subplot(222);
plot(n,s2);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('signal #2');
grid on;
subplot(223);
plot(n,x);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('Input signal');
grid on;
subplot(224);
plot(n,y);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('output signal');
grid on;
Comments:-
In this simulation when Desired signal=2 , put as length , we see that , the signal with high
frequency is compressed/suppressed i.e. s2[n], Because the property of Moving Average
System/Filter is to remove high frequencies of input signal.
Output:- when M=2,
Digital Signal Processing Lab Page 5
Answer no. 02):-
Code in command window:-
close all
clear all
clc
n = 0:40;
D = 10;
a = 3.0;
b = -2;
s1 = cos(2*pi*0.1*n);
s2 = cos(2*pi*0.4*n);
x = s1+s2;
num = [0.5 0.5];
dem = [1];
%ic = [0,0];
y = filter(num, dem, x);
subplot(4,1,1);
stem(n,y);
ylabel('Amplitude');
title('output y[n]');
subplot(4,1,2);
stem(n,x);
title('input x[n]');
subplot(413)
num1 = [0.5 -0.5];
dem1 = [1 0];
y1 = filter(num1, dem1, x);
stem(n,y1);
ylabel('Amplitude');
title('output y[n]' );
Digital Signal Processing Lab Page 6
grid;
subplot(414);
stem(n,x);
title ('input x[n]');
grid;
comment:-
There is no effect on input x[n] = s1[n] + s2[n], either the output is y[n] = 0.5(x[n]
+ x[n - 1]) or output is y[n] = 0.5(x[n] - x[n - 1]), as in figure below.
Answer no. 03):-
Code in command window:-
n=0:100;
s1=cos(2*pi*0.05*n);
s2=cos(2*pi*0.47*n);
x=s1+s2;
M=input('Desired length of filter=');
num=ones(1,M);
y=filter(num,1,x)/M;
subplot(221);
plot(n,s1);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('signal #1');
grid on;
subplot(222);
plot(n,s2);
axis([0,100,-2,2]);
xlabel('Time index n');
Digital Signal Processing Lab Page 7
ylabel('Amplitude');
title('signal #2');
grid on;
subplot(223);
plot(n,x);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('Input signal');
grid on;
subplot(224);
plot(n,y);
axis([0,100,-2,2]);
xlabel('Time index n');
ylabel('Amplitude');
title('output signal');
grid on;
Output:- when M=2, s1 frequency = 0.05, s2 frequency = 0.47,
Output:- when m=9, s1 frequency = 0.05, s2 frequeny = 0.47,
Digital Signal Processing Lab Page 8
Output:- when m=8, s1 frequency = 0.07, s2 frequeny = 0.67,
Digital Signal Processing Lab Page 9
Output:- when M=9, s1 frequency = 0.05, s2 frequency = 0.60,
Output:- when m=30, s1 frequency = 0.05, s2 frequency = 0.85,
Digital Signal Processing Lab Page 10
Comment:-
Upon changing both M length and frequencies of input, the signal becomes more “ distorted ”,
shown in above graphs.
But, when we fix frequencies , increase only M, output signal approaches to zero, shown in
figure, for M=30.
Answer no. 04):-
Code in command window:-
clear all
close all
clc
n=0:40;
f=0.1;
phase=0;
A=1;
x=A*cos(2*pi*f*n - phase);
stem(n,x,'r');
axis([0 40 -2 2]);
grid on;
title('sinosuidal sequence');
xlabel('time index');
ylabel('amplitude');
Code output:- when f=0.1,
Digital Signal Processing Lab Page 11
Code output:- when f=0.2,
Code ouput:- when f=0.5,
Digital Signal Processing Lab Page 12
Code output:- when f=1,
Explaination:-
Digital Signal Processing Lab Page 13
When the frequency of sinusoid increases I observe that the discrete samples of “ cosine
sinusoid ” goes simpler and changing highly on little change in frequencies. And when the f=1,
graph is shown in above figure, becomes samples of equal height i.e. 1.5.
Answer no. 05):-
Code in command window:-
close all
clear all
clc
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;
num = [2.24 2.49 2.24];
dem = [1 0.4 0.75];
ic = [0,0];
y1 = filter(num, dem, x1, ic);
y2 = filter(num, dem, x2, ic);
y = filter(num, dem, x, ic);
yt = a*y1 + b*y2;
d = y - yt;
subplot(3,1,1);
stem(n,y);
ylabel('Amplitude');
title('Output due to weighted input: a\cdot x_{1}[n] + b \cdot x_{2}[n]');
subplot(3,1,2);
stem(n,yt);
ylabel('Amplitude');
title('Weighted Output: a \cdot y_{1}[n] + b \cdot y_{2}[n]' );
subplot(3,1,3);
stem(n,d);
ylabel('Amplitude');
xlabel('Time Difference');
title('Difference Signal');
Code output:-
Digital Signal Processing Lab Page 14
Comparison :-
By comparing both graphs, we conclude that , both the graphs are “ equal ” because there is
too small difference signal we get. And, the system is “ linear ” because of its initial conditions
i.e. zero , here.
Answer no. 07):-
Code in command window:-
close all
clear all
clc
n =0:40;
D = 10;
a = 3.0;
b = -2;
x = a*cos(2 *pi*0.1*n) + b*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]
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D :41+D);
subplot(311);
stem(n,y);
ylabel('Amplitde');
Digital Signal Processing Lab Page 15
title('output');
grid on;
subplot(311)
stem(n,y);
ylabel('Amplitube');
title('output y[n]');
grid on;
subplot(312);
stem(n,yd(1:41))
ylabel('amplitude');
title(['output due to delayed input x[n - ', num2str(D) ,']']);
grid;
subplot(313);
stem(n,d);
xlabel('Time index n');
ylabel('Amplitude');
title('difference Signal');
grid;
Code output:-
Relationship between sequences:-
The relation between two sequences is, when delayed input sequence is applied to a system
then the same effect of appears on output of system. No , error shown in difference signal
output, means this system is “ time invariant system”.
Digital Signal Processing Lab Page 16
Answer no. 08):-
Code in command window:-
close all
clear all
clc
n =0:40;
D = 10;
a = 3.0;
b = -2;
x = a*cos(2 *pi*0.1*n) + b*cos(2*pi*0.4*n);
xd=[zeros(1,D) x]
num=[n 1]
den=[1];
ic = 0*[0:40];
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D :41+D);
subplot(311);
stem(n,y);
ylabel('Amplitde');
title('output');
grid on;
subplot(311)
stem(n,y);
ylabel('Amplitube');
title('output y[n]');
grid on;
subplot(312);
stem(n,yd(1:41))
ylabel('amplitude');
title(['output due to delayed input x[n - ', num2str(D) ,']']);
grid;
subplot(313);
stem(n,d);
xlabel('Time index n');
ylabel('Amplitude');
title('difference Signal');
grid;
comment:-
the graph output shows that the system is time invariant and equal because no difference
signal is exist here.
Ouput:-
Digital Signal Processing Lab Page 17
Digital Signal Processing Lab Page 18