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

COMSATS University Islamabad

Abbottabad Campus
Department of Electrical (Power) Engineering
Lab Assignment: 01

Name : Zabeeh ullah

Registration Number : FA19-EPE-028

Class/Section :EPE-5C

Subject : DSP

Lab Engineer Name : Maam Zenab Fazal

Course Teacher Name :Nauman khan tareen

Submission Date :22-September-2021


LAB TASK 1

1: A+B=

2: A-B=
A=[1 2 3;9 7 6;6 5 2];

>> B=[-9 -8 -7;-1 -3 6;-4 -5 -8];

D=A-B;
3: INVERSE MATRIX OF A:
A= [1 2 3; 9 7 6;6 5 2]

A=

1 2 3

9 7 6

6 5 2

>> inv(A)

4: Verify AB ≠ BA
5: Verify AB = BA (point-to-point multiplication):
• Q6 Draw x[n]=5sin(Ωn+pi/2) nϵ[-25, 25] , N = 4, 10, 21/2

Let x1[n] = {10, 0, 0, 0, 2, 3, 4, 0, 0}

x2[n]={0, -2.5, -3, -0.5, 0.5, 3}

Ans:
At N=4:

clc;

clear all;

close all;

n= -25:25

N= 4;
omega=(2*pi)/N;

y=5*sin((omega*n)+(pi/2))

stem(n,y)

xlabel('sample')

ylabel('amplitude')

grid('on')

AT N=10:

clc;

clear all;

close all;

n= -25:25

N= 10;

omega=(2*pi)/N;

y=5*sin((omega*n)+(pi/2))

stem(n,y)

xlabel('sample')

ylabel('amplitude')

grid('on')

AT N=21:

clc;

clear all;

close all;

n= -25:25
N= 21;

omega=(2*pi)/N;

y=5*sin((omega*n)+(pi/2))

stem(n,y)

xlabel('sample')

ylabel('amplitude')

title('sinusoidal signal')

grid('on')

Q7 a. y1[n]=x1[n]+x2[n]
b. y2[n]=x1[n]*x2[n]
clc;

clear all;

close all;

n =-5:5;

x1=[0,10,0,0,0,2,3,4,0,0,0];

subplot(411)

stem(n,x1)

xlabel('sample')

ylabel('amplitude')

title('x1')

grid('on')

x2=[0,0,0,0,0,0,-2.5,-3,-0.5,0.5,3]

subplot(412)

stem(n,x2,'red')

xlabel('sample')

ylabel('amplitude')

title('x2')

grid('on')

y1=x1+x2

subplot(413)

stem(n,y1,'blue')

xlabel('sample')
ylabel('amplitude')

title('sum')

grid('on')

y2=x1.*x2

subplot(414)

stem(n,y2,'black')

xlabel('time')

ylabel('magnitude')

title('multiplacation')

grid('on')
• Q8 Draw following signals

a. x3(t) = step size = 0.1, 0.5 , t ϵ[0, 3]


clc;

clear all;

close all;

% step size

t1= 0:0.1:3;

y= exp(-2*t1).*cos(t1);
subplot(211);

plot(t1,y)

xlabel('sample');

ylabel('amplitude');

title('step size 1');

grid('off')

t2= 0:0.5:3;

y= exp(-2*t2).*cos(t2);

subplot(212);

plot(t2,y)

xlabel('sample');

ylabel('amplitude');

title('step size 2');

grid('off')
b. x4[n] = (-1)^n nϵ[0, 20)

clc;
clear all;

close all;

%determining the tiem

n=0:20

%writing equation

x4=(-1).^n

stem(n,x4)

xlabel('sample')

ylabel('amplitude')
C: x5[n] = nϵ[10, 30], N = 6

clc;

clear all;

close all;

n= 10:30;

N= 6;

omega=(2*pi)/N;

y= abs(exp(i*omega*n))

stem(n,y)

xlabel('sample')

ylabel('amplitude')

title('exponential signal')

grid('off')
D. x6[n] = nϵ[-10, 30], N = 6

clc;

clear all;
close all;

n= -10:30;

N= 6;

omega=(2*pi)/N;

y=((exp(i*omega*n))-(exp(-i*omega*n)))/(2*i)

stem(n,y)

xlabel('sample')

ylabel('amplitude')

title('sinusoidal signal')

grid('on')
THANK YOU
COMSATS University Islamabad
Abbottabad Campus
Department of Electrical (Power) Engineering
Lab Assignment: 2

Name : Zabeeh ullah

Registration Number : FA19-EPE-028

Class/Section :EPE-5C

Subject : DSP

Lab Engineer Name : Maam Zenab Fazal

Course Teacher Name :Nauman khan tareen

Submission Date :29-September-2021


DSP LAB #2

Task 01:

x ( t )=co s ( 2 pifn
fs )
t
(a) Determine continuous signal?
(b) Determine Shifted Fourier Transform?
(c) Determine omega by using linspace command?
(d) Determine magnitude, phase, real, and imaginary properties to conclude proper
analysis?

Code:
clc;
close all;
clear all;
fs=1000;
fn=100;
t=-1:1/fs:1 % 1/fs is used to get an accurate
subplot(611)
x= cos((2*pi*fn)*t); % equation.
plot(t,x) % plotting
xlabel('time')
ylabel('magnitude')
grid('on')
title('sinusoidal wave')
N=1024;
xjw= fftshift(fft(x,N)) % fourier transform of equation
omega= linspace(-fs/2,fs/2,N);
subplot(612)
plot(omega,xjw)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('fourier transform')
x1=abs(xjw) % absolute or magnitude of equation
subplot(613)
plot(omega,x1)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('absolute or magnitude')
x2=real(xjw) % real part of the equation
subplot(614)
plot(omega,x2)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('real part')
x3=imag(xjw) % imaginary part of the equation
subplot(615)
plot(omega,x3)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('imaginary part')

x4=angle(xjw) % angle of the equation


subplot(615)
plot(omega,x4)
xlabel('frequency')
ylabel('angle')
grid('on')
title('angle')

Screenshot:

Task#2

Now generate a nonstationary signal as given below and compare the results with a stationary
one.
𝑁𝑜𝑛𝑠𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑟𝑦 𝑆𝑖𝑔𝑛𝑎𝑙:

w ( t )=co s ( 2 pifs( 100 ) t )u ( t − 10) +co s( 2 pifs( 65) t )u ( −t +2)

𝑆𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑟𝑦 𝑆𝑖𝑔𝑛𝑎𝑙:

2 pi ( 100 ) 2 pi ( 65 )
y ( t ) =co s ( fs ) (
t +co s
fs
t )

Code:
clc;
close all;
clear all;
fs=100;
t= -30:1/fs:30;
% non staionary signal
x= (cos(((2*pi*100)/fs)*t).*heaviside(t-10))+
(cos(((2*pi*65)/fs)*t).*heaviside(-t+2))
subplot(411)
plot(t,x)
xlabel('time')
ylabel('magnitude')
grid('on')
title('Non Staionary signal')
% Taking fourier transorm of non stsationary signal
N=1024;
y=fftshift(fft(x,N))
omega= linspace(-fs/2,fs/2,N)
subplot(412)
yabs= abs(y)
plot(omega,yabs)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('fourier transform of non Stationary Signal')
% stationary signal
x1= (cos(((2*pi*100)/fs)*t))+(cos(((2*pi*65)/fs)*t))
subplot(413)
plot(t,x1)
xlabel('time')
ylabel('magnitude')
grid('on')
title('Stationary Signal')
% for fourier transform of stationary wave
y1=fftshift(fft(x1,N))
omega= linspace(-fs/2,fs/2,N)
subplot(414)
y1abs= abs(y1)
plot(omega,y1abs)
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('fourier transfom of staionary signal')

Screenshot:

Diff between 𝑁𝑜𝑛𝑠𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑟𝑦 𝑆𝑖𝑔𝑛𝑎𝑙 and stationary:


Stationary Signals Non-Stationary Stationary Signals
Time The time period for a non- The time period for the
stationary signal varies with stationary signal remains
time and is not constant. constant at all times.
Frequency The frequency of a Non- The frequency of a stationary
stationary wave changes signal remains constant
constantly during the process. across the process.
Spectral Contents Spectral contents are dynamic Spectral content for
and keep changing in case of Stationary signals are
the non-stationary signal. constant.
Fourier Equation Fourier transform is non- Fourier transform is good at
good at representing non- representing stationary
stationary signals. signals
Examples Speech signals, Multitone Single-tone sinewave
sinewave of varied frequency constant frequency, Multitone
sine wave of constant
frequency

Question:#1:

Provide your analysis for the change in frequency fn?

Answer:

When the frequency fn is changed it decreases or increases the no of variations in time


domain and in frequency domain, our signal is bandlimited up to (- some point to +some point).
Basically, our signal can be lie in that specific frequency.

Question#2:

What is meant by the term’s frequency resolution and time


resolution?

Answer:

FREQUENCY RESOLUTION:

The ability of an algorithm to distinguish between two


closely spaced peaks in the frequency domain.

Question#3:
Do you think Fourier Transform provides all required
information for stationary and nonstationary signals?

Answer:

As it is known that Fourier transform is basically the train of impulses in frequency


domain and a sinusoidal signal has only two impulses in frequency domain.

Stationary Signal:

In case of stationary signal, Fourier transform gives all the required


information, and it gives a good result for stationary signal.

Nonstationary Signal:

In case of nonstationary signal, fourier transform does not provides all the
required information. Some of the information is lost. So it is not a good representation for
nonstationary signals.
COMSATS University Islamabad
Abbottabad Campus
Department of Electrical (Power) Engineering
Lab Assignment: 3

Name : Zabeeh ullah

Registration Number : FA19-EPE-028

Class/Section :EPE-5C

Subject : DSP

Lab Engineer Name : Maam Zenab Fazal

Course Teacher Name :Nauman khan tareen

Submission Date :06-October-2021

Code:
clc;
close all;
clear all;
fs=1000
fn=35;
t=-1:1/fs:1;
x=sin(2*pi*fn*t);
subplot(321)
plot(t,x,'r')
xlabel('time')
ylabel('magnitude')
grid('on')
title('CT Sinousidal signal')

x_jw=fftshift(fft(x,fs)) %FT of given sinousidal signal


% omega is used to define horizontal axis for fourier transform or angular
% freqeuncy axis.
x_abs=abs(x_jw)
omega=linspace(-fs/2,fs/2,fs)
subplot(322)
plot(omega,x_abs, 'g')
xlabel('frequency')
ylabel('magnitude')
grid('on')
title('Fourier Transform Signal')
fsqu=70;
x_sq= square(2*pi*fsqu*t)
subplot(323)
plot(t,x_sq,'y')
xlabel('time')
ylabel('magnitude')
grid('on')
title('Square Wave')
% Now taking derivative to break the wave from cont to descrete.
% absolute is taken to align in it to positive y axis only.
x_der = (abs(diff(x_sq)))/2;
subplot(324)
% as the vectors of t=12001 and x_der=12000. so vectors must be off same
% length. 1:length(x_der) means a increament of vector in t
plot(t(1:length(x_der)),x_der,'r')
xlabel('time')
ylabel('magnitude')
grid('on')
title('Differential Square Wave')
% NOW doing sampling process.
x_samp= x_der.*x(1:length(x_der))
subplot(325)
stem(t(1:length(x_der)),x_samp,'db')
xlabel('time')
ylabel('magnitude')
grid('on')
title('Sampled Signal')
% Now we will take for loop in order to overcome extra info of zeros
m=0;
for i=1:length(x_der)
if x_der(i)==1
m=m+1;
x_n(m)=x_samp(i);
end
end
subplot(326)
% Implementing the final descrete signal.
stem(1:m,x_n)
xlabel('time')
ylabel('magnitude')
grid('on')
title('Sampled Signal with no Zeros')

Output:
Lab# 4

Random Sinusoidal Signal

Name: Zabeeh ullah

Reg # FA19-EPE-028

Submitted to:

Teacher: sir Nauman khan Tareen

Lab Engr: Ms.Zenab Fazal

TASK:

Generate a random sinusoidal signal of any frequency < 10 Hz and sample it with

appropriate fs.

a) Plot the signal in continuous form and its sampled version.

b) Finally, use the reconstruction impulse response (i.e. sinc) to reproduce it again.

Generate x[n]= cos(wt) , f=200 Hz cosine wave with sampling frequency 1200 Hz

(6*200) having 100 samples. Decimate this signal and interpolate this signal with

factor of 2. Plot all these on same figure.


CODE:
clc;

close all;

clear all;

fs=100; % sampling freq

T=1/fs;

t=0:1/fs:4;

x=sin(2*pi*3*t)+sin(2*pi*8*t);% CT signal subplot(221)

plot(t,x,'linewidth',2);

xlabel('time');

ylabel('x(t)');

title('continuous signal')

grid on

subplot(222)

Figures:
Questions:
Analyze code and write a note on reconstruction.

Answer:

A continuous time signal can be processed by processing its samples through a discrete time system.

For reconstructing the continuous time signal from its discrete time samples without any error,
the signal should be sampled at a sufficient rate that is determined by the sampling theorem
(fs>=2*fn).

Change the value of fs and observe the reconstructed signal.

Answer:

By changing the value of fs we observe different signals.

• Sampling frequency must be greater than or equal to twice the normal frequency

(fs>=2*fn) to get a reconstructed signal equal to original continuous time signal.


• If fs is less than 2fn than their will be aliasing .we don’t get back original continuous time signals.

Aliasing occurs when fs is less than 2*fn


COMSATS University Islamabad

(Abbottabad Campus)

Lab Assignment 05

Name : Zabeeh ullah

Reg No : FA19-EPE-028-5C

Teacher Name : Nauman khan Tareen

Lab Engineer : Ma’am Zenab Fazal

Subject : Digital Signal Processing

Submission Date : 20-Oct-2021


“Introduction to Simulink and Digital Filters Implementation”

Objective:
The basic objective of this Lab is to make students able to understand how to design a system and
run a simulation in Simulink. What is simulation time, what is sampling time of block? How to use difference
blocks in Simulink environment, how to make connections, how to design a subsystem, how to mask a
subsystem, how to export data to workspace, how to import data from work space, how to use commands in
Simulink. How to make user defined blocks in Simulink. How to plot the Simulink output in MATLAB. And
finally the implementation of digital filter in Simulink for noise removal and frequency component removal.

Consider

Lab Task a:
1. Implement the following model in SIMULINK.
For the implementation of digital filter HPF/LPF in Simulink first generate filter
coefficients in MATLAB using fir1 command choose any appropriate cut off frequency for
HPF/LPF.
2. Spectrum scope / filtering in MATLAB
Generate two sampled sin waves (source in dsp library) of different frequencies in Simulink f1=
1850Hz, f2=6250Hz and add them together filter out the higher frequency component with the help
of digital filter. Check the spectrum of both the sin waves individually added signal and filter out
signal. For spectrum visualization you can use spectrum scope (sink in dsp library) in Simulink.

Simulink:

f1=1850Hz:
f2=6250Hz:
Lab Task b:
Interpolation and Decimation
Analyze the effect of interpolation (up sample by factor of 4) in Simulink: Add a block of
interpolation from signal processing block set and place it in front of sinusoidal signal in the
above block diagram.
Analyze the effect of decimation (down sample by factor of 5) in Simulink: Add a block of
decimation from signal processing block set and place it in front of sinusoidal signal in the
above block diagram.

Simulink:
Sine wave:

UP sampling:
Down sampling:

COMSATS University Islamabad Abbottabad Campus


Department of Electrical (Power) Engineering

Digital System Processing


Lab Assignment: 06
Name : Zabeeh ullah

Registration Number : FA19-EPE-028

Class/Section : EPE-5C

Subject : Digital System Processing

Lab Insturtor Name : Miss Zenab Fazal

Course Teacher Name : Sir Nauman khan Tareen

Submission Date : 27-Otober-2021

LAB 06
Z-Transform in MATLAB & effect of pole and zeros on frequency response

Questions 1:
A. Write a MATLAB program to compute and display the poles and zeros, to compute and display the
factored form, and to generate the pole-zero plot of a z-transform that is a ratio of two polynomials in
z−1. Using this program, analyze the z-transform G(z) of Eq. above.

B. From the pole-zero plot generated in above question, determine the number of regions of
convergence (ROC) of G(z). Show explicitly all possible ROCs . Can you tell from the pole-zero plot
whether or not the DTFT exists?

The reverse process of converting a z-transform given in the form of zeros, poles, and the gain constant
to a rational form can be implemented using the function zp2tf. The program statement to use is
[num,den] = zp2tf(z,p,k).

Answer:
Coding:
clc

clear all

close all

%plote zero plot using zplane command

zero=[ -1.0000 + 1.4142i; -1.0000 - 1.4142i; -0.2500 + 0.6614i; -0.3500 -


0.6614i]

pole= [-8.9576 + 0.0000i; -0.2718 + 0.0000i; 0.1147 + 0.2627i; 0.1147 -


0.2627i]

zplane(zero,pole)

%Find poles and zeros using both roots and tf2zp

num=[2 5 9 5 3]

denum=[5 45 2 1 1]

zplane(num,denum)

d=roots(num)

d=roots(denum)

[z,p,k]=tf2zp(num,denum)

[num deum]=zp2tf(z,p,k)

sos=zp2sos(z,p,k)
Output:

Question 2:

For the given 𝑥(𝑧) determine the following.

a) Pole zero plot using zplane command.

b) Find poles and zeros using both roots and tf2zp commands.

Answer:

Coding:
clc

clear all

close all
%plote zero plot using zplane command

zero=[3/4]

pole= [0.4659;0.0230]

zplane(zero,pole)

%Find poles and zeros using both roots and tf2zp

num=[1 -3/4]

denum=[5 130/58 -5/58]

zplane(num,denum)

d=roots(num)

d=roots(denum)

[z,p,k]=tf2zp(num,denum)

[num deum]=zp2tf(z,p,k)

sos=zp2sos(z,p,k)

Output:
Question 3:

For the given 𝑥(𝑧) determine the following.

a) Find Pole zero plot using zplane command.

b) Find poles and zeros using both roots and tf2zp commands.

Answer:

Coding:
clc

clear all

close all

%plote zero plot using zplane command


zero=[-4.7016;2.7016]

pole= [0.8222+2.8650i;0.8222-2.8650i]

zplane(zero,pole)

%Find poles and zeros using both roots and tf2zp

num=[1 3 8]

denum=[1 -1/13 4]

zplane(num,denum)

d=roots(num)

d=roots(denum)

[z,p,k]=tf2zp(num,denum)

Output:
COMSATS University Islamabad Abbottabad Campus

Department of Electrical (Power) Engineering

Lab Assignment: 07

Name & Registration No:

Zabeeh ullah & FA19-EPE-028

Semester: 5th

Class/Section: EPE-5C

Subject: Digital System Processing

Course Teacher: Sir Nauman Khan Tareen

Lab Teacher: Ms. Zenab Fazal

Submission Date: 03-November-2021


Q1.A) Plot the following pole zero plots and also find their transfer function.

clc

close all;

clear all;

pole=[-2 ; 0.5];

zero=[0];

subplot(2,1,1)

zplane(zero,pole)

[num,denum]=zp2tf(zero,pole,1)

H=filt(num,denum)

subplot(2,1,2)

impz(num,denum)
Q1.B:
clc

close all

clear all

pole=[1/3 ; 2 ; 3];

zero=[-1];

zplane(zero,pole);

[num,denum]=zp2tf(zero,pole,1)

H=filt(num,denum)
Q2) Plot the following pole zero plot and also find its transfer function.
(Exercise problem)

clc

close all
clear all

pole=[1/4 ];

zero=[-j*1/4 ; j*1/4];

zplane(zero,pole);

[num,denum]=zp2tf(zero,pole,1)

H=filt(num,denum)

Q3) Plot the following pole zero plot and also find its transfer function.
(Exercise problem)
clc

close all

clear all

pole=[0.6+j*0.6 ; 0.6-j*0.6 ];

zero=[0.6];

zplane(zero,pole);

[num,denum]=zp2tf(zero,pole,1)

H=filt(num,denum)
4.Find the inverse z-transform of the following expression and from pole zero
plot or from transfer function determine, whether it is FIR or IIR system.

Answer:

Code:
clear all

close all
clc

syms z

f=(1-0.5*z^-1)/(1+0.75*z^-1+0.125*z^-2);

fz=ztrans(f);

disp('z transform is');

disp(fz);

zz=iztrans(fz);

disp('inverse z transform is ');

disp(zz);

num=[1 -0.5];

denum=[1 0.75 0.125];

fvtool (num,denum)

Output:
5.Find the inverse z-transform of the following expression and from pole zero
plot or from transfer function determine, whether it is FIR or IIR system.

Answer:

Code:
clear all

close all

clc

syms z

f=(1-0.5*z^-1-0.33*z^-2)/(1-0.25*z^-2);

fz=ztrans(f);

disp('z transform is');

disp(fz);

zz=iztrans(fz);

disp('inverse z transform is ');

disp(zz);

num=[1 -0.5];

denum=[1 -0.25];

zplane(num,denum)

fvtool (num,denum)

Output:
6.A causal LTI system has the system function 𝐻(𝑧).
a) Plot its pole zero plot.
b) Find the impulse response h[n].
c) From the pole/zero plot or from transfer function determines whether it
FIR or IIR system.

Answer:

Code:
clear all

close all

clc

syms z

f=(1+2*z^-1+1*z^-2)/(1-0.5*z^-1)*(1-0.25*z^-2)*(1-1*z^-1);

fz=ztrans(f);

disp('z transform is');

disp(fz);

zz=iztrans(fz);

disp('inverse z transform is ');

disp(zz);

b1=[1 -0.5];

b2=[1 -0.25];

b3=[1 -1]

x=conv(b1,b2);

num=[1 2 1];
denum=conv(x,b3);

subplot(212)

zplane(num,denum)

subplot(211)

impz(num,denum)

fvtool (num,denum)

Output:
COMSATS University Islamabad Abbottabad Campus

Department of Electrical (Power) Engineering

Lab Assignment: 08

Name & Registration No:

Zabeeh ullah & FA19-EPE-028

Semester: 5th

Class/Section: EPE-5C

Subject: Digital System Processing

Course Teacher: Sir Nauman Khan Tareen

Lab Teacher: Ms. Zenab Fazal

Submission Date: 03-Nov-2021

LAB 08
Minimum phase system/ All-Pass systems/ FIR Filter Types/ Effect of
integer/ non integer delay
PROCEDURE:

function[Bmp,Bap,Amp,Aap]=Decomp(n,d) %A poles,B zeros

B=roots(n);

A=roots(d);

k=1;j=1;

mul=1

Bmp=1, Bap=1 ,Amp=1, Aap=1

for i=1:length(B)

mul=mul*abs(B(i))

if abs(B(i))>=1

Bap(k)=B(i)

Aap(k)=1/B(i)

Bmp(j)=1/B(i)

k=k+1;j=j+1

else

Bmp(j)=B(i)

k=k+1;j=j+1

end

end

for i=1:length(A)

j=1; mul=mul/abs(A(i)');

if abs(A(i))>=1

Aap(k)=A(i)

Bap(k)=1/A(i)

Amp(j)=1/A(i)
k=k+1;j=j+1

else

Amp(j)=A(i)

j=j+1

end

end

mul=1

Bmp=mul.*poly(Bmp); Pmp =poly(Amp); Bap=poly(Bap)/mul; Pap=poly(Aap)

zplane(Bmp,Amp)

zplane(Bap,Aap

CODE:

clc

clear all;

close all;

n=[1 16.5-28 108-187 -200+346]

d=[1 16 0.18 0 19]

[Aap,Amp,Bap,Bmp]=Decomp(n,d);

[H w]=freqz(n,d,'whole');

subplot(2,2,1.5)

zplane(n,d)

title 'H(z)'

grid on

subplot(2,2,3)

plot(w/pi-1,abs(H))
title '|H(Z)|'

grid on

subplot(2,2,4)

plot(w/pi-1,angle(H))

title 'phase |H(Z)|'

grid

figure

subplot(2,2,1.5)

zplane(Bap,Aap)

title 'H_a_p(Z)'

grid

subplot(223)

[H,w]=freqz(Bap,Aap,'whole')

plot(w/pi-1,abs(H))

title '|H_a_p(Z)|'

grid on

subplot(224)

plot(w/pi-1,angle(H))

title 'phase |H_a_p(Z)|'

figure

subplot(2,2,1.5)

zplane(Bmp,Amp)

title 'H_m_i_n(Z)'

grid
subplot(2,2,3)

[H,w]=freqz(Bmp,Amp,'whole')

plot(w/pi-1,abs(H))

title '|H_m_i_n(Z)|'

grid

subplot(224)

plot(w/pi-1,angle(H))

title 'phase|H_m_i_n(Z)|'

grid

A discrete-time causal LTI system has the system function.

𝐻(𝑧) =

(1 + 1.5𝑧−1)(1 − 25𝑧−2)/ (1 + 0.49𝑧−2)


i) Find the magnitude / phase / group delay of 𝐻(𝑧).
H(z)
10

Imaginary Part
5

-5

-10
-20 -10 0
Real Part
|H(Z)| phase |H(Z)|
4
40
2
35
0
30

25 -2

20 -4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

ii) ii) Find the magnitude / phase / group delay of 𝐻𝑚𝑖𝑛(z).


Hmin (Z)

Imaginary Part
-5

-10

-15

-20

-20 -10 0
Real Part
|H min (Z)| phase|H min (Z)|
4
0.1
2

0
0.05

-2

0 -4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

iii) Find the magnitude /phase / group delay of 𝐻𝑎𝑝(z).


H ap (Z)
1

Imaginary Part
0.5

3
0

-0.5

-1
-1 -0.5 0 0.5 1
Real Part
|H ap (Z)| phase |Hap (Z)|
-0.5
2
-1
1.5
-1.5
1

0.5 -2

0 -2.5
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

A discrete-time causal LTI system has the system function.


𝐻(𝑧) =
(1 + 4𝑒𝑗𝜋 3 𝑧−1)(1 + 4𝑒−𝑗𝜋 3 𝑧−1)(1 + 25𝑧−2)/ (1 + 0.81𝑧−2)(1 + 16𝑧−2)
i) Find the magnitude / phase / group delay of 𝐻(𝑧).
H(z)
30
Imaginary Part

20

10

-30 -20 -10 0 10


Real Part
|H(Z)| phase |H(Z)|
150 4

2
100
0

50
-2

0 -4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

Find the magnitude / phase / group delay of 𝐻𝑚𝑖𝑛(z).


Hmin (Z)
30

Imaginary Part
20

10

-20 -10 0 10 20
Real Part
|H min (Z)| phase|H min (Z)|
0.4 3

0.3 2

0.2 1

0.1 0

0 -1
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

Find the magnitude /phase / group delay of 𝐻𝑎𝑝

H ap (Z)
1
Imaginary Part

0.5

3
0

-0.5

-1
-1 -0.5 0 0.5 1
Real Part
|H ap (Z)| phase |Hap (Z)|
3
1.5
2.5

2
1
1.5

1
0.5
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

𝐻(𝑧) =
(1 +7 2𝑒𝑗𝜋 4 𝑧−1)(1 + 7 2𝑒−𝑗𝜋 4 𝑧−1)
/1 −1/ 5𝑧−1
i) Decompose the given transfer function into a minimum phase and all-pass
system. Determine freqz response of both systems.
H min (Z)
1

Imaginary Part
0

-1

-2

-3

-4 -2 0
Real Part
|H min (Z)| phase|H min (Z)|
0.06 4

2
0.04
0
0.02
-2

0 -4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

H ap (Z)
1
Imaginary Part

0.5

2
0

-0.5

-1
-1 -0.5 0 0.5 1
Real Part
|H ap (Z)| phase |Hap (Z)|
0.25 0.4

0.2

0.2 0

-0.2

0.15 -0.4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
COMSATS University Islamabad Abbottabad Campus

Department of Electrical (Power) Engineering

Lab Assignment: 09

Name & Registration No:

Zabeeh ullah & FA19-EPE-028

Semester: 5th

Class/Section: EPE-5C

Subject: Digital System Processing

Course Teacher: Sir Nauman Khan Tareen

Lab Teacher: Ms. Zenab Fazal

Submission Date: 17-Nov-2021

LAB 09

“Structures in Simulink and Digital Filters Implementation”


LAB TASK 1:
[ 1+ 2 Z −1 +Z − 2 ]
PART A: H ( Z )=
1 −0.75 Z − 1+ 0.125 Z −1

DIRECT FORM 1:

DIRECT FORM 2:
OUTPUT:

b: Find Impulse & Step response using fvtool (num, dnum)

CODE:
clc;

clear all;

close all;

num=[1 2 1]

denum=[1 -0.75 0.125]

fvtool(num,denum)

OUTPUT:
[ 1+ 2 Z −1 +Z − 2 ]
PART B: H ( Z )=
1 −0.75 Z − 1+ 0.125 Z −1

DIRECT FORM 1:

DIRECT FORM 2:
OUTPUT:

b: Find Impulse & Step response using fvtool (num, dnum)

CODE:
clc;

clear all;

close all;

num=[1 -2 -8]

denum=[1 2.5 -1.5]

fvtool(num,denum)
OUTPUT:

[(1+1.5 Z −1)(1 −25 Z −1 )]


PART C: H ( Z )=
1 − 0.49 Z −2

DIRECT FORM1:

DIRECT FORM2:
OUTPUT:

b: Find Impulse & Step response using fvtool (num, dnum)

CODE:
clc;

clear all;

close all;
num=[1 -25 -37.5]

denum=[1 0 0.49]

fvtool(num,denum)

OUTPUT:

CONCLUSION:
In this lab we have determined the structure of any system
function by using direct form1 and direct form2 on Simulink. After that we have
determined the impulse response of every system function H(z) by using fvtool
command.
COMSATS University Islamabad Abbottabad Campus

Department of Electrical (Power) Engineering

Lab Assignment: 11-12

Name & Registration No:

Zabeeh ullah & FA19-EPE-028

Semester: 5th

Class/Section: EPE-5C

Subject: Digital System Processing

Course Teacher: Sir Nauman Khan Tareen

Lab Teacher: Ms. Zenab Fazal

Submission Date: 30-Nov-2021


LAB 11-12
The effects of up/down sampling and Quantization on speech and Image

Objective :

The objective of this lab is familiarizing the students with the effects of up and down sampling
on speech and image signals. This lab is aimed to provide students with basic speech, image
processing and to develop their interest by connecting the mathematics of the underlying systems
with practical research problems or something that can be visualized.

Background and Lab Tasks

The students need to implement the previous lab regarding sampling rate and reconstruction to
image and speech signals. MATLAB will be used as the basic tool for this purpose. Some of the
basics of speech and image processing in MATLAB are given below.

Speech Signals in MATLAB

A speech signal has been uploaded on the student portal. You need to download the “Speech.zip”
folder, the contents of this folder are

1. An audio file containing test speech signal

2. Impulse responses of different environments

The first task is to read the given audio input signal with a predefined sampling frequency,
plotting it in time domain and then follow this step by analyzing the speech signal in frequency
domain. The term sampling frequency means that how many speech samples per second are
collected by the hardware under consideration, which not only describes the speech file’s pitch,
timbre but also can measure the sound card, sound file’s quality. The sampling frequency and
sampling time have a reciprocal relationship. According to the Nyquist theory, only when the
frequency of samples is twice higher than that of any signal’s peak frequency then we can
convert digital signal to the origin sound.
The following command is used to read an audio file in MATLAB. Check MATLAB help for
further details.

[y,Fs] = audioread(filename,samples) % where Fs is the sampling frequency.


 Plot 50 ms of this audio signal in time domain. Now analyze it in frequency domain,
using the builtin fft() function.
 Read the impulse response file in similar manner and convolve the original speech
signal with this impulse response plot it and analyze again in frequency domain. Also
listen to the resulting speech after saving the resulting vector as output.mp3 using the
wavwrite() command. Comment about the effects of convolution.
 Now take the original audio signal and down sample it by a factor of 2 and then 4. What
do you think happened? Explain the theory behind this, listen to the audio file, did you
notice any difference in the audio quality? If so, what happened? What about the
storage space it took? What happened to this signal in frequency domain? What was
expected to happen?

Image processing in MATLAB

An image is a function of space or its 2-D representation of the 3-D space. Generally when
dealing with image in MALTLAB, you will observe that’s it’s a multivalued function. This
function corresponds to different color intensities (RGB).

Whenever digital signal processing is involved there is a need to digitize images. This involves
two major steps (already discussed in lecture)

1. Sampling

2. Quantization

Sampling corresponds to discretization of the space hence, each of the images shown above are
represented as matrices. (Sampling corresponds to resolution of the image). The smallest element
resulting from this process is called a pixel.

The process of quantization on the other hand corresponds to discretization of the intensity
values and defines the number of bits/pixel. Usually for a colored/gray scale image 256 levels are
used i.e. 8 bits/pixel (which result in 256 unique intensity values).

Both of these processes have their own effect on an image. In today’s Lab you are going to see
what the difference is when you change sampling rate and the quantization levels of an image.
See the code attached in the *.rar file. Execute this code. See what happens when you decrease
the sampling rate. Comment about the effects of changing number of quantization levels. Explain
the two processes in your Lab report and the effects that you witnessed upon changing the
corresponding values
Since MATLAB processes everything in the form of matrices or vectors, the images read in
MATLAB are no different. For now we will be working with gray scale images. Some helping
material will be uploaded about basic image analysis and theoretical background.

We will be using the following commands when dealing with images:


 imread()
 imshow()
 rgb2gray()
 im2bw()
 imwrite()
 imhist()

Question No :

Code:

Output :
Impulse Response :
Question No :

Code :
Output :
Figure No : 1

Green image :
Figure No : 2

Blue image :
Figure N0 : 3

Red image :
Figure No : 4

RGB Image :
COMSATS University Islamabad Abbottabad Campus

Department of Electrical (Power) Engineering

Lab Assignment: 13

Name & Registration No:

Zabeeh ullah & FA19-EPE-028

Semester: 5th

Class/Section: EPE-5C

Subject: Digital System Processing

Course Teacher: Sir Nauman Khan Tareen

Lab Teacher: Ms. Zenab Fazal

Submission Date: 07-Dec-2021

LAB N0 13
Analysis of FIR Digital Filter Design Using Various Techniques
FIR Digital Filter Design Using Window Method

Q. No 1:

Part (a):

Code:
clc;

clear all;

close all;

load chirp

t = (0:length(y)-1)/Fs;

bhi = fir1(34,0.48,'low',chebwin(35,30));

freqz(bhi,1)

outhi = filter(bhi,1,y);

subplot 211

plot(t,y)

title('Original Signal')

ys = ylim;

subplot 212

plot(t,outhi)

title('Low Pass Filtered Signal')

xlabel('Time (s)')

ylim(ys)
Output:

Part (b):
bm = fir1(46,[0.6 0.9]);

freqz(bm,1,512)

Output:

Part (c):
bw = fir1(46,[0.6 0.9],'stop');
freqz(bw,1)

fvtool(bw,1)

Output:

Part (d):
bm = fir1(46,[0.6 0.9]);

L = 46;

wvtool(hann(L))
Output:

Q. No 2:

Part (a):

Code:
N = 50;

Fs = 1e3;

Fstop1 = 150;

Fpass1 = 200;

Fpass2 = 300;

Fstop2 = 350;

Wstop1 = 3;

Wpass = 1;
Wstop2 = 100;

b = firpm(N,[0 Fstop1 Fpass1 Fpass2 Fstop2 Fs/2]/(Fs/2), ...

[0 0 1 1 0 0],[Wstop1 Wpass Wstop2]);

fvtool(b,1)

Output:
50
Magnitude (dB)

-50

-100
0 10 20 30 40 50 60 70 80 90 100
Frequency (Hz)
0
Phase (degrees)

-200

-400

-600
0 10 20 30 40 50 60 70 80 90 100
Frequency (Hz)
Magnitude Response (dB)

0.4

0.3

0.2
Magnitude (dB)

0.1

-0.1

-0.2

-0.3

-0.4

-0.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)

You might also like