You are on page 1of 141

COMSATS CAMPUS ABBOTTABAD

LAB O1

NAME SYED MOAZZAM ALI

REG NUM FA19/EPE/112

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP

DATE 22 SEP 2021

LAB-1
TASK

Given that matrix A & B Find A+B Find A-BInverse Matrix of AVerify AB ≠
BAVerify AB = BA (point-to-point multiplication)

Find A+B

A= [1 2 3; 9 7 16;6 5 2]

A =

1 2 3
9 7 16
6 5 2

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

B =

-9 -8 -7
-1 -3 6
-4 -5 -8

A+B
ans =

-8 -6 -4
8 4 22
2 0 -6

Find A-B

A= [1 2 3; 9 7 16;6 5 2];

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


A-B

ans =

10 10 10
10 10 10
10 10 10

Inverse Matrix of A

A= [1 2 3; 9 7 16;6 5 2];

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

A^(-1)

ans =
-0.6667 0.1111 0.1111
0.7879 -0.1616 0.1111
0.0303 0.0707 -0.1111

Verify AB ≠ BA

A= [1 2 3; 9 7 16;6 5 2];

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

A*B
ans =

-23 -29 -19


-152 -173 -149
-67 -73 -28

B*A

ans =

-123 -109 -169


8 7 -39
-97 -83 -108

Verify AB = BA (point-to-point multiplication)


A= [1 2 3; 9 7 16;6 5 2];
B= [-9 -8 -7; -1 -3 6; -4 -5 -8];

C=A.*B

C =

-9 -16 -21
-9 -21 96
-24 -25 -16

D=B.*A

D =

-9 -16 -21
-9 -21 96
-24 -25 -16
UESTION 06

Q6 Draw x[n]=5sin(Ωn+pi/2) nϵ[-25, 25] , N = 4, 10, 21/2

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 Moazzam Ali')

ylabel('amplitude ')

grid('on')

FIGURE
AT 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 Moazzam Ali')

grid('on')

FIGURE

AT 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')

title('MOAZZAM ALI 112')

FIGURE
QUESTION 07:

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


x2[n]={0, -2.5, -3, -0.5, 0.5, 3} 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,'green')

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')

title('MOAZZAM ALI 112')

FIGURE

Q.8: Draw following signals


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

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)
c. x5[n] =ejΩ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('on')

title('MOAZZAM ALI 112')

FIGURE
d. x6[n] = ejΩn – e-jΩn /2i 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')

title('MOAZZAM ALI 112')

FIGURE
COMSATS CAMPUS ABBOTTABAD

LAB O2

NAME SYED MOAZZAM ALI

REG NUM FA19/EPE/112

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP
DATE 29 SEP 2021

LAB 2

Introduction to Signal Analysis and Continuous Time Fourier Transform using


Matlab

Objective:

In today’s Lab we will take a continuous time signal and use “fft” to estimate its continuous time
frequency transform.

Commands to be used:

• plot • real • exp • imag • fft


• fftshift • linspace • sin/cos

Help on these commands is available in MATLAB help directory.

Procedure:
1. Open M-file or M-Book

2. Save it by any useful name but remember not to start the name by any numeric digit, do not use any
special character other than under-the-score ( _ ) and also remember not to give any space in the name.
Task 01.

In order to generate a continuous time signal we require a fundamental frequency fn and a


simulated frequency fs.

4. Firstly, take a continuous time sinusoidal with fundamental frequency of fn=100 Hz & a simulated
sampling frequency of fs=100Hz.

5. Let “t” be an integer index.

6. In order to analyze its frequency spectrum using “fft” following step needs to be taken. a. Generate a
variable “N” indicating the size of frequency components let it be 1200. b. Now calculate the Fourier
transform using “fft”, and use “fftshift” to make the spectrum centered.

7. Use “linspace” to generate Ω-axis.

8. Now by varying the variable “t” & “fn” analyze the changes in the spectrum. As the spectrum is a
complex entity used magnitude, phase, real, and imaginary properties to conclude proper analysis.

Task II

9.Now generate a nonstationary signal as given below and compare the results with a stationary
one.���������������������������������������

NONSTATIONARY SIGNAL

���(���)=cos(2���(100)���������)���(���−10)+cos(2���(6
5)���������)���(−���+2)

CODE

close all;
clc;

fs=100;

t=[-2500:4500]/fs;

N=50;

w=cos(2*pi*100/fs*t).*heaviside(t-10)+cos(2*pi*65/fs*t).*heaviside(-t+2);

subplot(311)

plot(t,w),title('w(t)=cos(2*pi*100/fs*t)+cos(2*pi*65/fs*t) MOAZZAM'),

xlabel 't(sec)';

ylabel 'Amp';

grid on

axis([-1550/fs 4000/fs -1 1])

%generating CTFT using fft

omega=linspace(-fs/2,fs/2,N);

X=fftshift(fft(w,N));%use the code once with fftshift and once without fftshift &
explain

subplot(323),

plot(omega,abs(X)),

title '|W(e^j^\Omega) MOAZZAM |',

xlabel '\Omega (rad/sec)';ylabel 'Magnitude'; grid on

axis([-100 100 0 max(abs(X))])

subplot(324),plot(omega,angle(X)),title 'arg{W(e^j^\Omega)MOAZZAM}',

xlabel '\Omega (rad/sec)';

ylabel 'Phase'; grid on

axis([-100 100 min(angle(X)) max(angle(X))])


subplot(325),plot(omega,real(X)),title 'Re{W(e^j^\Omega) MOAZZAM}',

xlabel '\Omega (rad/sec)';

ylabel 'Real'; grid on

axis([-100 100 min(real(X)) max(real(X))])

subplot(326),plot(omega,imag(X)),title 'Im{W(e^j^\Omega)MOAZZAM}',

xlabel '\Omega (rad/sec)';

ylabel 'Imaginary'; grid on

axis([-100 100 min(imag(X)) max(imag(X))])

FIGURE:
STATIONARY SIGNAL:

���(���)=cos(2���(100)���������)+cos(2���(65)�������
��)

CODE
close all;

clc;

fs=100;
t=[-1550:4000]/fs;

N=50;

w=cos(2*pi*100/fs*t)+cos(2*pi*65/fs*t);

subplot(311)

plot(t,w),title('Stationary signal BY MOAZZAM'),

xlabel 't(sec)';

ylabel 'Amp';

grid on

axis([-1550/fs 4000/fs -1 1])

%generating CTFT using fft

omega=linspace(-fs/2,fs/2,N);

X=fftshift(fft(w,N));%use the code once with fftshift and once without fftshift &
explain

subplot(323),plot(omega,abs(X)),title '|W(e^j^\Omega)|',

xlabel '\Omega (rad/sec)';

ylabel 'Magnitude'; grid on

axis([-100 100 0 max(abs(X))])

subplot(324),plot(omega,angle(X)),title 'arg{W(e^j^\Omega)}',

xlabel '\Omega (rad/sec)';

ylabel 'Phase'; grid on

axis([-100 100 min(angle(X)) max(angle(X))])

subplot(325),plot(omega,real(X)),title 'Re{W(e^j^\Omega)}',

xlabel '\Omega (rad/sec)';

ylabel 'Real'; grid on

axis([-100 100 min(real(X)) max(real(X))])


subplot(326),plot(omega,imag(X)),title 'Im{W(e^j^\Omega)}',

xlabel '\Omega (rad/sec)';

ylabel 'Imaginary'; grid on

axis([-100 100 min(imag(X)) max(imag(X))])

FIGURE:

Questions:
1. Provide your analysis for the change in frequency fn.

As we know that

Ωs≥2Ωn

Or in the case of natural frequency and the sampling frequency

Fs≥2fn

According to the above equation

When the sampling frequency is less than the double of the natural frequency then this result in
the loss of the information and produce disturbance in our required signal and in short we lost
our information.

2. What is meant by the terms frequency resolution and time resolution?

Frequency Resolution:

It is the inverse of the time period to be observed in the signal

Such that,

1/T

Time Resolution:

Time resolution is equal to the inverse of the bandwidth or frequency to be observed at lower
band

Such that,

1/f

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

No, fourier transform didn’t provides us all required information because when we applied
fourier transform to the non stationary signals this result in the lost of data or information but in
case of stationary signal there is less data lost .
Conclusion:

We learnt about the fourier transform and how it effect on the stationary and the non-stationary
signal and we have seen the effect of the sampling frequency over the natural frequency .

COMSATS CAMPUS ABBOTTABAD

LAB 3

NAME SYED MOAZZAM ALI

REG NUM FA19/EPE/112

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP
DATE 06 OCT 2021

LAB TASK

STATEMENT Sampling of a Continuous Time Signal, its


Frequency Analysis & Reconstruction

Fn=35hz

CODE:
close all

clear all

clc

fs=1000;

t=-2:1/fs:2;

fn=35;

x=sin(2*pi*fn*t);

figure('name','sinusoidal signal by Moazzam 112');

plot(t,x);

grid on

Xjw=fftshift(fft(x,fs));

omega=linspace(-fs/2,fs/2,fs);
figure('name','fourier transform by Moazzam 112');

subplot(212)

plot(omega,abs(Xjw));

grid on

y=square(2*pi*70*t);

figure('name','square wave by Moazzam 112');

subplot(211)

plot(t,y);

grid on

impulse=abs(diff(y))/2;

for(i=1:length(impulse));

if impulse(i)==0

impulse(i)=1;

end

end

sample_signal=x(1:length(impulse)).*impulse;

figure('name','sample signal by moazzam 112');

stem(t(1:length(impulse)),(sample_signal));

FIGURES:
Fn=2hz

close all

clear all

clc

fs=1000;

t=-2:1/fs:2;

fn=2;
x=sin(2*pi*fn*t);

figure('name','sinusoidal signal by Moazzam 112');

plot(t,x);

grid on

Xjw=fftshift(fft(x,fs));

omega=linspace(-fs/2,fs/2,fs);

figure('name','fourier transform by Moazzam 112');

subplot(212)

plot(omega,abs(Xjw));

grid on

y=square(2*pi*70*t);

figure('name','square wave by Moazzam 112');

subplot(211)

plot(t,y);

grid on

impulse=abs(diff(y))/2;

for(i=1:length(impulse));

if impulse(i)==0

impulse(i)=1;

end

end

sample_signal=x(1:length(impulse)).*impulse;

figure('name','sample signal by moazzam 112');


stem(t(1:length(impulse)),(sample_signal));

FIGURES
Fn=200hz
close all

clear all

clc

fs=1000;

t=-2:1/fs:2;

fn=200;
x=sin(2*pi*fn*t);

figure('name','sinusoidal signal by Moazzam 112');

plot(t,x);

grid on

Xjw=fftshift(fft(x,fs));

omega=linspace(-fs/2,fs/2,fs);

figure('name','fourier transform by Moazzam 112');

subplot(212)

plot(omega,abs(Xjw));

grid on

y=square(2*pi*70*t);

figure('name','square wave by Moazzam 112');

subplot(211)

plot(t,y);

grid on

impulse=abs(diff(y))/2;

for(i=1:length(impulse));

if impulse(i)==0

impulse(i)=1;

end

end

sample_signal=x(1:length(impulse)).*impulse;
figure('name','sample signal by moazzam 112');

stem(t(1:length(impulse)),(sample_signal));

FIGURES
Question no 01

Provide your analysis for change in frequency of impulse train

By changing frequency of an impulse train, when we multiply our

original signal with impulse train we get different no of samples.

e.g

Higher the frequency of impulse train, greater the no of samples

Question no 02

Explain if you observe under, over sampling.

 If nyquist rate during sampling is satisfies then there will be no problem

while sampling and reconstruction.

Sampling frequency >=2*fundamental frequency

If nyquist rate during sampling is not satisfies then there will be aliasing

while sampling and reconstruction


COMSATS CAMPUS ABBOTTABAD

LAB 4

NAME SYED MOAZZAM ALI

REG NUM FA19/EPE/112

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP

DATE 06 OCT 2021

LAB TASK
RECONSTRUCTION OF SIGNAL

clc

close all

clear all

fs=50; % 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('con
tinuous signal')

grid on

subplot(222)

stem(1:length(t),x) %sampled signal

xlabel('time');title('sampled signal')

grid on

sum=0;

subplot(223)

for i=1:length(x)

sum=sum+x(i).*sinc(pi*(t-i.*T)/T); % convolution with sinc

hold on
plot(sum)

xlabel('time');title('convolution with sinc')

grid on

%pause(0.1)

end

subplot(224)

plot(t,sum,'linewidth',2) %reconstructed signal plotting

title('reconstructed signal plotting')

grid on

FIGURE
clc

close all

clear all

fs=50; % sampling freq

T=1/fs;

t=0:1/fs:4;

x=sin(2*pi*1*t)+sin(2*pi*2*t);% CT signal

subplot(221)
plot(t,x,'linewidth',2);xlabel('time');ylabel('x(t)');title('con
tinuous signal')

grid on

subplot(222)

stem(1:length(t),x) %sampled signal

xlabel('time');title('sampled signal')

grid on

sum=0;

subplot(223)

for i=1:length(x)

sum=sum+x(i).*sinc(pi*(t-i.*T)/T); % convolution with sinc

hold on

plot(sum)

xlabel('time');title('convolution with sinc')

grid on

%pause(0.1)

end

subplot(224)

plot(t,sum,'linewidth',2) %reconstructed signal plotting

title('reconstructed signal plotting')

grid on

FIGURE
QUESTION 2 AND 3 WAS COMPLETED IN PREVIOUS LAB

Question No 03
Analyze code and write a note on reconstruction.

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).

Question No 04

Change the value of fs and observe the reconstructed signal.

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.

COMSATS CAMPUS ABBOTTABAD

LAB 4
NAME SYED MOAZZAM ALI

REG NUM FA19/EPE/112

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP

DATE 19 OCT 2021


LAB N0 05

“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.

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 fir1command

choose any appropriate cut off frequency for HPF/LPF.

SIMULINK MODEL

SCOPE RESULT
2.Spectrum scope / filtering in MATLAB:

Generate two sampled sin waves (source in dsp library) of different frequencies in

Simulink f1=1850Hz, f2=6250Hzand add them together filter out the higher frequency

componentwith 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

SIMULATION
Lab Task b:Interpolation and Decimation Analyze:

INTERPOLATION/UPSAMPLE:
DECIMATION / DOWNSAMPLER:
COMSATS CAMPUS ABBOTTABAD

LAB 6
NAME SYED MOAZZAM ALI, AhSAN ULLAh

REG NUM FA19/EPE/112,FA19/EPE/096

SUBMITTED TO MA’AM ZENAB

SUBJECT DSP

DATE 27 OCT 2021


LAB 06

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

response

Objective:

The basic objective of this Lab is to understand Z-Transform in MATLAB. How to find poles/zeros of the

transfer function & Effect of pole and zeros on frequency response?

Commands to be used:
 ztrans  stem  zplane  title  roots  xlabel  tf2zp  ylabel  zp2tf  grid on  freqz  sym  stem
ones  subplot  zeros  figure  abs  eps  angle  sign

Help on these commands is available in MATLAB help directory.

Procedure:

1. Open M-file or M-Book.

2. Save it by any useful name but do not start the name by any numeric digit, do not use any special

character other than under-the score (_) and also remember not to give any space in the name.

3. Firstly, write numerator polynomial and denominator polynomial.

4. Using tf2zp command, convert it into z-plane.

5. Now take its frequency response either using freqz command or DTFT function.

6. Use zplane command to sketch the zplane, poles and zeroes.

7. Now change the location of poles and zeros and analyze the change in frequency response of the

system.

As in the case of the discrete-time Fourier transform, we restrict our attention here to a z-transform G(z)
of

a sequence g[n] that is a rational function of the complex variable z−1 and expressed in the form of a ratio

of polynomials in z−1 or in factored form. Some of the operations that are of interest in practice are as

follows.

1. Evaluate the z-transform G(z) on the unit circle, that is, evaluate G(ejω);

2. Develop the pole-zero plot of G(z);

3. Develop the factored form of G(z);

Analysis of z-Transforms

The function freqz can be used to evaluate the values of a rational z-transform on the unit circle. To this
end, Program P1 can be used without any modifications.

Question:

Using Program P1 evaluate the following z-transform on the unit circle:

���(���) = 2 + 5���−1 + 9���−2 + 5���−3 + 3���−4 /5 + 45���−1 +


2���−2 + ���−3 + ���−4

The pole-zero plot of a rational z-transform G(z) can be readily obtained using the function zplane. There

are two versions of this function. If the z-transform is given in the form of a rational function as in Eq.

above, the command to use is zplane(num, den) where num and den are row vectors containing the

coefficients of the numerator and denominator polynomials of G(z) in ascending powers of z−1. On the

other hand, if the zeros and poles of G(z) are given, the command to use is zplane(zeros, poles) where
zeros and poles are column vectors. In the pole-zero plot generated by MATLAB, the location of a pole is

indicated by the symbol × and the location of a zero is indicated by the symbol◦.

The function tf2zp can be used to determine the zeros and poles of a rational z-transform G(z) . The
program statement to use is [z, p, k] = tf2zp(num,den) where num and den are row vectors containing the
coefficients of the numerator and denominator polynomials of G(z) in ascending powers of z−1 and the
output file contains the gain constant k and the computed zeros and poles given as column vectors z and p,
respectively. The factored form of the z-transform can be obtained from the zero-pole description using
the function sos = zp2sos(z,p,k).

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).

CODE

clear all

close all

clc

num=[2 5 9 5 3];%COFFICIENT OF NUM

dnum=[5 4 2 1 1];%COFFICIENT OF DENUM

z=roots(num);%FINDING ZEROS

p=roots(dnum);%FINDING POLES

zplane(num',dnum');%ZPLOT

figure % FIGURE OF ZPLOT

zplane(z,p); % ZPLOT OF ZEROS AND POLES

title('MOAZZAM')

[z p k]=tf2zp (num,dnum)
Question 2:

CODE

clc

clear all

close all

n=[1 -2/3] ;%COFFICIENT OF NUM

d=[5 -1/7 15/7 -3/56] ;%COFFICIENT OF DENUM

z=roots(n); %FINDING ZEROS

p=roots(d); % FINDING ZEROS

zplane(n,d);

title('moazzam')

figure,

zplane(z,p)

title('moazzam')

[z p k]=tf2zp(n,d)
CODE

clc

clear all

close all

n=[1 3 -8]; ];%COFFICIENT OF NUM

d=[1 -13/9 4];%COFFICIENT OF DENUM

z=roots(n);

p=roots(d);

zplane(n,d);
title('moazzam')

figure,

zplane(z,p)

title('moazzam')

[z p k]=tf2zp(n,d)
LAB 07
Inverse Z-Transform in MATLAB
Student Name: Syed Moazzam Ali (fa19/epe/112)

Ehsan Ullah (fa19/epe/096)

Class/Section: EPE 5c

Semester: 5th

Lab Engineer Name: Maam Zenab Fazal

Course Teacher Name: Sir Nauman Khan Tareen

Submission Date: 02/Nov/2021


Questions:
1) Plot the following pole zero plots and also find their transfer function

clc

close all

clear all

poles=[-2;1/2]; %% ASSIGNING POLES

zero=[0]; %% ASSIGNING ZEROS

zplane(zero,poles);

[n,d]=zp2tf(zero,poles,1)

zplane(n,d)

h=filt(n,d)

impz(n,d); %% IMPULSE RESPONCE


IMPULSE RESPONCE
In this solution we have learnt that how to plot ploes and zeros and reversing the original
equation by given figure

PART B:

Clc; close all; clear all;poles=[1/3;2;3];

zero=[-1];%% ASSIGNNING ZEROS

zplane(zero,poles);

[n,d]=zp2tf(zero,poles,1)

zplane(n,d);

h=filt(n,d); %%FOR FINDINQ QUES EQ

impz(n,d); %% IMPULSE RESPONCE


IMPULSE RESPONSE;
QUESTION 2

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

using (0.4cos(90)+0.4sin(90)=0+j(0.4)+0-j(0.4)

close all;

clear all;

clc;

%% zeros and poles by given figure .

zeros=[0+j*0.4;0-j*0.4]; %% zeros in given figure


poles=[1/4]; %% poles in given figure

[a,b,c]=tf2zp(zeros ,poles); %% transfer func to z pane

zplane(zeros,poles);%% zplan

grid on

[n,d]=zp2tf(poles,zeros,1)%% zplane to transfer function

zplane(n,d)

h=filt(n,d)

title ('syed Moazzam Ali')


QUESTION 3

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

using (0.9cos(45)+0.9sin(45)=0.6+j(0.6)+0.6-j(0.6)
close all;

clear all;

clc;

%% zeros and poles by given figure .

zeros=[0.5]; %% zeros in given figure

poles=[0.6+j*0.6 ; 0.6-j*0.6]; %% poles in given figure

zplane(zeros,poles);%% zplan

grid on

[n,d]=zp2tf(poles,zeros,1)%% zplane to transfer function

zplane(n,d)

h=filt(n,d)

title ('syed Moazzam Ali')


QUESTION 4

4) Find the inverse z-transform of the following expression and from pole zero plot or from
transferfunction determine, whether it is FIR or IIR

system

close all

clear all

clc

syms z %% symbolic math toolbox

x(z)=(1-(1/2).*(z)^-1 )/(1+(3/4).*z^-1 +(1/8).*z^-2)

inverse_ztransform=iztrans(x(z)) %% command for inverse z transform

zeros=[1 -1/2] ; %% assigning zeros or num value


poles=[1 3/4 1/8]; %% assigning poles or den values

zplane(zeros,poles)

grid on

As by poles zeros graph we notice that the all poles and zeros not lies on origin so the given
system in IIR system

QUESTION 5
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.

close all

clear all

clc

syms z %% symbolic math toolbox

x(z)=(1-(1/2).*(z)^-1-(1/3).*z^-2 )/(1-(1/4).*z^-2)

inverse_ztransform=iztrans(x(z)) %% command for inverse z transform

zeros=[1 -1/2 -1/3] ; %% assigning zeros or num value

poles=[1 -1/4]; %% assigning poles or den values

zplane(zeros,poles)

grid on

title('Syed Moazzam Ali 112')


As by poles zeros graph we notice that the all poles and zeros not lies on origin so the given
system in IIR system

QUESTION 6

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.

close all

clear all
clc

syms z %% symbolic math toolbox

H(z)=(1+(2).*(z)^-1+(1).*z^-2 )/((1-(1/2).*z^-1).*(1-(1/4).*z^-2).*(1-
(1).*z^-1))

inverse_ztransform=iztrans(H(z)) %% command for inverse z transform

zeros=[1 2 1] ; %% assigning zeros or num value

poles=[1 -3/2 1/4 3/8 -1/8]; %% assigning poles or den values

figure,

zplane(zeros,poles)

grid on

figure;

impz(zeros,poles)%% impulse responce

title('Syed Moazzam Ali 112')


IMPULSE RESPONSE
As by poles zeros graph we notice that the all poles and zeros not lies on origin so the given
system in IIR system

QUESTION 7

A 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 determine whether it is FIR or IIR system?

close all

clear all

clc

syms z %% symbolic math toolbox

H(z)=((1).*(z)^-1+(3).*z^-2+(1/2).*(z)-(3).*(z)^2-(4).*z^3)

inverse_ztransform=iztrans(H(z)) %% command for inverse z transform

zeros=[1 3 1/2 -3 -4] ; %% assigning zeros or num value

zplane(zeros)

grid on

title('Syed Moazzam Ali 112')


From the graph and also from problem we notice that the denominator is 1 and poles and lies on
origin in unity circle so the system is FIR

Lab 8
Minimum phase system/ All-Pass systems/ FIR Filter Types/ Effect of integer/
non integer delay
Student Name: Syed Moazzam Ali (fa19/epe/112)
Ehsan Ullah (fa19/epe/096)
Class/Section: EPE 5c
Semester: 5th
Lab Engineer Name:
Maam Zenab Fazal
Course Teacher Name: Sir Nauman Khan Tareen
Submission Date: 10/Nov/2021
NOV/10/2021
SYED MOAZZAM ALI
FA19/EPE/112QUESTION 1
A discrete-time causal LTI system has the system function.
i) Find the magnitude / phase / group delay of �(�).
ii) Find the magnitude / phase / group delay of ����(z). Find the magnitude /phase /
group delay of ���(z)
clear all; close all; clc;
N=[1 3/2 -25 -37.5]
D=[1 0 0.49 0]
zplane(N,D);
[h,w]=freqz(N,D,'whole')
figure,
plot((w/pi)-1,abs(h),'r')
title('mag ,MOAZZAM')
figure,
plot((w/pi)-1,angle(h),'r')
title('phase ,MOAZZAM')
figure,
grpdelay(N,D)
title('grp delay ,MOAZZAM')clear all; close all; clc;
N=[1 3/2 -25 -37.5]
D=[1 0 0.49 0]
z=[1.5 ;5; -5]
p=[0.7i;-0.7i]
zplane(N,D);
[h,w]=freqz(N,D,'whole')
figure,
plot((w/pi)-1,abs(h),'r')
title('mag ,MOAZZAM')
figure,
plot((w/pi)-1,angle(h),'r')
title('phase ,MOAZZAM')
figure,
grpdelay(N,D)
title('grp delay ,MOAZZAM')
x=1
for i=1:length(z)
if abs(z(i))<=1
zm(x)=z(i);
else
zm(x)=1/z(i)
end
x=x+1
end
m=1for j=1:length(p)
if abs(p(j))<=1
pm(m)=p(j);
else
pm(m)=1/p(j)
end
m=m+1
end
figure,
zplane(zm',pm')
[nmp,dnm]=zp2tf(zm',pm',1)
%using fvtool for minimum pass
fvtool(nmp,dnm)clear all; close all; clc;
z=[1.5 ;5; -5]
p=[0.7i;-0.7i]
zapp=0;
papp=0;
x=1
for i=1:length(z)
if abs(z(i))>=1
zapp(x)=z(i);
papp(x)=1/z(i)
else
end
x=x+1
end
zplane(zapp',papp')
title('pole zero all phase ,MOAZZAM')QUESTION 2
A discrete-time causal LTI system has the system function.
i) Find the magnitude / phase / group delay of �(�).
ii) Find the magnitude / phase / group delay of ����(z). Find the magnitude /phase /
group delay of ���(z).
clear all; close all; clc;
N=[1 8*exp(-j*(pi/3)) 41 200*exp(-j*(pi/3)) 400]
D=[ 1 0 16.81 0 0 12.96]
zplane(N,D)
[h,w]=freqz(N,D,'whole')
figure,
plot((w/pi)-1,abs(h),'r')
title('mag ,MOAZZAM')
figure,
plot((w/pi)-1,angle(h),'r')
title('phase ,MOAZZAM')
figure,
grpdelay(N,D)
title('grp delay ,MOAZZAM')clear all; close all; clc;
N=[1 8*exp(-j*(pi/3)) 41 200*exp(-j*(pi/3)) 400]D=[ 1 0 16.81 0 0 12.96]
z=roots(N)
p=roots(D)
zplane(N,D)
x=1
for i=1:length(z)
if abs(z(i))<=1
zm(x)=z(i);
else
zm(x)=1/z(i)
end
x=x+1
end
m=1
for j=1:length(p)
if abs(p(j))<=1
pm(m)=p(j);
else
pm(m)=1/p(j)
end
m=m+1
end
figure,
zplane(zm',pm')
[nmp,dnm]=zp2tf(zm',pm',1)
%using fvtool for minimum pass
fvtool(nmp,dnm)clear all; close all; clc;
N=[1 8*exp(-j*(pi/3)) 41 200*exp(-j*(pi/3)) 400]
D=[ 1 0 16.81 0 0 12.96]
z=roots(N)
p=roots(D)
zplane(N,D)
zapp=0;
papp=0;
x=1
for i=1:length(z)
if abs(z(i))>=1
zapp(x)=z(i);
papp(x)=1/z(i)
else end
x=x+1
end
zplane(zapp',papp')
title('pole zero all phase ,MOAZZAM')
QUESTION 3
Decompose the given transfer function into a minimum phase and all
-pass system. Determine freqz response of both systems.
clear all; close all; clc;
N=[1 (7/2*exp(-j*(pi/4))+ 7/2*exp(j*(pi/4))) 49/9]
D=[ 1 -1/5]
zplane(N,D)
[h,w]=freqz(N,D,'whole')
figure,
plot((w/pi)-1,abs(h),'r')
title('mag ,MOAZZAM')
figure,plot((w/pi)-1,angle(h),'r')
title('phase ,MOAZZAM')
figure,
grpdelay(N,D)
title('grp delay ,MOAZZAM')clear all; close all; clc;
N=[1 (7/2*exp(-j*(pi/4))+ 7/2*exp(j*(pi/4))) 49/9]D=[ 1 -1/5]
z=roots(N)
p=roots(D)
zplane(N,D)
x=1
for i=1:length(z)
if abs(z(i))<=1
zm(x)=z(i);
else
zm(x)=1/z(i)
end
x=x+1
end
m=1
for j=1:length(p)
if abs(p(j))<=1
pm(m)=p(j);
else
pm(m)=1/p(j)
end
m=m+1
end
figure,
zplane(zm',pm')
[nmp,dnm]=zp2tf(zm',pm',1)
%using fvtool for minimum pass
fvtool(nmp,dnm)clear all; close all; clc;
N=[1 (7/2*exp(-j*(pi/4))+ 7/2*exp(j*(pi/4))) 49/9]
D=[ 1 -1/5]
z=roots(N)
p=roots(D)
zplane(N,D)
zapp=0;
papp=0;
x=1
for i=1:length(z) if abs(z(i))>=1
zapp(x)=z(i);
papp(x)=1/z(i)
else
end
x=x+1
end
zplane(zapp',papp')

title('pole zero all phase ,MOAZZAM')


LAB 09
“STRUCTURES IN SIMULINk AND DIGITAL FILTERS
IMPLEMENTATION”

STUDENT NAME: SYED MOAZZAM ALI (FA19/EPE/112)

CLASS/SECTION: EPE 5C

SEMESTER: 5Th

LAB ENGINEER NAME: MAAM ZENAB FAZAL

COURSE TEAChER NAME: SIR NAUMAN khAN TAREEN

SUBMISSION DATE: 16/NOv/2021


clear all

close all
clc

N=[1 2 1]

D=[1 -0.74 0.125]

impz(N,D);

fvtool(N,D)
clear all

close all

clc

N=[1 -4 2 -8]

D=[1 -0.5 3 -1.5]

impz(N,D);

fvtool(N,D)
clear all

close all

clc
N=[1 -25 1.5 -37.5]

D=[1 0.4]

impz(N,D);

fvtool(N,D)

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

STUDENT NAME: SYED MOAZZAM ALI (FA19/EPE/112)


CLASS/SECTION: EPE 5C

SEMESTER: 5Th

LAB ENGINEER NAME: MAAM ZENAB FAZAL

COURSE TEAChER NAME: SIR NAUMAN khAN


TAREEN

SUBMISSION DATE: 12/DEC/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.


 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?

Question 1

fs=50

[h,fs] = audioread('zgm.mp3') % where Fs is the sampling frequency.

sound(h,fs*2);

figure

subplot(311);plot(h);

y=fftshift(fft(h));

subplot(312);

plot(abs(y))
%% convolution

[l,fs] = audioread('quantum hall 5R.wav')

[H,fs] = audioread('zgm.mp3')

h=H(:,1);

r=conv(h,l,'same');

sound(r,fs)

figure,

plot(r)
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)

CODE:

A=imread('Hersee.jpg');

figure,

imshow(A);
%% gray

B=rgb2gray(A);

figure,

imshow(B);

%%im2bw

C=im2bw(A);

figure,

imshow(C);

%% colour

q=A

q(:,:,[1,3])=0

figure,

imshow(q)

Q=im2bw(A)

q=A

q(:,:,[2,3])=0

figure,

imshow(q)

Q=im2bw(A)
q=A

q(:,:,[3,3])=0

figure,

imshow(q)

Q=im2bw(A)

%% imhist

figure,

imhist(A);

%% imwrite

A = rand(500);

imwrite(A,'Hersee.jpg')

figure

imshow(A)

RESULTS:
LAB 13
Analysis of FIR Digital Filter Design Using Various Techniques

STUDENT NAME: SYED MOAZZAM ALI (FA19/EPE/112)


CLASS/SECTION: EPE 5C

SEMESTER: 5Th

LAB ENGINEER NAME: MAAM ZENAB FAZAL

COURSE TEAChER NAME: SIR NAUMAN khAN TAREEN

SUBMISSION DATE: 12/DEC/2021

LAB N0 13
Analysis of FIR Digital Filter Design Using Various Techniques
FIR Digital Filter Design Using Window Method
Design a 48th-order FIR bandpass filter with passband 0.35π≤ω≤0.65π rad/sample. Visualize its
magnitude and phase responses.
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
Load chirp.mat. The file contains a signal, y, that has most of its power above Fs/4, or half the
Nyquist frequency. The sample rate is 8192 Hz.
Design a 34th-order FIR highpass filter to attenuate the components of the signal below Fs/4. Use
a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple. Filter the signal. Display

the original and highpass-filtered signals. Use the same y-axis scale for both plots.

Q. No 1
(a) Design a lowpass filter with the same specifications. Filter the signal and compare the
result to the original. Use the same y-axis scale for both plots.
(b) Design a 46th-order FIR filter that attenuates normalized frequencies below 0.4π rad/sample
and between 0.6π and 0.9π rad/sample. Call it bM.
(c) Redesign bM so that it passes the bands it was attenuating and stops the other frequencies. Call
the new filter bW. Use fvtool to display the frequency responses of the filters.
(d) Redesign bM using a Hann window. (The 'DC-0' is optional.) Compare the magnitude
responses of the Hamming and Hann designs.
(e) Redesign bW using a Tukey window. Compare the magnitude responses of the Hamming and
Tukey designs.

%%%1 PART A
clc;
clear all;
close all;
load chirp
t = (0:length(y)-1)/Fs;
bhi = fir1(34,0.48,'low',chebwin(35,30));
figure,
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)
%%b
bm = fir1(46,[0.6 0.9]);
figure,
freqz(bm,1,512)
%%b
bm = fir1(46,[0.6 0.9]);
figure,
freqz(bm,1,512)

%%c
bw = fir1(46,[0.6 0.9],'stop');
figure,
freqz(bw,1)
fvtool(bw,1)

%%d
bm = fir1(46,[0.6 0.9]);
L = 46;
figure,
wvtool(hann(L))

%part 'e'
bW = fir1(46,[0.6 0.9],'stop');
tW = fir1(46,[0.6 0.9],'stop',tukeywin(46+1));

figure
hfvt = fvtool(bW,1,tW,1);
figure
legend(hfvt,'Hamming','Tukey')
bm = fir1(46,[0.6 0.9]);
figure,
freqz(bm,1,512)

%%c
bw = fir1(46,[0.6 0.9],'stop');
figure,
freqz(bw,1)
fvtool(bw,1)
%%d
bm = fir1(46,[0.6 0.9]);
L = 46;
figure,
wvtool(hann(L))
%part 'e'
bW = fir1(46,[0.6 0.9],'stop');
tW = fir1(46,[0.6 0.9],'stop',tukeywin(46+1));

figure
hfvt = fvtool(bW,1,tW,1);
legend(hfvt,'Hamming','Tukey')
QUESTION2
Q. No 2
(a) Use the Parks-McClellan algorithm to create a 50th-order equiripple FIR bandpass filter to
be used with signals sampled at 1 kHz.
(b) Specify that the passband spans the frequencies between 200 Hz and 300 Hz and that the
transition region on either side of the passband has a width of 50 Hz.
(c) Design the filter so that the optimization fit weights the low-frequency stopband with a
weight of 3, the passband with a weight of 1, and the high-frequency stopband with a weight
of 100. Display the magnitude response of the filter.
(d) Design the filter so that the optimization fit weights the low-frequency stopband with a
weight of 3, the passband with a weight of 1, and the high-frequency stopband with a weight
of 100. Display the magnitude response of the filter

clc
clear all,close all,
%%A
N = 50;
Fs = 1e3;
%%B
Fstop1 = 150;
Fpass1 = 200;
Fpass2 = 300;
Fstop2 = 350;
%%C
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)

You might also like