DSP Lab Manual Final Final
DSP Lab Manual Final Final
LAB MANUAL
For the course
Instructor name:__________________________________
Student name:____________________________________
Roll no: Batch:___________________
Semester: Year:________________
LAB MANUAL
For the course
Approved By
____________________ ____________________
____________________ ___________________
____________________ ____________________
CONTENTS
Psychomotor Level: 4
CLO: Experimentally verify the analytical and design techniques developed for discrete time systems and signals.
[PLO (5)]
S.No. Date Title of Experiment Total Marks Signature
1. Before hitting the ‘run’, just try to understand what the code is doing and try to link it
with what we have studied in classes regarding concepts of frequency for DT signals.
LAB TASKS:
1. Consider the following CT signal:
x(t) = sin (2 pi F0 t). The sampled version will be:
x(n) = sin (2 pi F0/Fs n),
where n is a set of integers and sampling interval Ts=1/Fs.
Plot the signal x(n) for n = 0 to 99
for Fs = 5 kHz and F1 = 0.5, 2, 3 and 4.5 kHz. Explain the similarities and differences among
various plots.
clear all;
close all;
clc;
F1=500; %2000; %3000; %4500; %( here we are changing frequency of
analog signal keeping sampling frequency same to observe their plots
on same sampling frequency)
Fs=5000;
Ts=1/Fs
nTs=[0: Ts :99]
x1n=sin(2*pi*F1*nTs)
figure
stem(nTs,x1n,'filled','LineWidth',1)
grid on
title('500 Hz DTCV (sampled) signal')
xlabel('discrete time (sec)')
ylabel('amplitude')
xlim([0 0.01])
2. Generate a tone in MATLAB with varying frequency f = 1000,2000,3000,4000, 5000, 6000, 8000,
9000, 25000,-1000,-2000,-3000 Hz with Fs = 8000 samples/sec.
Listen to the tones, and observe at Sounds like what
frequency? Also Specify whether Aliasing is happening or not.
CODE FOR TASK 2:
Fs=8000;
f1=1000; f2=2000; f3=3000; f4=4000; f5=5000; f6=6000; f7=8000; f8=9000; f9=25000; f10=-
1000; f12=-2000; f13=-3000;
t= [0:1/Fs:5];
x= sin(2*pi*f2*t);
sound(x)
OBSERVATION:
Yes aliasing is happening, after listening the tones at different analog frequencies we can
say that.
f3 is an aliasing effect of f5 and f13. f1 is an aliasing effect of f8,f9 and f10.
f2 is an aliasing effect of f6 and f12.
3. Record a sentence in your voice.(you may use Simulink /audacity to record).Change Fs =44100,
22050, 11025, 8192, 4096 , 2048 , 1024
and observe
a) Voice quality during playback [Excellent/Good/OK/Bad]
b) File size in kilobytes
c) Aliasing happening or not?
OBSERVATION:
Voice quality is turning bad as we decrease the sampling frequency Yes aliasing is happening, after
decreasing sampling one by one frequency we can say that signal is losing its information.
In analog data communication (analog signals), the signal -to-noise ratio is defined as the ratio of the
average power in the signal versus the power in the noise level. In this context, think of a signal being
sent over a network connection compared to the extent to which the signal is corrupted. This is related to
the general usage of the term described above. This usage of the term SNR applies to analog signals.
SIGNAL-TO-QUANTIZATION-NOISE-RATIO-SQNR (OFADC):
Using finite word lengths prevents us from representing values with infinite precision, increases the
background noise in our spectral estimation techniques etc. The amount of error implicit in a chosen bit
depth can be measured in terms of the signal-to-noise ratio (SNR).
For a digitized image or sound, the signal-to-noise ratio is defined as the ratio of the maximum
sample value versus the maximum quantization error. In this usage of the term, the ratio depends on the bit
depth chosen for the signal. Any signal encoded with a given bit depth will have the same ratio. This can
also be called signal-toquantization-noise ratio (SQNR), but you should be aware that in many sources the
term signal-to-noise ratio is used with this meaning as well. (Henceforth, we'll use the term SQNR to
distinguish this measurement from SNR.)
Practical A/D converters are constrained to have binary output words of finite length. Commercial A/D
converters are categorized by their output word lengths, which are normally in the range from 8 to 16 bits.
There is no infinite bit ADC. So whenever we will digitize our signal, we will always have a quantization
error. Quantization error represents the quality of quantization process but the total error may also turn
out to be zero, so signal-toquantization-noise-ratio (SQNR) is used to describe the quality of quantization
process and it can be defined as
SQNRA/D = 10 log 10(Px /Pe)
Where, Px~and Pe are average power of the DTCV (sampled) signal and quantization error signal
respectively.
PROCEDURE:
1. Simulate a DTCV sinusoid of 1/50 cycles/sample with length of the signal be 500.
2. Choose the no. of significant digits for round-off and apply to the signal generated above.
3. Compute the error signals and SQNR
4. Explore and observe.
STEPS:
1. Make a folder at desktop and name it as your current directory within MATLAB.
2. Open M-file editor and write the following code:
3. Save the file as P021.m in your current directory and run it.
figure,
plot(q,SQNR);
xlabel('Significant
Digits'); ylabel('SQNR
(dB)'); xlim([q(1) q(end)]);
1. Before hitting the ‘run’, just try to understand what the code is doing and try to link it with
the previous code.
2. Now ‘run’ the file and observe the results.
RESULT:
Explain (write) in your own words the cause and effects of what you just saw.
LAB TASKS:
1. Effects of Quantization with variable precision levels
Simulate a DTCV sampled composite signal of 1=1/25 samples/sec and
2=1/50 samples/sec with length of the signal be 250 samples.
Take the desired number of significant digits from user as an input. Then choose the method
of Quantization (round-off, floor & ceil) and apply to the signal generated above. Compute the
quantization error signals and SQNR.
CODE FOR TASK:
fd1=1/25; Pe2r=sum(abs(x2r-x2).^2)/length(x2r-x2);
fd2=1/50; Pe2c=sum(abs(x2c-x2).^2)/length(x2c-x2);
n=[0:249]; Pe2f=sum(abs(x2f-x2).^2)/length(x2f-x2);
x1=sin(2*pi*fd1*n); SQNRr1=10*log(Px1/Pe1r);
x2=sin(2*pi*fd2*n); SQNRc1=10*log(Px1/Pe1c);
Px1=(sum(abs(x1).^2))/length(x1); SQNRf1=10*log(Px1/Pe1f);
Px2=(sum(abs(x2).^2))/length(x2); SQNRr2=10*log(Px2/Pe2r);
N=input('Enter the desired number of SQNRc2=10*log(Px2/Pe2c);
significant figures:'); SQNRf2=10*log(Px2/Pe2f);
x1r=round(x1*10^N)/10^N ; disp(['signal to quantization round off noise
x1c=ceil(x1*10^N)/10^N ; ratio for x1 is: ' num2str(SQNRr1)]);
x1f=floor(x1*10^N)/10^N ; disp(['signal to quantization ceiling noise
x2r=round(x2*10^N)/10^N ; ratio for x1 is: ' num2str(SQNRc1)]);
x2c=ceil(x2*10^N)/10^N ; disp(['signal to quantization floor noise ratio
x2f=floor(x2*10^N)/10^N ; for x1 is: ' num2str(SQNRf1)]);
Pe1r=sum(abs(x1r-x1).^2)/length(x1r-x1); disp(['signal to quantization round off noise
Pe1c=sum(abs(x1c-x1).^2)/length(x1c-x1); ratio for x2 is: ' num2str(SQNRr2)]);
Pe1f=sum(abs(x1f-x1).^2)/length(x1f-x1); disp(['signal to quantization ceiling noise
ratio for x2 is: ' num2str(SQNRc2)]); subplot(2,3,6)
disp(['signal to quantization floor noise ratio stem(n,x1f-x1);
for x2 is: ' num2str(SQNRf2)]); xlabel('Error')
figure, ylabel('Amp')
suptitle('For fd=1/25') xlim([0 10])
subplot(2,3,1) ylim([-0.2 0.2])
stem(n,x1); grid on
hold; figure,
stem(n,x1r); suptitle('fd=1/50')
xlabel('Indices') subplot(2,3,1)
ylabel('Amp') stem(n,x2);
xlim([0 10]) hold;
ylim([-1 1]) stem(n,x2r);
grid on xlabel('Indices')
subplot(2,3,4) ylabel('Amp')
stem(n,x1r-x1); xlim([0 10])
xlabel('Error') ylim([-1 1])
ylabel('Amp') grid on
xlim([0 10]) subplot(2,3,4)
ylim([-0.2 0.2]) stem(n,x2r-x2);
grid on xlabel('Error')
subplot(2,3,2) ylabel('Amp')
stem(n,x1); xlim([0 10])
hold; ylim([-0.2 0.2])
stem(n,x1c); grid on
xlabel('Indices') subplot(2,3,2)
ylabel('Amp') stem(n,x2);
xlim([0 10]) hold;
ylim([-1 1]) stem(n,x2c);
grid on xlabel('Indices')
subplot(2,3,5) ylabel('Amp')
stem(n,x1c-x1); xlim([0 10])
xlabel('Error') ylim([-1 1])
ylabel('Amp') grid on
xlim([0 10]) subplot(2,3,5)
ylim([-0.2 0.2]) stem(n,x2c-x2);
grid on xlabel('Error')
subplot(2,3,3) ylabel('Amp')
stem(n,x1); xlim([0 10])
hold; ylim([-0.2 0.2])
stem(n,x1f); grid on
xlabel('Indices') subplot(2,3,3)
ylabel('Amp') stem(n,x2);
xlim([0 10]) hold;
ylim([-1 1]) stem(n,x2f);
grid on xlabel('Indices')
ylabel('Amp')
xlim([0 10]) xlabel('Error')
ylim([-1 1]) ylabel('Amp')
grid on xlim([0 10])
subplot(2,3,6) ylim([-0.2 0.2])
stem(n,x2f-x2); grid on
THEORY:
i.e.one can compute the output y(n) to a certain input x(n) when impulse response h(n) of that system is
known. Convolution holds commutative property.
2. The length of the resulting convolution sequence is N+M-1,where N and M are the lengths of two
convolved signals respectively.
3. In causal system, the outputs only depend on the past and/or present values of inputs and NOT on future
values. This means that the impulse response h(n) of a causal system will always exist only for n≥ 0.
PROCEDURE:
subplot(3,1,1),
stem(nh,h);
xlabel('Time index n');
ylabel('Amplitude');
xlim([nh(1)-1 nh(end)+1]);
title('Impulse Response h(n)');
grid;
subplot(3,1,2),
stem(nx,x);
xlabel('Time index n');
ylabel('Amplitude');
xlim([nx(1)-1 nx(end)+1]);
title('Input Signal x(n)');
grid;
subplot(3,1,3)
stem(ny,y);
xlabel('Time index n');
ylabel('Amplitude');
xlim([ny(1)-1 ny(end)+1]); title('Output
Obtained by Convolution'); grid;
1. Save the file as P031.m in your current directory and ‘run’ it.
2. Calculate the length of input signal (N) and impulse response (M) used in above task?
3. Calculate the length of the output sequence and verify the result with N+M-1
4. Try to learn, explore the code and make notes.
5. Now modify the above code such that h(n)= {3,2, 1, -2,1,0,-4,0,3}(origin is shifted) and check for
causality.
RESULT:
EXERCISE:
3. Modify the code to prove Associative and Distributed properties of the convolution.
OBJECTIVE:
To study discrete time correlation and apply it to real data to observe the correlation
between two signals.
THEORY:
1. Correlation is given as where ‘l’ is the lag. This is called cross-correlation and it
gives the magniyude and location of similarity between two signals. The
correlation between x(n) and y(n) . It is given as:
2. Generally rxy(l) = ryx(l). These two are the same when x(n) and y(n) are the same signals
or when x(n) and y(n) are even symmetric signals .
3. The length of the resulting correlation sequence is N+M-1, where N and M are the
lengths of the two signals.
STEPS:
PROCEDURE:
1.Make a folder at desktop and name it as your current directory within MATLAB. -
2.Open M-file editor and write the following code: )
clear all;
close all;
clc;
n = [0:9];
ph1 = 0;
ph2 = 0;
x = sin(2*pi*0.1*n + ph1);
org_x = 1;
nx = [0 : length(x)-1]- org_x + 1;
y = sin(2*pi*0.1*n + ph2);
org_y = 1;
ny = [0 : length(y)-1]- org_y + 1;
rxy = xcorr(x,y);
nr = [nx(1)-ny(end) : nx(end)-ny(1)];
subplot(3,1,2),
stem(ny,y);
xlabel('Time index n');
ylabel('Amplitude');
xlim([ny(1)-1 ny(end)+1]);
title('Signal y(n)');
grid;
subplot(3,1,3)
stem(nr,rxy);
xlabel('Time index n');
ylabel('Amplitude');
xlim([nr(1)-1 nr(end)+1]);
title('Cross Correlation');
grid;
3.Save the file as P041.m in your current directory and ‘run’ it.
Learn the specific logical bits of the code and make notes
Now modify the phase of the second signal to pi/2 (it will make it cosine) and observe
the correlation at lag zero. Modify the phase again to ‘pi’ and observe.
1. Check for auto-correlation (ph1 = ph2) that the lag zero value gives the energy of the
Signal.
2. Observe that the commutative property does not hold.
RESULT:
CODING
The correlation at lag zero is: 4.1633e-16.
The maximum correlation is at lag 2.
close all;
clc;
n = [0:9];
ph1 = 0;
ph2 = pi/2;
x = sin(2*pi*0.1*n + ph1);
org_x = 1;
nx = [0 : length(x)-1]- org_x + 1;
y = sin(2*pi*0.1*n + ph2);
org_y = 1;
ny = [0 : length(y)-1]- org_y + 1;
rxy = xcorr(x,y);
nr = [nx(1)-ny(end) : nx(end)-ny(1)];
[maxR indR] = max(rxy);
disp(['The correlation at lag zero is: ' num2str(rxy(find(nr==0))) '.']);
disp(['The maximum correlation is at lag ' num2str(nr(indR)) '.']);
figure,
subplot(3,1,1),
stem(nx,x);
xlabel('Time index n');
ylabel('Amplitude');
xlim([nx(1)-1 nx(end)+1]);
title('Signal x(n)');
grid;
subplot(3,1,2),
stem(ny,y);
xlabel('Time index n');
ylabel('Amplitude');
xlim([ny(1)-1 ny(end)+1]);
title('Signal y(n)');
grid;
subplot(3,1,3)
stem(nr,rxy);
xlabel('Time index n');
ylabel('Amplitude');
xlim([nr(1)-1 nr(end)+1]);
title('Cross Correlation');
grid;
Please write in exercise book.
EXERCISE:
1. Now modify the phase of the second signal to pi/2 (it will make it cosine)and observe the
correlation at lag zero.
2. Modify the phase again to ‘pi’ and observe.
3. Check for auto-correlation (ph1 = ph2) that the lag zero value gives the m energy of the
signal.
4. Observe that the commutative property does not hold.
5. Modify the code, such that the correlation is obtained using convolution command.
6. Calculate correlation between voltages of any two phases of a 10HP motor Using the data
given below. First use Ms. Excel to copy data and then calculate correlation.
OUTPUT:
The auto correlation gives 25J energy.
OBJECTIVE:
To study the computer implementation of Discrete Fourier T transform and Inverse Fourier
Transform using Twiddle factor.
THEORY:
The formulas for the DFT and IDFT are given as
X(K) = ∑ −1
( )
; k=0,1,……N-1
=0
X(n) = ; k=0,1,……N-1
1 ∑ −1 ( ) −
=0
Where by definition WN =
− 2
W = − 2 /
PROCEDURE:
TASK
Compute 4 point DFT of x(n)= ( 1,2,3,0).
STEPS
1.Generate given sequence in Matlab .
2.Take N-=4 to calculate 4-point DFT.
3.Define 0: N-1 point vector for time and frequency samples.
4.Define W matrix and then use DFT analysis equation to compute DFT.
0, 0,
( ) = { , 4∠ − 90 ∘, 2∠45 ∘, 0, 2∠−45∘, 4∠90 ∘}
0, 0,
( ) = { , 4∠ − 90 ∘, 2∠45 ∘, 0, 2∠−45∘, 4∠90 ∘}
OBJECTIVE:
To observe/find different frequency components in an audio signal and plot it with different x_
axes .
THEORY:
PROCEDURE:
STEPS
1. Make a folder at desktop and name it as your current directory within MATLAB.
2. Copy the audio file ‘noisy.wav’ into your current directory.
3. Open M file editor and write the following code:
subplot(2,1,1);
plot(F,magY);
grid on;
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('DFT Magnitude');
title('Discrete Fourier Transform');
subplot(2,1,2);
plot(F,magY);
grid on;
xlim([0 2000]);
xlabel('Frequency (Hz)');
ylabel('DFT Magnitude');
title('Discrete Fourier
Transform');
4. Save the file as P081.m in your current directory and run it.
RESULT:
OBJECTIVE:
The purpose of this lab is to become familiar with the practical constraint in calculating the Fourier
transform of any real-world signal. i.e. DFT or FFT leakage and its solution.
INTRODUCTION:
Another way to think about DFT leakage is, when the input signal has frequencies which do
not complete integer number of cycles in the sample interval N (Length of DFT), the input to
DFT seems like abruptly starting and abruptly ending giving rise to side lobes in the DFT
output. A selection of finite input samples means that we have multiplied the input sequence
by a rectangular window. The DFT output will follow the Sinc shape which is the Fourier
Transform of the rectangular function. For real life signals, DFT leakage can never be entirely
eliminated because no matter what point DFT you take and no matter what your sampling rate
is, there is a very high probability that the input would contain a frequency which is not an
integer multiple of analysis frequencies and DFT leakage would happen. We can minimize
DFT leakage by multiplying the input with a smooth window which will make the input go
from zero to maximum and back to zero in a very smooth and slow fashion. This reduces the
abruptness of the input which minimizes the higher sides lobes in the DFT output.
Some Window functions and their spectrums
LAB TASKS
Fill the following table specifying whether DFT leakage would happen or not?
Calculate exactly how many cycles of the 440 Hz wave sampled at 1000 Hz are contained in the 1024-
sample window. Explain why this number indicates leads to spectral leakage.
a) Generate two sinusoids of frequencies 500 Hz and 600 Hz. Both signals should be
sampled at 8000 samples/sec.
b) Take 64-point DFT of both signals and observe their spectrums.
c) Comment on the DFT Leakage for both cases.
PROCEDURE:
Type wintool (Window Design & Analysis Tool) in the command window of MATLAB. Observe
different window functions like Rectangular (no window), Triangular, Hamming, Hanning,
Blackman, Flat Top, Gaussian etc. Attach the time domain and frequency domain representations of
various window functions and make a comparison between their performances on the basis of following
attributes:
a)
b)
Leakage Factor in %
Width of the main lobe in fraction of π ( ⁄ ) or ⁄2 ( ⁄sec )
b) Take 64-point DFT of the generated signal and observe the spectrum.
c) Comment on the DFT Leakage phenomenon for the above case.
d) Generate a triangular window function of 64 points.
e) Now apply a triangular window to the signal and then observe the spectrum of windowed
signal.
f) Change the window function from Triangular to Hamming, Hanning, Blackman, Flat
Top and Gaussian. Compare the results of these window functions on a signal's
spectrum.
PROCEDURE:
stem(Fk,X,'filled')
xlabel('Frequency (Hz)')
ylabel('DFT Magnitude')
title('Spectrum')
grid
Triangle window:
Hamming Window:
Hanning Window:
Flat top Window:
Blackman Window:
Gaussian Window:
OBJECTIVE:
To study s-plane and plot impulse and frequency response for different pole zero location in s-
plane. Also to determine weather system is FIR or IIR.
THEORY:
The Laplace Transform of a general continuous time signal x (t) is defined as;
PROCEDURE:
Generate pole zero constellation in s plane.
1. Plot corresponding Frequency (Bode magnitude) response.
2. Plot impulse response and determine that the system is FIR or IIR.
3. Modify location of poles in s plane to observe the corresponding change in frequency and
impulse response.
STEPS.
1. Make a folder at desktop and name it as your current directory within MATLAB.
2. Open M-file editor and write the following code:
RESULT:
1. Learn the specific logical bits of the code and make notes.
2. Observe the plots.
3. Now, explain (write) in your own words the cause and effects of what you just saw.
EXERCISE:
a) Generate pole zero constellation of an analog system in s-plane having only one pole at
s=0
b) Write the transfer function of a system
c) Plot the corresponding frequency response and impulse response of a system. Also
comment on the stability of system
PROCEDURE:
a) Make a folder at desktop and name it as your current directory within MATLAB.
b) Open M-file editor and write the following code:
a) Generate pole zero constellation of an analog system in s-plane having only one pole at: s = -0.5
b) Write the transfer function of a system
c) Plot the corresponding frequency response and impulse response of a system. Also comment on
the stability of system.
a) Generate pole zero constellation of an analog system in s-plane having only one pole at: s =0.5
b) Write the transfer function of a system
c) Plot the corresponding frequency response and impulse response of a system. Also comment on
the stability of system.
a) Generate pole zero constellation of an analog system in s-plane having pure imaginary poles at: s= = ± ⁄2
b) Write the transfer function of a system
c) Plot the corresponding frequency response and impulse response of a system. Also comment on
the stability of system.
Task-7: Analysis of 2nd order Analog system [complex zeros and poles at LHP]
a) Generate pole zero constellation of an analog system in s-plane for given roots. [zeros: = ± ( /2) & poles: = −0.2 ± ( /4)]
b) Write the transfer function of a system
c) Plot the corresponding frequency response and impulse response of a system. Also comment on
the stability of system.
Change the location of poles of a system defined in Task-7 from L.H.S of s-plane to axis first, and
then to R.H.S of s-plane and observe the effects on impulse response and frequency response of a
system.
To study z-plane and plot impulse and frequency response for different pole zero location in z-
plane.Also to determine weather system is FIR or IIR.
THEORY:
Where the complex variable z=r ∠w , with r the radius and w the angle. DTFT is a subset of z transform
when r =1. Since ‘r’ information is not present in DTFT, therefore information about stability in discrete
time can only be obtained from z transform. If pole lies inside the unit circle, system is stable. If pole lies
outside the unit circle, system is unstable. If pole lies at the unit circle, system is marginally stable or
oscillatory. If system has FIR, it is stable. If system is IIR, it can be stable or unstable .
PROCEDURE:
STEPS:
1. Make a folder at desktop and name it as your current directory within MATLAB.
2. Open M-file editor and write the following code:
RESULT:
1 Learn the specific logical bits of the code and make notes.
2 Observe the plots.
3 Now, explain (write) in your own words the cause and effects of what you just saw.
EXERCISE:
Task-1: Analysis of 1st order Digital system [one pole inside the Unit circle at DC]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zero: = 0 & pole: = 0.9∠0]
b) Write the transfer function of a system [see command window]
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
PROCEDURE:
c) Make a folder at desktop and name it as your current directory within MATLAB.
d) Open M-file editor and write the following code:
Task-3: Analysis of 1st order Digital system [one pole at the DC location of Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zero: = 0 & pole: = 1∠0]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-4: Analysis of 1st order Digital system [pole at the Fs/2 location of Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zero: = 0 & pole: = 1∠ ± ]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of digital system
Task-5: Analysis of 1st order Digital system [one pole outside the Unit circle at DC]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zero: = 0 & pole: = 1.1∠0]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-6: Analysis of 1st order Digital system [pole outside the Unit circle at Fs/2]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zero: = 0 & pole: = 1.1∠ ± ]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-7: Analysis of 2nd order Digital system [poles at origin]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 0.8944∠ ± 2 /3) & poles: = 0]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-8: Analysis of 2nd order Digital system [complex poles inside the Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 1∠ ± /2) & poles: = 0.8∠ ± /4]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-9: Analysis of 2nd order Digital system [complex poles at the Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 1∠ ± /2) & poles: = 1∠ ± /4]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-10: Analysis of 2nd order Digital system [complex poles outside the Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 1∠ ± /2) & poles: = 1.2∠ ± /4]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-11: Analysis of 2nd order Digital system [complex zeros inside the Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 0.8∠ ± /2) & poles: = 0.8∠ ± /4]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system
Task-12: Analysis of 2nd order Digital system [complex zeros outside the Unit circle]
a) Generate pole zero constellation in z-plane for the following roots of a digital system: [zeros: = 1.2∠ ± /2) & poles: = 0.8∠ ± /4]
b) Write the transfer function of a system
c) Determine that whether the digital system is FIR or IIR
d) Plot corresponding frequency response and impulse response of a digital system.
OUTCOME BASED EDUCATION
LAB RUBRICS
Digital Signal Processing (EE-394)
Student Name: Roll No: Section:
THEORY:
The process of deriving a realizable transfer function of a digital filter by considering given
frequency response specifications is known as digital filter design. The digital filter can be
classified as:
Butterworth filter
Chebyshev Type I filter
Chebyshev Type II
filter Elliptic filter
FIR digital filter operates on digital sample values. It uses current and past input samples to
produce a current output sample. It does not use previous output samples. There are various
types of FIR filter based on need viz. low pass, high pass, band pass and band stop, Low pass
filter.
Following points are usually considered to design FIR filter other the window type.
INPUT:
• Window Type
• Passband and stopband ripples
• passband and stopband edge frequencies
• sampling frequency
• order of the filter
• window coefficients
OUTPUT:
• magnitude and phase responses
PROCEDURE:
TASK-1
TASK -2
Write a program to design a FIR filter using Hanning windows,take inputs from user for design
values of filter.
close all;
clear all;
clc;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n=abs(n);
wp=2*fp/f;
ws=2*fs/f;
wn=(ws+wp)/2;
if (rem(n,2)==0)
m=n+1;
else
m=n;
n=n-1;
end
TASK-3
Write a program for FIR(Finite Impulse Response) filter like Low pass FIR filter, High pass FIR
filter, Band pass FIR filter and Band stop FIR filter using Rectangular window using MATLAB .
ALGORITHM:
LOW PASS FILTER:
Step 1: Read the input sequence
Step 2: Perform low pass filter calculations
Step 3: Plot the output sequences
PROGRAM:
clc; if(rem(n,2)~=0)
clear all; n1=n;
close all; n=n-1;
rp=input('Enter the passband end
ripple(rp):'); y=boxcar(n1);
rs=input('Enter the stopband %Low pass filter
ripple(rs):'); b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
fp=input('Enter the passband
m=20*log10(abs(h));
frequency(fp):'); subplot(2,2,1);
fs=input('Enter the stopband plot(m);
frequency(fs):'); ylabel('Gain(db)->');
f=input('Enter the sampling xlabel('(a)Normalised
frequency(f):'); frequency->');
wp=2*fp/f; %High pass filter
ws=2*fs/f; b=fir1(n,wp,'high',y);
num=-20*log10(sqrt(rp*rs))- [h,o]=freqz(b,1,256);
13; m=20*log10(abs(h));
dem=14.6*(fs-fp)/f;
n=ceil(num/dem); subplot(2,2,2);
plot(m);
n1=n+1;
ylabel('Gain(db)');
xlabel('(b)Normalised %Band stop
frequency'); filter==============
%Band pass filter wn=[wp*ws];
wn=[wp*ws]; b=fir1(n,wn,'stop',y);
b=fir1(n,wn,y); [h,o]=freqz(b,1,256);
[h,o]=freqz(b,1,256); m=20*log10(abs(h));
m=20*log10(abs(h)); subplot(2,2,4);
subplot(2,2,3); plot(m);
plot(m); ylabel('Gain(db)');
ylabel('Gain(db)'); xlabel('(d)Normalised
xlabel('(c)Normalised frequency-');
frequency');
EXERCISE:
Task-1: Designing of an IIR Butterworth filter
Design a 16th order IIR Butterworth bandpass filter with the following specifications:
a) Normalized pass band edges at 0.40 and 0.65
b) Normalized stop band edges at 0.3 and 0.75
c) Pass band ripple 1 dB
d) Minimum stop band attenuation 40 dB
Attach (i) Magnitude response (ii) Phase response (iii) Impulse Response (iv) Pole Zero plot
Attach (i) Magnitude response (ii) Phase response (iii) Impulse Response (iv) Pole Zero plot
Design an IIR filter with the following specifications: Pass band at pi/2 and stop bands at 0 and pi.
Take = 8000 .
THEORY:
Filter Design and Analysis Tool (FDA Tool) is Graphic User Interface for designing and
analyzing filters. It is used to design FIR and IIR filters by entering the desired filter
specifications, or by importing filter from MATLAB workspace or by adding, moving or
deleting poles and zeros. After designing a filter, the response can be viewed and analyses in
other Graphic User Interface tool named Filter Visualization Tool (FV Tool) linked with FDA
Tool. The different types of responses that can be viewed are listed below:
Magnitude response
Phase response
Group delay
Phase delay
Impulse response
Step response
Pole-zero plot
Zero-phase plot
Figure A
The different steps involved in designing a filter using FDA Tool can be listed as:
After providing the information listed above, filter can be designed and its response can be viewed and
analysed.
The complete description of the FDA Tool window and different steps required to design a filter
are elaborated below:
1. Selecting response type: The desired response type is selected from the list of available
options, i.e., lowpass, highpass, bandpass, bandstop, differentiation, multiband, peaking etc.
2. Type of design method: The design can be of FIR or IIR filter. Depending upon whether
FIR Or IIR filter design is selected, further options are available in the dropdown menu. In
IIR filter design, the different options available in dropdown menu are as given below:
Butterworth
Chebyshev type I
Chebyshev type II
Elliptic
Maximally flat
Least Pth-norm
Const least Pth-norm
Equirriple
Least square
Window
Const least squares
Complex equiripple
Least Pth norm
Constrained equiripple
Generalized equiripple
Constrained band equirriple
Interpolated FIR
The options available depend upon the selection of response type.
4. Filter specifications: Depending upon the response type and design method selected,
the graphical representation of generalized filter specifications appear in the display
region of FDA Tool. These specifications are ‘Frequency Specifications’ and
‘Magnitude Specification’.
These specifications are provided by the user, as per filter design requirement, in the
appropriate blocks.
5. Designing filter: After all the requisite information is entered, a filter can be designed by
clicking the ‘Design Filter’ button available at the bottom of the window. Filter |
coefficients are calculated and magnitude response appears in the display region.
(Note: ‘Design Filter’ button will be disabled once the filter coefficients are computed.
This button will be enabled again in case any changes are made in the filter specifications.)
lated as per the specifications provided by the user, the display region will show
magnitude response of the designed filter. The other filter response characteristics
can be viewed in the display region or FV Tool. The response to be viewed can be
selected from the different icons displayed on the toolbar shown in Figure below.
(NOTE: The different responses for display can also be selected from the
‘Analysis’ menu on menu bar.)
7. Current filter information: The information about the designed filter is given in
the ‘Current Filter Information’ region of FDA Tool window as shown
in Figure A The information provided is about the ‘structure’, ‘order’, ‘stability’ and
‘source’
Storing a filter
The designed filter is stored by clicking ‘Store Filter’ button in
the ‘Current Filter Information’ region.
Filter manager
The ‘Filter Manager’ button opens up a new Filter Manager window
(Figure B) showing the list of filters stored. This window also has
options as: Edit current filter, Cascade, Rename, Remove and FV Tool.
To cascade two or more filters, highlight the designed filters and press ‘Cascade’ button.
A new cascaded filter is added to the ‘Filter Manager’.
The response characteristics can be viewed in a separate window by selecting the ‘Filter
Visualization Tool’ (FV Tool) from ‘view’ menu or clicking the ‘Full View Analysis’ button
on the toolbar. The FV Tool window is shown in Figure C
FV Tool has most of the menus on the menu bar and icons on the toolbar similar to that FDA
Tool with some additional icons which are mainly used to work with representation of the
responses.
TASK-1
Design an IIR Butterworth band pass filter with the following specifications:
Show (i) Magnitude response (ii) Phase response (iii) Group delay (iv) Phase delay response.
Solution:
As per the given specifications, the requisite data is entered in new FDA Tool window
as shown in Figure
Figure. FDA Tool Window Showing Specification Entered and Magnitude Response for Task-1.
The filter is designed for minimum order so as to reduce the complexity of the design. In case, it
has to be designed for user defined order, then the order of the filter has to be calculated first by
user using appropriate formulas or MATLAB function.
The other responses can be viewed by clicking on the appropriate icon on the toolbar and
responses obtained are shown in Figures below
TASK-2
Design a Type II Chebyshev IIR lowpass filter with the following specifications :
Passband frequency 1,200 Hz
Solution: FDA Tool Window showing given specifications duly entered and magnitude
response in response display region is shown in Figure.
Solution:
As per given specifications, the requisite data is entered in FDA Tool window. By
clicking appropriate icon on toolbar, the magnitude and phase responses are obtained in
the same window.
1. These magnitude and phase responses obtained are viewed in FV Tool window also
and are shown in Figure .
Figure . Magnitude and Phase Response for Task-3.
2. To obtain the information about the filter ‘Filter Information’ icon on Toolbar of FDA
Tool Window is clicked or ‘Filter Information’ option is selected from ‘Analysis’ menu. The
detailed filter information appears in the display region as shown in Figure a, b and c.
Figure ‘Filter information’ for Task-2
The filter information is obtained by scrolling down the text in the window
shown in Figure 15.41b.
EXERCISE:
Record Your Voice at home while turn any motor of your house ON.
Design a filter using FDA Tool.
Remove sound of motor from recorded signal.
Listen the output signal.