DSP 394
DSP 394
DSP 394
Name:
Roll Number:
Class: Section:
Batch: Semester:
Department :
CONTENTS
Lab.
Title of Experiments Dated Remarks
No.
3 Discrete-Time Convolution.
4 Discrete-Time Correlation.
LAB SESSION 01
Effects of Sampling in Discrete Time Signals
OBJECTIVE:
To study the relationship between discrete-time and continuous time signals by examining
sampling and aliasing.
THEORY:
Signals are physical quantities that carry information in their patterns of variation. Continuous-
time signals are continuous functions of time, while discrete-time signals are sequences of
numbers. If the values of a sequence are chosen from a finite set of numbers, the sequence is
known as a digital signal. Continuous-time, continuous-amplitude signals are also known as
analog signals.
Sampling Theorem: A continuous time phenomenon or signal like x(t) can be reconstructed
exactly from its samples x(n) = x(nTs), if the samples are taken at a rate Fs = 1/Ts
that is greater than twice the frequency of the signal being sampled i.e. Fs ≥ 2 ∗ F.
Mathematically,
Aliasing: A common problem that arises when sampling a continuous signal is aliasing, where a
sampled signal has replications of its sinusoidal components which can interfere with other
components. It is an effect that causes two discrete time signals to become indistinct due to
improper sampling (fd>1/2 cycles/sample).
PROCEDURE:
1. Simulate and plot two CT signals of 10 Hz and 110 Hz for 0 < t < 0.2 secs.
2. Sample at Fs = 100 Hz and plot them in discrete form.
3. Observe and note the aliasing effects.
4. Explore and learn.
STEPS:
1. Make a folder at desktop and name it as your current directory within MATLAB.
2. Open M-file editor and type the following code:
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
F1 = 10;
F2 = 110;
Fs = 100;
Ts = 1/Fs;
t = [0 : 0.0005 : 0.2];
x1t = cos(2*pi*F1*t);
x2t = cos(2*pi*F2*t);
figure,
plot(t,x1t,t,x2t, 'LineWidth',2);
xlabel('cont time (sec)');
ylabel('Amp');
xlim([0 0.1]);
grid on;
legend('10Hz','110Hz');
title('Two CTCV sinusoids plotted');
3. Save the file as P011.m in your current directory and ‘run’ it, either using F5 key or
writing
the file name at the command window.
(Check for the correctness of the time periods of both sinusoids.)
Now add the following bit of code at the bottom of your P011.m file and save.
x1n = cos(2*pi*F1*nTs);
x2n = cos(2*pi*F2*nTs);
figure,
subplot(2,1,1),
stem(nTs,x1n,'LineWidth',2);
grid on;
xlabel('discrete time (sec)');
ylabel('Amp');
xlim([0 0.1]);
subplot(2,1,2)
stem(nTs,x2n,'LineWidth',2);
grid on;
title('110Hz sampled')
xlabel('discrete time(sec)');
ylabel('Amp');
xlim([0 0.1]);
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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.
2. Now ‘run’ the file and observe both plots.
To see what is really happening, type the following code at the bottom of your existing
P011.m file and run again.
figure,
plot(t,x1t,t,x2t);
hold;
stem(nTs,x1n,'r','LineWidth',2);
xlabel('time (sec)');
ylabel('Amp');
xlim([0 0.05]);
legend('10Hz','110Hz');
RESULT:
Explain (write) in your own words the cause and effects of what you just saw.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB TASKS:
LAB SESSION 02
Effects of Quantization in Discrete Time Continuous Valued Signals
OBJECTIVE:
To observe the quantization effects on sampled signals and to understand how quantization leads
to quantization error. In this lab, we will investigate the influence of the number of quantization
levels on the quality of digitized signal. Method of selection of ADC is also a part of this lab
session.
THEORY:
Everything stored on a computer is discrete time discrete valued signal. Because computer has
finite number of registers and each register is a finite length register. We take too many samples
to give the ‘effect’ of continuous time signals. But actually they are discrete time. We also take
very fine resolution of amplitude axis to give the effect of continuous valued signal but due to
finite word length of the computer register, the stored variables are already quantized. This lab
aims to explain the quantization effects in a computer.
Regardless of the medium (audio or image), the digitization of real world analog signal
usually involves two stages: sampling, i.e. the measurement of signal at discretely spaced
time intervals, and quantization, i.e. the transformation of the measurements (amplitudes)
into finite-precision numbers (allowed discrete levels), such that they can be represented in
computer memory. Quantization is a matter of representing the amplitude of individual
samples as integers expressed in binary. The fact that integers are used forces the samples to
be measured in a finite number of bits (discrete levels). The range of the integers possible is
determined by the bit depth, the number of bits used per sample. The bit depth limits the
precision with which each sample can be represented.
Bit Depth:
Within digital hardware, numbers are represented by binary digits known as bits—in fact, the
term bit originated from the words Binary digit. A single bit can be in only one of two possible
states: either a one or a zero. When samples are taken, the amplitude at that moment in time
must be converted to integers in binary representation. The number of bits used to represent
each sample, called the bit depth (bits/sample) or sample size, determines the precision with
which the sample amplitudes can be represented. Each bit in a binary number holds either a 1 or
a 0. In digital sound, bit depth affects how much you have to round off the amplitude of the
wave when it is sampled at various points in time
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
The number of different values that can be represented with b-bit is 2b .The largest decimal
number that can be represented with an b-bit binary number is 2 b - 1. For example, the
decimal values that can be represented with an 8-bit binary number range from 0 to 255, so
there are 256 different values (levels of ADC). A bit depth of 8 allows 2 8=256 different
discrete levels at which samples can be approximated or recorded. Eight bits together
constitute one byte. A bit depth of 16 allows 2 16 = 65,536 discrete levels, which in turn
provides much higher precision than a bit depth of 8.
The number of bits in a data word is a key consideration. The more bits used in the word, the
better the resolution of the number, and the larger the maximum value that can be represented.
Some computers use 64-bit words. Now, 264 is approximately equal to 1.8 x 1019—that's a pretty
large number. So large, in fact, that if we started incrementing a 64-bit counter once per second
at the beginning of the universe (≈20 billion years ago), the most significant four bits of this
counter would still be all zeros today.
To simplify the explanation, take an example of ADC with a bit depth of 3, 2 3 = 8
quantization levels ranging from -4 to 3 are possible in signed magnitude representation. For
bipolar ADCs (or signed magnitude representation), by convention, half of the quantization
levels are below the horizontal axis (that is 21, of the quantization levels). One level is the
horizontal axis itself (level 0), and 2b-1 − 1levels are above the horizontal axis.Note that since
one bit is used for the signed bit (in 2-complementformat), the largest magnitude corresponds
to 2^(b -1 ). (not 2b). When a sound is sampled, each sample must be scaled to one of the
8 discrete levels. However, the samples in reality might not fall neatly onto these levels. They
have to be rounded up or down by some consistent convention.
QUANTIZATION ERROR:
The samples, which are taken at evenly-spaced points in time, can take on the values only
at the discrete quantization levels to store on our computer. Therefore quantization leads
to a loss in the signal quality, because it introduces a “Quantization error”.
Quantization error is sometimes referred to as '"Quantization noise". Noise can be
broadly defined as part of an audio signal that isn’t supposed to be there. However, some
sources would argue that a better term for quantization error is "distortion", defining
distortion as an unwanted part of an audio signal that is related to the true signal.
The difference between the quantized samples and the original samples constitutes
quantization error or rounding error (if round-off method is used). Xe(n) = Xq(n) − x(n).
The lower the bit depth, the more values potentially must be approximated (rounded),
resulting in greater quantization error
To calculate the required bit depth of ADC i.e. bits/sample, there are two
important points which we must have to consider:
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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 represen ts
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
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:
clear all;
close all;
clc;
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
fd1 = 1/50;
n = [0 : 499 ];
SQNR = 10*log10(Px1/Pe1);
disp(['The Signal to Quantization Noise Ratio is: ' num2str(SQNR) '
dB.' ]);
figure,
subplot(2,1,1);
plot(n,x1,n,x1q);
xlabel('indices');
ylabel('Amp');
xlim([0 49]);
ylim([-1.1 1.1]);
legend('DTCV','DTDV');
subplot(2,1,2);
plot(n,x1e);
xlabel('indices');
ylabel('Error');
xlim([0 49]);
3. Save the file as P021.m in your current directory and run it.
clear all;
close all;
clc;
fd1 = 1/50;
n = [0 : 499 ];
q = [0 : 10];
x1e = x1 -x1q;
Pe1 = sum(abs(x1e).^2)/length(x1e);
SQNR(num) = 10*log10(Px1/Pe1);
end
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:
LAB SESSION 03
Discrete-Time Convolution
OBJECTIVE:
To study impulse response, observe convolution technique in signal processing, and verify
different properties like causality, commutative, distributive and associative properties.
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:
clear all;
close all;
clc;
h = [3 2 1 -2 1 0 -4 0 3]; % impulse response
org_h = 1; % Sample number where origin exists
nh = [0 : length(h)-1]- org_h + 1;
x = [1 -2 3 -4 3 2 1]; % input sequence
org_x = 1; % Sample number where origin exists
nx = [0 : length(x)-1]- org_x + 1;
y = conv(h,x);
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.
↑
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
RESULT:
EXERCISE:
3. Modify the code to prove Associative and Distributed properties of the convolution.
LAB SESSION 04
Discrete-Time Correlation
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.
4. Correlation may also be computed using convolution algorithm with a modification that
we need to fold one of the signals before applying convolution.
Mathematically, rxy(n)= x(n) * y(-n)
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: )
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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');
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
xlim([nr(1)-1 nr(end)+1]);
title('Cross Correlation');
grid;
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:
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.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB SESSION 05
Effects of Re-Sampling in Discrete Time Signals.
OBJECTIVE:
To study the process of sampling rate conversion of discrete signal and to note the effect of
sampling rate conversion in a real audio signal.
THEORY:
The process of converting a signal from a given sampling rate to a different sampling rate is called
sampling rate conversion. Systems that employ multiple sampling rate in the processing of digital
signals are called multi_rate digital signal processing systems. In a multi-rate DSP system
whenever a signal with one sampling rate used by a system that needs a different rate, sampling
rate has to be increased or decreased.
UP-SAMPLING
It is a process used to increase the sampling rate by an integer factor.
Up-sampling operation is implemented by inserting equidistant zero-valued samples between two
consecutive samples of x[n] .
In practice, the zero-valued samples inserted by the up-sampler are replaced with appropriate
nonzero values using some type of filtering process .Process is called zero stuffing.
Second method for up sampling is interpolation
Up_Sampler Used to increase the sampling rate by an integer factor
DOWN-SAMPLING:
It is a process used to decrease the sampling rate by an integer factor.
Down-sampler - Used to decrease the sampling rate by an integer factor
A down-sampler with a down-sampling factor M, where M is a positive integer, develops an
output sequence y[n] with a sampling rate that is (1/M)-th of that of the input sequence x[n].
Down-sampling operation is implemented by keeping every M-th sample of x[n] and removing
in-between samples to generate y[n]
Input-output relation
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
y[n] = x[nM]
RE-SAMPLING
Mostly we are required to implement both down_sampling and up_sampling to obtain the
sampling rate by a fractional value that can be expressed as a ratio. For example, to resample by
a factor of 1.5, we can interpolate by a factor of 3 then decimate (down_sample) by a factor of 2
(to change the sampling rate by a factor of 3/2=1.5).
𝐹𝑠𝑛ew = 𝐹𝑠𝑜ld ∗ (𝐿⁄𝑀)
TASK-1
1. Generate 50 sample of a sinusoid with fd=0.12 .
2. Up sample it by a factor of 6 using zero stuffing method.
PROCEDURE:
clf;
clear all;
clc;
close all;
n = 0:50;
x = sin(2*pi*0.12*n);
y = zeros(1, 6*length(x));
y([1: 6: length(y)]) = x;
subplot(2,1,1)
stem(n,x);
title('Input Sequence');
xlabel('Time index n');ylabel('Amplitude');
subplot(2,1,2)
stem(n,y(1:length(x)));
title('Output Sequence');
xlabel('Time index n');ylabel('Amplitude');
Task-2: Re-Sampling (Up sampling: Zero stuffing) of Sinusoids by an integer factor
a) Generate a composite signal of 100 Hz and 200Hz sinusoid originally sampled at Fs=1000 Hz.
b) Plot it in discrete form for two complete cycles.
c) Now up-sample the original signal such that the effective sampling rate will become Fs'=4000
Hz.
d) Observe and note the effects of up-sampling.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
figure
subplot(211)
stem(nTs,x,'k','Markerfacecolor','r','Linewidth',2)
xlabel('Discrete time (sec)'), ylabel('Amplitude'),axis tight,
grid,
legend('Original signal')
title('Original Signal')
subplot(212)
stem(tup,xup,'k','Markerfacecolor','r','Linewidth',2)
xlabel('Discrete time (sec)'), ylabel('Amplitude'),axis tight,
grid,
legend('Upsampled signal')
title('Interpolation')
a) Generate a 1Hz signal originally sampled at 20Hz. Now convert the original sampling rate
so that effective sampling rate will become 30Hz.
b) Attach plot and make notes.
x = 0.7*sin(2*pi*F*nTs)
figure;
stem(nTs,x); % Original sequence
L = 3; % Interpolation Factor
M = 2; % Downsample Factor
y = resample(x,L,M); % Re-sampling
Ts1= (Ts*M)/L;
ty = [0:length(y)-1]*Ts1; % New time vector ty
figure
stem(nTs,x,'*', 'Linewidth',2)
hold on
stem(ty,y,'-.r', 'filled')
xlabel('Time(sec)'), ylabel('Amplitude'), axis tight, grid,
legend('Original signal','Resampled signal'),
title('Original and Resampled signals')
EXERCISE:
1. Write values of corresponding input and output sequences to prove lab task 2.you may use
following table to note data. Also prove that value of up sampling factor.
Record your voice at sampling rate of 11025 Hz. Now down-sample and upsample the recorded
speech signal by different factors and observes the quality of re-sampled signals. Use this code:
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
4 5
5 6
6 7
7 8
8 9
9 10
10 11
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
e) Mention both the maximum downsampling limit (factor) and upsampling limit (factor)
in speech signal and also specify the reasons.
LAB SESSION 06
OBJECTIVE:
To study the computer implementation of Discrete FourierT transform and Inverse Fourier
Transform using Twiddle factor.
THEORY:
1 −𝑘𝑛
X(n) = ∑𝑁−1
𝑛=0 𝑋(𝑘) 𝑊𝑁 ; k=0,1,……N-1
𝑁
−𝑗2𝛱
Where by definition WN = 𝑒 𝑁
𝑘𝑛
W = 𝑒 −𝑗2𝛱𝑘𝑛/𝑁
𝑁
𝑘𝑛
XN=[ W ]xN
𝑁
𝑘𝑛 -1
xN= [W ] XN
𝑁
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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.
close all,
clear all;
clc;
x=[1 ,2 ,3 ,0];
N=4;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk
LAB TASK
Prove DFT synthesis equation using DFT output generated from lab task.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB SESSION 07
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:
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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:
EXERCISE:
LAB SESSION 08
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;
-st
∫
X(S) = x(t) e dt.
Where the complex variable s=δ+ j w, with δ and w the real and imaginary parts. CTFT is a
subset of Laplace when δ =0. Since ‘δ’ information is not present in CTFT, therefore information
about stability can only be obtained from Laplace. If pole lies on L.H.S of s-plane, system is
stable. If pole lies on R.H.S of s-plane, system is unstable. If pole lies on y(jw)-axis, system is
marginally stable or oscillatory. If system has FIR, it is stable. If system is IIR, it can be stable or
unstable.
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:
clear all;
close all;
clc;
Num = poly([(0-(i*(pi/2))),(0+(i*(pi/2)))]);
Zeros=roots(Num)
Den = poly([-1,-1]);
poles=roots(Den) sys=tf(Num,Den)
figure;
subplot(3,1,1);
pzmap(sys);
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
xlim([-2 2]);
ylim([-4 4]);
subplot(3,1,2);
[mag phase w]=bode(sys);
mag=squeeze(mag);
plot(w,mag);
subplot(3,1,3);
impulse(sys);
H=dfilt.df1(Num,Den);A=isfir(H)
3. Save the file as P091.m in your current directory and ‘run’ it.
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:
Change the location of poles from L.H.S of s-plane to y axis first, and then to R.H.S of s-
plane and observe the effects.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB SESSION 09
OBJECTIVE:
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:
X (z) = ∑∞
𝑛=𝑜 𝑥 (𝑛) z
-n
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:
clear all;
close all;
clc;
Num = poly([(0-(i*(pi/2))),(0+(i*(pi/2)))]);
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
Den = poly([-1,-1]);
Num1 = poly([j,-j]);
Den1 = poly([exp(-1),exp(-1)]);
sys1=tf(Num1,Den1,1)
figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);
subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])
subplot(3,1,3);
impulse(sys1);
H=dfilt.df1(Num,Den);
A=isfir(H)
figure;
pzmap(sys1)
grid on;
3. Save the file as P010.m in your current directory and ‘run’ it.
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:
Change the location of poles from inside the unit circle to outside and at the unit circle and
observe and note the changes.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB SESSION 10
OBJECTIVE:
Object of this lab is introduction to digital filters and its types, design FIR filter and study how it
performs filtering on a signal. Further truncate different types of FIR filter like Low Pass, High
Pass, Band Pass using different windows like rectangular, Kaiser Etc. and compare the results
obtained from different windows.
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
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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
F1 = 100; F2 = 150;
Fs = 1000;
yh = filtfilt(bh,1,x);
yl = filtfilt(bl,1,x);
% Plotting
figure, subplot(5,1,1),
plot(F,abs(fft(x)));
xlim([0 Fs/2]);
title('FFT of original signal');
subplot(5,1,2),
plot(F,abs(hh));
xlim([0 Fs/2]);
title('Frequency response of Filter One');
subplot(5,1,3),
plot(F,abs(fft(yh)));
xlim([0 Fs/2]);
title('FFT of filtered signal from filter one');
subplot(5,1,4),
plot(F,abs(hl));
xlim([0 Fs/2]);
title('Frequency response of Filter Two');
subplot(5,1,5),
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
plot(F,abs(fft(yl)));
xlim([0 Fs/2]);
title('FFT of filtered signal from filter two');
xlabel('Hz.')
[bh,ah] = eqtflength(bh,1);
[zh,ph,kh] = tf2zp(bh,ah);
[bl,al] = eqtflength(bl,1);
[zl,pl,kl] = tf2zp(bl,al);
figure,
subplot(1,2,1),
pzplane(bh,ah);
xlim([-1.5 1.5]);
ylim([-1.5 1.5]);
title('Filter_One');
subplot(1,2,2),
pzplane(bl,al);
xlim([-1.5 1.5]);
ylim([-1.5 1.5]);
title('Filter Two');
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);
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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
w=hann(m);
b=fir1(n,wn,'low',w);
freqz(b,1,500,3000);
TITLE('Magnitude and Phase response');
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;
clear all;
close all;
rp=input('Enter the passband ripple(rp):');
rs=input('Enter the stopband ripple(rs):');
fp=input('Enter the passband frequency(fp):');
fs=input('Enter the stopband frequency(fs):');
f=input('Enter the sampling frequency(f):');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=boxcar(n1);
%Low pass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(m);
ylabel('Gain(db)->');
xlabel('(a)Normalised frequency->');
%High pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
m=20*log10(abs(h));
subplot(2,2,2);
plot(m);
ylabel('Gain(db)');
xlabel('(b)Normalised frequency');
%Band pass filter
wn=[wp*ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(m);
ylabel('Gain(db)');
xlabel('(c)Normalised frequency');
%Band stop filter==============
wn=[wp*ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(m);
ylabel('Gain(db)');
xlabel('(d)Normalised frequency-');
EXERCISE:
Q1. Perform Q3.using Hamming and Kaiser Window.
Compare results of designed filters using three different windows on a single plot.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
LAB SESSION 11
Designing IIR using Filter Design and analysis Tool (FDA tool)
OBJECTIVE:
Object of this lab is to design different IIR filter using FDA tool.
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:
Figure A
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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
In FIR filter design the options available are listed as follows:
Equirriple
Least square
Window
Const least squares
Complex equiripple
Least Pth norm
Constrained equiripple
Generalized equiripple
Constrained band equirriple
Interpolated FIR
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
‘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:
Normalized pass band edges at 0.40 and 0.65
Normalized stop band edges at 0.3 and 0.75
Pass band ripple 1 dB
Minimum stop band attenuation 40 dB
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
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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.
By using the FV Tool, the magnitude response and pole/zero plot is obtained as separate figures and is
shown in Figures.
TASK-3:
Design an elliptic IIR low pass filter with following specifications:
Pass band ripple 0.5 dB
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.
Digital Signal Processing
NED University of Engineering & Technology Department of Electrical Engineering
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.