Department of Computer Engineering, University of Engineering & Technology, Taxila

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Assignment # 1

Advance Digital Signal Processing

Department of Computer Engineering,


University of Engineering & Technology,
Taxila.

Page | 1
Code: -
% NAME = MUJEEB UR REHMAN

% REG NO = 18F-MS-CP-08

% part (a) Impulse Response

n=[1:20];

h=5*(-1/2).^n;

subplot(10,2,1),stem(h);

title('(a) Impulse Response');

% Part (b) inputs X1,X2,X3

n=[1:10];

x1=n-5;

n=[1:5];

x2=(1/3).^n;

n=[1:20];

x3=sin(pi*n/4);

% convolution of x[n] with h[n]

y1=conv(x1, h);

y2=conv(x2, h);

Page | 2
y3=conv(x3, h);

% plots of inputs and convolutions

subplot(10,2,3),plot(x1);

title('(b) 1. plot of X1');

subplot(10,2,4),plot(y1);

title('Conv of X1 & h');

subplot(10,2,5),plot(x2);

title('(b) 2. plot of X2');

subplot(10,2,6),plot(y2);

title('Conv of X2 & h');

subplot(10,2,7),plot(x3);

title('(b) 3. plot of X3');

subplot(10,2,8),plot(y3);

title('Conv of X3 & h');

% Part (c) convolution of accumulated values with h[n]

xc = cat(2,x1,zeros(1,10)) + cat(2,x2,zeros(1,15)) + x3;

yc=conv(xc, h);

subplot(10,2,9),plot(yc);

title(' (c) Conv of acc val with h');

% Part (d) addition of outputs and plot of accumulated values

ya=cat(2,y1,zeros(1,10)) + cat(2,y2,zeros(1,15)) + y3;

subplot(10,2,10),plot(ya);

title('(d) accumulated val');

% Part (e) as the graph is similar of part c and part d so results are

% similar

Page | 3
Output: -

Code: -
% NAME = MUJEEB UR REHMAN

% REG NO = 18F-MS-CP-08

% Impulse Response h[n]

n=[1:20];

h=5*(-1/2).^n;

subplot(2,4,1),stem(h);

title('Impulse Response');

% part (a)

%plot of output of lti system

x = cos((3*n*pi/2)+pi/4);

y=conv(x, h);

Page | 4
subplot(2,4,2),plot(x);

title('input X');

subplot(2,4,3),plot(y);

title('conv of X & h');

lx=length(x);

ly=length(h);

xp=[x zeros(1,ly-1)];

hp=[h zeros(1,lx-1)];

% Part (b)

%taking fourier transform of both signals

x2=fft(xp);

h2=fft(hp);

subplot(2,4,4),plot(h2);

title('ft of hp');

subplot(2,4,5),plot(x2);

title('ft of xp');

% mul of transformed signals

y=x2.*h2;

subplot(2,4,6),plot(y);

title('multiplied signals');

% Part (c)

% Inverse fourier transform

iy=ifft(y);

Page | 5
subplot(2,4,7),plot(iy);

title('Inv FT of mul signal');

Output: -

Code: -
% NAME = MUJEEB UR REHMAN

Page | 6
% REG = 18F-MS-CP-08

% Part (a)

%y=audiorecorder(5*32000,32000,'int16')

[y, fs] = audioread('Myvoice.wav');

Ts=1/fs;

t=0:Ts:length(y)*Ts - Ts;

subplot(10,1,1),plot(t,y);

[h,w]=freqz(y);

subplot(10,1,2),plot(h);

p=audioplayer(y,fs);

play(p)

max(h)

% Part (b) Decimation by factor 2

r=2;

yd = decimate(y,r);

Ts=1/fs;

t=0:Ts:length(yd)*Ts - Ts;

subplot(10,1,3),plot(t,yd);

hd=freqz(yd);

subplot(10,1,4),plot(hd);

p1=audioplayer(yd,fs);

play(p1)

Page | 7
% Part (c) Decimation by factor 2

r1=2;

yd1 = decimate(yd,r1);

Ts=1/fs;

t=0:Ts:length(yd1)*Ts - Ts;

subplot(10,1,5),plot(t,yd1);

hd1=freqz(yd1);

subplot(10,1,6),plot(hd1);

p2=audioplayer(yd1,fs);

play(p2)

% Part (d) Decimation by factor 2

r2=2;

yd2 = decimate(yd1,r2);

Ts=1/fs;

t=0:Ts:length(yd2)*Ts - Ts;

subplot(10,1,7),plot(t,yd2);

hd2=freqz(yd2);

subplot(10,1,8),plot(hd2);

p3=audioplayer(yd2,fs);

play(p3)

% Part (e) Decimation by factor 2

r3=2;

yd3 = decimate(yd2,r3);

Ts=1/fs;

Page | 8
t=0:Ts:length(yd3)*Ts - Ts;

subplot(10,1,9),plot(t,yd3);

hd3=freqz(yd3);

subplot(10,1,10),plot(hd3);

p4=audioplayer(yd3,fs);

play(p4)

Output: -

Page | 9

You might also like