DSP Lab 1 Task
DSP Lab 1 Task
Output of P1_1:-
Output of P1_2:-
Output of P1_4:-
Output of P1_6:-
%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,
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');
Explaination:-
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:-
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');
Code output:-
comment:-
the graph output shows that the system is time invariant and equal because no difference
signal is exist here.
Ouput:-