Professional Documents
Culture Documents
LAB O1
SUBJECT DSP
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
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];
ans =
10 10 10
10 10 10
10 10 10
Inverse Matrix of A
A= [1 2 3; 9 7 16;6 5 2];
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];
A*B
ans =
B*A
ans =
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
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)
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')
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')
FIGURE
QUESTION 07:
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')
FIGURE
clc;
clear all;
close all;
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')
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')
FIGURE
COMSATS CAMPUS ABBOTTABAD
LAB O2
SUBJECT DSP
DATE 29 SEP 2021
LAB 2
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:
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.
4. Firstly, take a continuous time sinusoidal with fundamental frequency of fn=100 Hz & a simulated
sampling frequency of fs=100Hz.
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.
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
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)),
subplot(324),plot(omega,angle(X)),title 'arg{W(e^j^\Omega)MOAZZAM}',
subplot(326),plot(omega,imag(X)),title 'Im{W(e^j^\Omega)MOAZZAM}',
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)
xlabel 't(sec)';
ylabel 'Amp';
grid on
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)|',
subplot(324),plot(omega,angle(X)),title 'arg{W(e^j^\Omega)}',
subplot(325),plot(omega,real(X)),title 'Re{W(e^j^\Omega)}',
FIGURE:
Questions:
1. Provide your analysis for the change in frequency fn.
As we know that
Ωs≥2Ωn
Fs≥2fn
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.
Frequency Resolution:
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 .
LAB 3
SUBJECT DSP
DATE 06 OCT 2021
LAB TASK
Fn=35hz
CODE:
close all
clear all
clc
fs=1000;
t=-2:1/fs:2;
fn=35;
x=sin(2*pi*fn*t);
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);
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;
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);
plot(t,x);
grid on
Xjw=fftshift(fft(x,fs));
omega=linspace(-fs/2,fs/2,fs);
subplot(212)
plot(omega,abs(Xjw));
grid on
y=square(2*pi*70*t);
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;
FIGURES
Fn=200hz
close all
clear all
clc
fs=1000;
t=-2:1/fs:2;
fn=200;
x=sin(2*pi*fn*t);
plot(t,x);
grid on
Xjw=fftshift(fft(x,fs));
omega=linspace(-fs/2,fs/2,fs);
subplot(212)
plot(omega,abs(Xjw));
grid on
y=square(2*pi*70*t);
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
e.g
Question no 02
If nyquist rate during sampling is not satisfies then there will be aliasing
LAB 4
SUBJECT DSP
LAB TASK
RECONSTRUCTION OF SIGNAL
clc
close all
clear all
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)
xlabel('time');title('sampled signal')
grid on
sum=0;
subplot(223)
for i=1:length(x)
hold on
plot(sum)
grid on
%pause(0.1)
end
subplot(224)
grid on
FIGURE
clc
close all
clear all
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)
xlabel('time');title('sampled signal')
grid on
sum=0;
subplot(223)
for i=1:length(x)
hold on
plot(sum)
grid on
%pause(0.1)
end
subplot(224)
grid on
FIGURE
QUESTION 2 AND 3 WAS COMPLETED IN PREVIOUS LAB
Question No 03
Analyze code and write a note on reconstruction.
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
Question No 04
Sampling frequency must be greater than or equal to twice the normal frequency
If fs is less than 2fn than their will be aliasing .we don’t get back original continuous
time signals.
LAB 4
NAME SYED MOAZZAM ALI
SUBJECT DSP
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
.
filter HPF/LPF in Simulink first generate filter coefficients in MATLAB using fir1command
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
SUBJECT DSP
response
Objective:
The basic objective of this Lab is to understand Z-Transform in MATLAB. How to find poles/zeros of the
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
Procedure:
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.
5. Now take its frequency response either using freqz command or DTFT function.
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ω);
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:
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
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
z=roots(num);%FINDING ZEROS
p=roots(dnum);%FINDING POLES
zplane(num',dnum');%ZPLOT
title('MOAZZAM')
[z p k]=tf2zp (num,dnum)
Question 2:
CODE
clc
clear all
close all
zplane(n,d);
title('moazzam')
figure,
zplane(z,p)
title('moazzam')
[z p k]=tf2zp(n,d)
CODE
clc
clear all
close all
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)
Class/Section: EPE 5c
Semester: 5th
clc
close all
clear all
zplane(zero,poles);
[n,d]=zp2tf(zero,poles,1)
zplane(n,d)
h=filt(n,d)
PART B:
zplane(zero,poles);
[n,d]=zp2tf(zero,poles,1)
zplane(n,d);
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;
zplane(zeros,poles);%% zplan
grid on
zplane(n,d)
h=filt(n,d)
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;
zplane(zeros,poles);%% zplan
grid on
zplane(n,d)
h=filt(n,d)
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
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
x(z)=(1-(1/2).*(z)^-1-(1/3).*z^-2 )/(1-(1/4).*z^-2)
zplane(zeros,poles)
grid on
QUESTION 6
c. From the pole/zero plot or from transfer function determines whether it FIR or IIR system.
close all
clear all
clc
H(z)=(1+(2).*(z)^-1+(1).*z^-2 )/((1-(1/2).*z^-1).*(1-(1/4).*z^-2).*(1-
(1).*z^-1))
figure,
zplane(zeros,poles)
grid on
figure;
QUESTION 7
. c. From the pole/zero plot or from transfer function determine whether it is FIR or IIR system?
close all
clear all
clc
H(z)=((1).*(z)^-1+(3).*z^-2+(1/2).*(z)-(3).*(z)^2-(4).*z^3)
zplane(zeros)
grid on
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')
CLASS/SECTION: EPE 5C
SEMESTER: 5Th
close all
clc
N=[1 2 1]
impz(N,D);
fvtool(N,D)
clear all
close all
clc
N=[1 -4 2 -8]
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
SEMESTER: 5Th
LAB 11-12
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
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
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
sound(h,fs*2);
figure
subplot(311);plot(h);
y=fftshift(fft(h));
subplot(312);
plot(abs(y))
%% convolution
[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
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
SEMESTER: 5Th
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)