DSP Lab File
DSP Lab File
Cycle I
Cycle II:
9. Implementation of HP IIR filter for a given sequence.
10. Implementation of Decimation Process.
11. Implementation of Interpolation Process.
12. Implementation of I/D sampling rate converters.
Additional experiments:
1. Determination of Power Spectrum of a given signal(s).
2. Converting CD DATA TO DVD DATA
Design Experiments
1. Audio application such as to plot a time and frequency display of microphone plus a cosine using DSP.
Read a .wav file and match with their respective spectrograms.
2. Noise removal: Add noise above 3 KHz and then remove interference suppression using 400 Hz tone.
Open Experiment
1. Impulse response of first order and second order systems.
2. Implementation of I/D sampling rate converters
Introduction
Starting MATLAB:
After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut icon
(MATLAB 7.0.4) on your Windows desktop. When you start MATLAB, a special window called the
MATLAB desktop appears. The desktop is a window that contains other windows. The major tools within or
accessible from the desktop are:
Figure 1.1: The graphical interface to the MATLAB workspace When MATLAB is started for the first
time, the screen looks like the one that shown
in the Figure 1.1. This illustration also shows the default configuration of the MATLAB desktop. You can
customize the arrangement of tools and documents to suit your needs.
Now, we are interested in doing some simple calculations. We will assume that you have sufficient
understanding of your computer under which MATLAB is being run. You are now faced with the MATLAB
desktop on your computer, which contains the prompt (>>) in the Command Window. Usually, there are 2
types of prompt:
Note: To simplify the notation, we will use this prompt, >>, as a standard prompt sign, Though our
As an example of a simple interactive calculation, just type the expression you want to
evaluate. Let’s start at the very beginning. For example, let’s suppose you want to calculate the expression, 1
+ 2 × 3. You type it at the prompt command (>>) as follows,
>> 1+2*3
ans = 7
You will have noticed that if you do not specify an output variable, MATLAB uses a
default variable ans, short for answer, to store the results of the current calculation. Note that the variable ans
is created (or overwritten, if it is already existed). To avoid this, you may assign a value to a variable or output
argument name. For example
>> x = 1+2*3
x =7
Will result in x being given the value 1 + 2*3=7. This variable name can always
be used to refer to the results of the previous computations. Therefore, computing 4 result in
>> 4*x
ans =28.0000
Before we conclude this minimum session, Table 1.1 gives the partial list of arithmetic Operators.
Operation Example
+ Addition 2+3
- Subtraction 2-3
* Multiplication 2*3
/ Division 2/3
3 Quitting MATLAB
To end your MATLAB session, type quit in the Command Window, or select File
Getting started
After learning the minimum MATLAB session, we will now learn to use some additional operations.
MATLAB variables are created with an assignment statement. The syntax of variable assignment is Variable
For example,
>> x = expression
Where expression is a combination of numerical values, mathematical operators, variables, and function calls.
On other words, expression can involve:
manual entry
built-in functions
user-defined functions
Overwriting variable
Once a variable has been created, it can be reassigned. In addition, if you do not wish to see the intermediate
results, you can suppress the numerical output by putting a semicolon (;) at the end of the line. Then the
sequence of commands looks like this:
>> t = 5;
>> t = t+1
t =6
Error messages
If we enter an expression incorrectly, MATLAB will return an error message. For example, in the following, we left
out the multiplication sign, *, in the following expression
>> x = 10;
>> 5x
Making corrections
To make corrections, we can, of course retype the expressions. But if the expression is
Lengthy, we make more mistakes by typing a second time. A previously typed command can be recalled with
the up-arrow key When the command is displayed at the command prompt, it can be modified if needed and
executed.
Let’s consider the previous arithmetic operation, but now we will include example,
>> (1+2)*3
ans =9
>> 1+2*3
ans =7
By adding parentheses, these two expressions give di errant results: 9 and 7 The order in which MATLAB
performs arithmetic operations is exactly that taught in high school algebra courses Exponentiations are done
first, followed by multiplications and divisions, and finally by additions and subtractions. However, the
standard order of precedence of arithmetic operations can be changed by inserting parentheses. For example,
the result of 1 +2×3 is quite deferent than the similar expression with parentheses (1+2) ×3. The results are 7
and 9 respectively. Parentheses can always be used to overrule priority and their use is recommended in some
complex expressions to avoid ambiguity.
Therefore, to make the evaluation of expressions unambiguous, MATLAB has established a series of rules.
The order in which the arithmetic operations are evaluated is given in Table 1.2. MATLAB arithmetic
operators obey the same precedence rules as those in Hierarchy of arithmetic operations Precedence
Mathematical operations
First The contents of all parentheses are evaluated first, starting from the innermost parentheses and working
outward Second All exponentials are evaluated, working from left to right Third All multiplications and
divisions are evaluated, working
from left to right Fourth All additions and subtractions are evaluated, starting
from left to rightmost computer programs. For operators of equal precedence, evaluation is from left to right
Now, consider another example:
In MATLAB, it becomes
=0.7766.
=10.1857.
So here what we get: two different results. Therefore, we want to emphasize the importance of precedence
rule in order to avoid ambiguity.
MATLAB by default displays only 4 decimals in the result of the calculations, for example -163. 6667, as
shown in above examples. However, MATLAB does numerical calculations in double precision, which is 15
digits. The command format controls how the results of computations are displayed. Here are some examples
of the different formats together with the resulting outputs
>> x=-163.6667
>> x= -1.636666666666667e+002
To return to the standard format, enter format short, or simply format there are several other formats. For more
details, see the MATLAB documentation, or type help format Note - Up to now, we have let MATLAB
repeat everything that we enter at the prompt (>>). Sometimes this is not quite useful, in particular when the
output is pages en length. To prevent MATLAB from echoing what we type, simply enter a semicolon (;) at
the end of the command. For example,
>> x=-163.6667;
>> x
x =-163.6667
The contents of the workspace persist between the executions of separate commands. There-fore, it is
possible for the results of one problem to have aneect on the next one. To avoid this possibility, it is a good
idea to issue a clear command at the start of each new independent calculation
>> Clear
The command clear or clear all removes all variables from the workspace. This
frees up system memory. In order to display a list of the variables currently in the memory type
>> Who
While, whose will give more details which include size, space allocation, and class of the variables
It is possible to keep track of everything done during a MATLAB session with the diary
command.
>> Diary
Or give a name to a created file
The function diary is useful if you want to save a complete MATLAB session.
They Save all input and output as they appear in the MATLAB window. When you want to stop the
recording, enter diary off. If you want to start recording again, enter diary on. The file that is created is a
simple text file. It can be opened by an editor or a word processing program and edited to remove extraneous
material, or to add your comments. You can use the function type to view the
diary file or you can edit in a text editor or print. This command is useful, for example in the process of
preparing a homework or lab submission.
It is possible to enter multiple statements per line. Use commas (,) or semicolons (;) to Enter
more than one statement at once. Commas (,) allow multiple statements per line Without
suppressing output
c =548.3170
Miscellaneous commands
Getting help
To view the online documentation, select MATLAB Help from Help menu or MATLAB Help directly in the
Command Window. The preferred method is to use the Help Browser. The Help Browser can be started by
selecting the? Icon from the desktop toolbar. On the other hand, information about any command is available
by typing
Another way to get help is to use the look for command. The look for commandeers
from the help command. The help command searches for an exact function name match, while the look for
command searches the quick summary information in each function for a match. For example, suppose that
we were looking for a function to take
The inverse of a matrix. Since MATLAB does not have a function named inverse, the command help inverse
will produce nothing. On the other hand, the command look for inverse will produce detailed information,
which includes the function of interest, inv
>> look for inverse
Note - At this particular time of our study, it is important to emphasize one main point.
of each function one by one. However, we will give you information how to get help. Here are some examples
• Use on-line help to request info on a specific function
• In the current version (MATLAB version 7), the doc function opens the on-line version of the help manual.
This is very helpful for more complex commands
Objective: To generate basic signals like unit impulse, unit step, unit ramp signal and Exponential signals
using MATlab.
y=[zeros(1,2),ones(1,1),zeros(1,2)] figure(1)
subplot(2,2,1); stem(t,y);
title('unit impulse');
y=ones(1,n); figure(2)
subplot(2,2,2);
stem(t,y); title('unit
step');
(c).Program for the generation of unit RAMP signal
y=ones(1,n); figure(3)
subplot(2,2,3);
y=exp(a*t); figure(4)
subplot(2,2,4);
stem(t,y);
2. AIM : To Generate continuous time sinusoidal signal, Discrete time cosine signal.
Requirements : Computer with MATLAB software
t=0:.01:pi;
y= sin(2*pi*t);
subplot(4,1,1);
t=0:.03:pi/3;
y= cos(2*pi*t);
subplot(4,1,2);
stem(t,y); xlabel('a(n)');ylabel('amplitude');title('cosinusoidal');
Results: Continuous time sinusoidal signal, discrete time cosine signal and sum of sinusoidal signal is
designed.
Outcomes: After finishing this experiment the students are able to
VIVA QUESTIONS:
7. Define D.T.S.
9. Define Stem, Plot, Plot3,fplot, ezplot, linspace, flyplr, grid,mesh and legend
FREQUENCY RESPONSE:
3. To find frequency response of a given system given in (Transfer Function/
Differential equation form).
AIM:- To write a MATLAB program to evaluate the Frequency response of the system .
Objective: To write a MATLAB program to evaluate the Frequency response of the system
.
EQUIPMENTS:
THEORY:-
The frequency response is a representation of the system's response to sinusoidal inputs at varying
frequencies. The output of a linear system to a sinusoidal input is a sinusoid of the same frequency but with a
different magnitude and phase. Any linear system can be completely described by how it changes the
amplitude and phase of cosine waves passing through it. This information is called the system's frequency
response. Since both the impulse response and the frequency response contain complete information about the
system, there must be a one-to-one correspondence between the two. Given one, you can calculate the other.
The relationship between the impulse response and the frequency response is one of the foundations of signal
processing: A system's frequency response is the Fourier Transform of its impulse response Since h [ ] is the
common symbol for the impulse response, H [ ] is used for the frequency response.
PROGRAM:
all;
% y[n]-0.25y[n-1]+0.45y[n-2]=1.55x[n]+1.95x[n-1]+ 2.15x[n-2]
subplot(2,1,1);
% figure(1); plot(t,h);
subplot(2,1,2);
% figure(2); stem(t,h);
title('plot of frequency response'); ylabel('amplitude');
xlabel('time index----->N'); disp(h);
grid on;
OUTPUT:
enter the coefficients of x(n),x(n-1)-----[1.55 1.95 2.15]
enter the coefficients of y(n),y(n-1)----[1 -.25 .45]
enter the number of samples of frequency response 1500
RESULT: The frequency response of given Differential equation is obtained. Hence the theory and
practical value are proved.
AIM:- To write a MATLAB program to evaluate the impulse response of the system .
OBJECTIVE:- To write a MATLAB program to evaluate the impulse response of the system using
MATlab.
EQUIPMENTS:
Operating System - Windows XP Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
The Difference equation is given as
y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
THEORY:-
LTI Discrete time system is completely specified by its impulse response i.e. knowing the impulse response
we can compute the output of the system to any arbitrary input. Let h[n] denotes the impulse response of the
LTI discrete time systems. Since discrete time system is time invariant, its response to [n-1] will be h[n-1]
.Likewise the response to [n+2] , [n-4] and [n-6] will be h[n+2], h[n-4] and h[n-6] .
From the above result arbitrary input sequence x[n] can be expressed as a weighted linear combination of
delayed and advanced unit sample in the form k=+
where weight x[k] on the right hand side denotes specifically the k th sample value of the sequence.
The response of the LTI discrete time system to the sequence x[k] [n-k]
As a result, the response y[n] of the discrete time system to x[n] will be given by k=+
The above equation (1) and (2) is called the convolution sum of the sequences x[n]
and h[n] and represented compactly as y[n]=x[n] * h[n] Where the notation * denotes the convolution sum.
This realization uses separate delays(memory) for both the input and output samples and it is called as
Direct form one structure.
A close approximation reveals that the two delay elements contain the same input
w(n) and hence the same output w(n-1).consequently these two elements can be merged into
one delay. In contrast to the direct form I structure , this new realization requires only one
delay for auxiliary quantity w(n) ,and it is more efficient in terms of memory requirements. It
PROGRAM:-
all;
% y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
subplot(2,1,1);
% figure(1); plot(t,h);
title('plot of impulse response');
ylabel('amplitude'); xlabel('time index----
->N'); subplot(2,1,2);
% figure(2); stem(t,h);
title('plot of impulse response');
ylabel('amplitude'); xlabel('time index----
->N'); disp(h);
grid on;
Output
enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85] enter the coefficients of y(n),y(n-1)-----[1 -1 -1] enter the
number of samples of imp respons 41.0000 1.5000
3.3500
4.8500
CALCULATIONS:-
y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
y(n) - y(n-1) - y(n-2) = x(n) + 0.5x(n-1) + 0.85x(n-2) Taking Z transform on both sides,
Y(Z) - Z-1 Y(Z)- Z-2 Y(Z) = X(Z) + 0.5 Z-1 X(Z) + 0.85 Z-2 X(Z) Y(Z)[1 - Z-1 - Z-2] = X(Z)[1 + 0.5 Z-1 +
0.85 Z-2 ]
= [1 + 0.5 Z-1 + 0.85 Z-2 ]/ [1 - Z-1 - Z-2] By dividing we get H(Z) = 1 + 1.5 Z-1 + 3.35 Z-2 + 4.85 Z-3
h(n) = [1 1.5 3.35 4.85]
RESULT: The impulse response of given Differential equation is obtained. Hence the theory and practical
value are proved
Outcome: The students are able to write the MATlab code to find the impulse response of given Differential
equation is obtained and the theory and practical value are proved
Dev Bhoomi Institute Of Technology LABORATORY
Department of Electronics and Communication MANUAL
Engineering
PRACTICAL INSTRUCTION SHEET
EXPERIMENT NO. 6 ISSUE NO. : ISSUE DATE:JULY 2010
REV. NO. : REV. DATE : PAGE: 6
LABORATORY Name & Code: Digital Signal Processing SEMESTER: III
Objective: To wite the MATlab code to find the DFT / IDFT of given signal.
MATLAB Code:
w = [0:500]*pi/500;
z = exp(-j*w);
x = 3*(1-0.9*z).^(-1);
a = abs(x);
b = angle(x)*180/pi;
subplot(2,1,1);
plot(w/pi,a);
subplot(2,1,2);
plot(w/pi,b);
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY:
Discrete Time Fourier Transform:
In general X(ejω) is a complex function of the real variable ω and can be written as
where Xre(ejω) and Xim(ejω) are, respectively, the real and imaginary parts of X(ejω), and are real functions of ω.
X(ejω) can alternately be expressed in the form
The quantity |X(ejω)| is called the magnitude function and the quantity θ(ω) is called the phase function
In many applications, the Fourier transform is called the Fourier spectrum and, likewise, |X(ejω)| and θ(ω)
are referred to as the magnitude spectrum and phase spectrum, respectively.
The DTFT X(ejω) is a periodic continuous function in ω with a period 2π. The DTFT satisfies a
number of useful properties that are often uitilized in a number of applications.
MATLAB COMMANDS:
For complex Z, the magnitude R and phase angle theta are given by:
angle (Z)
Y = fft(X) returns the discrete Fourier transform of vector X, computed with a fast Fourier transform
(FFT) algorithm.
Y = fft(X)
Compute the discrete Fourier transform of the following function analytically and Then plot the
magnitude and phase:
num=[2 1]
den=[1 –0.6]
MATLAB CODE:
4*pi:8*pi/511:4*pi;
num = [2 1];
den = [1 -0.6];
h = freqz(num, den, w);
subplot(2,2,1)
subplot(2,2,2)
plot(w/pi,imag(h)); grid on;
subplot(2,2,3)
num=[2 1]
den=[1 –0.6]
MATLAB CODE:
subplot(2,2,1)
subplot(2,2,2)
subplot(2,2,3)
plot(w/pi,abs(h)); grid on;
ylabel('Amplitude');
subplot(2,2,4)
plot(w/pi,angle(h));
grid on;
title('Phase Spectrum
arg[H(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase, radians');
PROGRAM:
Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.
-------------*******-------------- OUTPUT
Enter the the value of N(Value of N in N-Point DFT)4 Enter the sequence for which DFT is to be
calculated [1 2 3 4]
Outcomes:
VIVA QUESTIONS:
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY: The Fast Fourier Transform is useful to map the time-domain sequence into a continuous function
of a frequency variable. The FFT of a sequence {x(n)} of length N is given by a complex-valued sequence
X(k).
M nk
j
X(k) x(n) e n k N
k
The above equation is the mathematical representation of the DFT. As the number of computations involved
in transforming a N point time domain signal into its corresponding frequency domain signal was found
to be N2 complex multiplications, an alternative algorithm involving lesser number of computations is opted.
When the sequence x(n) is divided into 2 sequences and the DFT performed separately, the resulting
number of computations would be N2/2 i.e.
Consider x(2n) be the even sample sequences and x(2n+1) be the odd sample sequence derived form
x(n).
N/
would result in
(12)
The time burden created by this large number of computations limits the usefulness of DFT in many
applications. Tremendous efforts devoted to develop more efficient ways of computing DFT resulted in the
above explained Fast Fourier Transform algorithm. This mathematical shortcut reduces the number of
calculations the DFT requires drastically. The above mentioned radix-2 decimation in time FFT is employed
for domain transformation.
Dividing the DFT into smaller DFTs is the basis of the FFT. A radix-2 FFT divides the DFT into two
smaller DFTs, each of which is divided into smaller DFTs and so on, resulting in a combination of two-
point DFTs. The Decimation -In-Time (DIT) FFT divides the input (time) sequence into two groups, one
of even samples and the other of odd samples. N/2 point DFT are performed on the these sub-sequences
and their outputs are combined to form the N point DFT.
The above shown mathematical representation forms the basis of N point FFT and is called the
Butterfly Structure.
STAGE - II
STAGE – I
STAGE - III FIG. 3A.2 - 8 POINT DIT
The Fast Fourier Transform (FFT) is just a computationally fast way to calculate the DFT.
Determine the Fourier transform of the following sequence. Use the FFT (Fast Fourier
Transform) function.
x (n) = {4 6 2 1 7 4 8}
MATLAB Code: for defined sequence n = 0:6;
x = [4 6 2 1 7 4 8];
a = fft(x);
mag = abs(a); pha =
angle(a); subplot(2,1,1);
plot(mag); grid on
title('Magnitude Response');
subplot(2,1,2);
plot(pha); grid on
title('phase Response');
PROGRAM:
mag=abs(X_k);
phase=angle(X_k)*180/pi;
subplot(2,1,1);
stem(mag); xlabel('frequency index
k');
ylabel('Magnitude of X[k]'); axis([0 N+1
-2 max(mag)+2]); subplot(2,1,2);
stem(phase); xlabel('frequency index
k'); ylabel('Phase of X[k]'); axis([0
N+1 -180 180]);
X=
EQUIPMENTS:
In the previous section we saw how to unwrap the FFT and get back the sine and cosine coefficients.
Usually we only care how much information is contained at a particular frequency and we don’t really care
whether it is part of the sine or cosine series. Therefore, we are interested in the absolute value of the FFT
coefficients. The absolute value will provide you with the total amount of information contained at a given
frequency, the square of the absolute value is considered the power of the signal. Remember that the
absolute value of the Fourier coefficients are the distance of the complex number from the origin. To get the
power in the signal at
each frequency (commonly called the power spectrum) you can try the following commands.
This set of commands will return something much easier to understand, you should get 1 at a frequency of 1
and zeros everywhere else. Try substituting cos for sin in the above commands, you should get the same
result. Now try making >>f = sin(2*pi*t) + cos(2*pi*t). This change should result in twice the power
contained at a frequency of 1.
Thus far we have looked at data that is defined on the time interval of 1 second, therefore we could interpret
the location in the number list as the frequency. If the data is taken over an arbitrary time interval we need to
map the index into the Fourier series back to a frequency in Hertz. The following m-file script will create
something that might look like data that we would obtain from a sensor. We will
.
PROGRAM:
OUTPUT:-
RESULT: The power spectral density of given sequence is obtained. Hence the theory and practical
value are proved.
Outcome: At the end of the experiment the students are able to find the power spectral density of given
sequence is obtained.
VIVA QUESTION:
1. What do you mean by phase spectrum and magnitude spectrum/ give comparison?
2. How do you reduce spectral leakage?
3. What do you mean by spectral resolution?
Dev Bhoomi Institute Of Technology LABORATORY
Department of Electronics and Communication MANUAL
Engineering
PRACTICAL INSTRUCTION SHEET
EXPERIMENT NO. 8 ISSUE NO. : ISSUE DATE:
REV. NO. : REV. DATE : PAGE: 8
LABORATORY Name & Code: Digital Signal Processing SEMESTER: V
EXPERIMENT # 6 & 7
AIM : Design of FIR filters of Low pass and high pass filter using Matlab commands
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
.
DESCRIPTION: Digital filters refers to the hard ware and software implementation of the mathematical
algorithm which accepts a digital signal as input and produces another digital signal as output whose wave
shape, amplitude and phase response has been modified in a specified manner. Digital filter play very
important role in DSP. Compare with analog filters they are preferred in number of application due to
following advantages.
pass FIR digital filter and returns the filter coefficients in length N+1 vector B. The cut- off
frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The
filter B is real and has linear phase. The normalized gain of the filter at Wn is -6 dB.
B = FIR1(N,Wn,'high') designs an N'th order highpass filter.
If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband
W1 < W < W2.
B = FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. You can also specify If Wn is a multi-element
vector, Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands 0 < W <
W1, W1 < W < W2, ..., WN < W < 1.
By default FIR1 uses a Hamming window. Other available windows, including Boxcar, Hann, Bartlett,
Blackman, Kaiser and Chebwin can be specified with an optional trailing argument.
For filters with a gain other than zero at Fs/2, e.g., highpass and bandstop filters, N must be even.
Otherwise, N will be incremented by one. In this case the window length should be specified as
N+2.
By default, the filter is scaled so the center of the first pass band has magnitude exactly one after windowing. Use a
trailing 'noscale' argument to prevent this scaling, e.g.
B = FIR1(N,Wn,'noscale')
B = FIR1(N,Wn,'high','noscale') B =
FIR1(N,Wn,wind,'noscale').
You can also specify the scaling explicitly, e.g. FIR1(N,Wn,'scale'), etc.
FREQZ Digital Filter Frequency Response.
[H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-
point frequency vector W in radians/sample of the filter: given numerator and denominator
coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced
around the upper half of the unit circle. If N isn't specified, it defaults to 512.
[H,F] = FREQZ(B,A,N,Fs) and [H,F] = FREQZ(B,A,N,'whole',Fs) return frequency vector F (in Hz),
where Fs is the sampling frequency (in Hz).
H = FREQZ(B,A,F,Fs) returns the complex frequency response at the frequencies designated in vector F
(in Hz), where Fs is the sampling frequency (in Hz).
[H,W,S] = FREQZ(...) or [H,F,S] = FREQZ(...) returns plotting information to be used with FREQZPLOT. S
is a structure whose fields can be altered to obtain different frequency response plots. For more information
see the help for FREQZPLOT.
FREQZ(B,A,...) with no output arguments plots the magnitude and unwrapped phase of the filter in the
current figure window
fs=8000; n=50;
w=1200/ (fs/2);
b=fir1(n,w,'high');
freqz(b,1,128,8000); % this function plots the phase(degree)and magnitude in db
subplot(2,1,2)
figure(2) [h,w]=freqz(b,1,128,8000);
plot(w,abs(h)); % Normalized Magnitude Plot
title('Magnitude Plot ');
grid
figure(3)
zplane(b,1); % this function plots fiq in zplane
n=50;
w=1200/ (fs/2);
b=fir1(n,w,'high');
freqz(b,1,128,8000); figure(2)
[h,w]=freqz(b,1,128,8000);
figure(3) zplane(b,1);
[h,w]=freqz(b,1,128,8000);
figure(3) zplane(b,1);
figure(2) [h,w]=freqz(b,1,128,8000);
figure(3)
zplane(b,1);
b=fir1(n,w); freqz(b,1,128,8000)
figure(2) [h,w]=freqz(b,1,128,8000);
figure(3) zplane(b,1);
RESULT: The FIR low pass & high pass filter for given values is obtained. Hence the ideal and
practical response of FIR filter are proved.
Outcomes:
After finishing this experiment the students are able to:
VIVA QUESTION:
1. What is filter?
2. What is FIR and IIR filter define, and distinguish between these two?
3. What is window method? How you will design an FIR filter using window method?
4. What are low-pass and band-pass filter and what is the difference between these two?
5. What is the matlab command for Hamming window? Explain.
6. What do you mean by built in function ‘abs’ and where it is used?
7. Explain how the FIR filter are stable?
8. Why is the impulse response "finite"?
9. What does "FIR" mean?
10. What are the advantages of FIR Filters (compared to IIR filters)?
11. What are the disadvantages of FIR Filters (compared to IIR filters)?
12. What terms are used in describing FIR filters?
13. What is the delay of a linear-phase FIR?
14. What is the Z transform of a FIR filter?
15. What is the frequency response formula for a FIR filter?
16. How Can I calculate the frequency response of a FIR using the Discrete Fourier Transform (DFT)?
17. What is the DC gain of a FIR filter?
Dev Bhoomi Institute Of Technology LABORATORY
Department of Electronics and Communication MANUAL
Engineering
PRACTICAL INSTRUCTION SHEET
EXPERIMENT NO. 9 ISSUE NO. : ISSUE DATE:
REV. NO. : REV. DATE : PAGE: 8
LABORATORY Name & Code: Digital Signal Processing SEMESTER: V
EXPERIMENT # 8 & 9
IMPLEMENTATION OF ANALOG IIR LOW PASS AND HIGH PASS FILTER FOR A GIVEN
SEQUENCE
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY: Matlab contains various routines for design and analyzing digital filter IIR. Most of these are
part of the signal processing tool box. A selection of these filters is listed below.
Ellipord ( for calculating the order of filter) Ellip (creates an IIR filter)
Cheb1ord (for calculating the order of filter) Cheyb1 (creates an IIR filter)
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth
filter that loses no more than Rp dB in the pass band and has at least Rs dB of attenuation in the stop
band. Wp and Ws are the pass band and stop band edge frequencies, normalized from 0 to 1 (where
1 corresponds to pi radians/sample).
For example
Low pass: Wp = .1, Ws = .2 High pass:
Wp = .2, Ws = .1 Band pass: Wp = [.2 .7],
Ws = [.1 .8]
Band stop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency") to use with
BUTTER to achieve the specifications.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and
Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD.
[N, Wn] = ELLIPORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital elliptic
filter that loses no more than Rp dB in the pass band and has at least Rs dB of attenuation in the
stop band Wp and Ws are the pass band and stop band edge frequencies, normalized from 0 to 1
(where 1 corresponds to pi radians/sample).
For example
ELLIPORD also returns Wn, the elliptic natural frequency to use with ELLIP to achieve the
specifications.
[N, Wn] = ELLIPORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp
and Ws are in radians/second. NOTE: If Rs is much greater than Rp, or Wp and Ws are very close, the
estimated order can be infinite due to limitations of numerical precision.
[N, Wn] = CHEB1ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Chebyshev Type I filter that loses no more than Rp dB in the pass band and has at least Rs dB of
attenuation in the stop band. Wp and Ws are the pass band and stop band edge frequencies,
normalized from 0 to 1 (where 1 corresponds to pi radians/sample).
For example,
CHEB1ORD also returns Wn, the Chebyshev natural frequency to use with CHEBY1 to achieve the
specifications. [N, Wn] = CHEB1ORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.
[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the
filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients are
listed in descending powers of z. The cutoff frequency Wn must be
0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate.
If Wn is a two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband
W1 < W < W2.
[B,A] = BUTTER(N,Wn,'high') designs a highpass filter.
When used with three left-hand arguments, as in [Z,P,K] = BUTTER(...), the zeros and poles are
returned in length N column vectors Z and P, and the gain in scalar K. When used with four left-
hand arguments, as in [A,B,C,D] = BUTTER(...), state-space matrices are returned.
[B,A] = ELLIP(N,Rp,Rs,Wn) designs an Nth order low pass digital elliptic filter with Rp decibels
of peak-to-peak ripple and a minimum stop band attenuation of Rs decibels.
ELLIP returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator).The cutoff
frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. Use Rp = 0.5 and Rs =
20 as starting points, if you are unsure about choosing them. If Wn is a two- element vector, Wn = [W1 W2],
ELLIP returns an order 2N band pass filter with pass band W1 < W < W2. [B,A] =
ELLIP(N,Rp,Rs,Wn,'high') designs a high pass filter.
When used with three left-hand arguments, as in [Z,P,K] = ELLIP(...), the zeros and poles are
returned in length N column vectors Z and P, and the gain in scalar K. When used with four left-
hand arguments, as in [A,B,C,D] = ELLIP(...), state-space matrices are returned.
[B,A] = CHEBY1(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with R decibels of peak-
to-peak ripple in the passband. CHEBY1 returns the filter coefficients in length N+1 vectors B (numerator)
and A (denominator). The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the
sample rate. Use R=0.5 as a starting point, if you are unsure about choosing R.
If Wn is a two-element vector, Wn = [W1 W2], CHEBY1 returns an order 2N bandpass filter with passband
W1 < W < W2.
When used with three left-hand arguments, as in [Z,P,K] = CHEBY1(...), the zeros and poles are returned
in length N column vectors Z and P, and the gain in scalar K.
When used with four left-hand arguments, as in [A,B,C,D] = CHEBY1(...), state-space matrices are returned.
CHEBY1(N,R,Wn,'s'), CHEBY1(N,R,Wn,'high','s') and CHEBY1(N,R,Wn,'stop','s')
design analog Chebyshev Type I filters.In this case, Wn is in [rad/s] and it can be greater than 1.0.
ALGORITHM:
PROCEDURE:
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
2*fp/f w2 = 2*fs/f
5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following function]
[n,wn]=buttord(w1,w2,rp,rs,’s’)
6) Design an nth order analog lowpass Butter worth filter using the following statement.
[b,a]=butter(n,wn,’s’)
7) Find the complex frequency response of the filter by using ‘freqs( )’ function
[h,om]=freqs(b,a,w) where, w = 0:.01:pi
This function returns complex frequency response vector ‘h’ and frequency vector ‘om’ in
radians/samples of the filter.
a(s) a(1)Sna-1+a(2)Sna-2+…………..a(na)
Where a,b are the vectors containing the denominator and numerator coefficients.
relevant names to x and y axes and give an appropriate title for the plot. 11)Repeat the
9) Repeat the program for Chebyshev type-I and Chebyshev type-II filters.
PROGRAM CODE:
rp=1; rs=50;
[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wn);
[h,w]=freqz(b,a,128);
subplot(2,2,1) plot(abs(h));
xlabel('frequency');
ylabel('amplitude');
rp=1; rs=50;
[n,wn]=buttord(wp,ws,rp,rs); n
[b,a]=butter(n,wn);
[h,w]=freqz(b,a,128);
subplot(2,2,3)
plot(abs(h));
xlabel('frequency');6
ylabel('amplitude');
rp=1; rs=30;
[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wn, 'high');
[h,w]=freqz(b,a,128);
subplot(2,2,2) plot(abs(h));
xlabel('frequency');
ylabel('amplitude');
rp=1; rs=30;
[n,wn]=buttord(wp,ws,rp,rs); n
[b,a]=butter(n,wn,'high');
[h,w]=freqz(b,a,128);
subplot(2,2,4) plot(abs(h));
xlabel('frequency');
ylabel('amplitude');
OUTPUT:
RESULT: The IIR low pass & high pass IIR filter for given values is obtained. Hence the ideal and
practical response of IIR filter are proved.
Outcomes:
After finishing this experiment the students are able to:
1. Implement HP FIR filter for a given sequence
2. Plot the response of the same.
VIVA QUESTION:
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
PROGRAME:
clear all close all
echo on
t0=.2; % signal duration ts=0.001; %
sampling interval fc=250; % carrier
frequency fs=1/ts; % sampling
frequency t=[-t0/2:ts:t0/2]; % time
vector kf=100; % deviation constant
m=cos(2*pi*10*t); % the message signal
int_m(1)=0;
for i=1:length(t)-1 % integral of m
int_m(i+1)=int_m(i)+m(i)*ts; echo off ;
end
echo on ;
u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal
subplot(2,1,1);
plot(t,u); hold on;
plot(t,m,'r');
subplot(2,1,2);
plot(t,filter_out); hold on;
plot(t,m,'r')
RESULT: The sinusoidal signal is generated from filter response for given values .
Outcome : At the end of the experiment the students are able to generate a sinusoidal signal is generated
from filter response for given values
VIVA QUESTION:
1. What is the special about minimum phase filter?
2. In signal processing, why we are much more interested in orthogonal transform?
3. How is the non-periodic nature of the input signal handled?
4. If a have two vectors how will i check the orthogonality of those vectors?
Dev Bhoomi Institute Of Technology LABORATORY
Department of Electronics and Communication MANUAL
Engineering
PRACTICAL INSTRUCTION SHEET
EXPERIMENT NO. 11 ISSUE NO. : ISSUE DATE:
REV. NO. : REV. DATE : PAGE: 3
LABORATORY Name & Code: Digital Signal Processing SEMESTER: V
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY :
Decimation is the process of reducing the sampling frequency of a signal to a lower sampling frequency that
differs from the original frequency by an integer value. Decimation also is known as down-sampling. The
lowpass filtering associated with decimation removes high-frequency content from the signal to
accommodate the new sampling frequency.
Decimation is useful in applications in which the Nyquist frequency of a signal is much higher than the
highest frequency of the signal. Decimation filters help you remove the excess bandwidth and reduce the
sampling frequency of the signal. Decimation filters also help you reduce the computational resources
required for processing and storing the signal. During the analog-to-digital (A/D) conversion process,
decimation filters also can reduce the variance of quantization noise in a signal and maintain the signal
power, thus improving the signal-to-noise ratio (SNR).
The following figure shows a typical M-fold decimation filter, where M is the integer value by which you
want to decrease the sampling frequency. This filter contains a lowpass FIR filter H(z). This lowpass FIR
filter is an anti-aliasing filter followed by anM-fold decimator. The decimator passes every Mth sample and
discards the other samples. After this operation, the decimation filter changes the sampling frequency fs of
the input signal x(n) to a new sampling frequency fs/M. The decimation filter then returns an output signal
y(n) with the new sampling frequency.
equation for decimation
To prevent aliasing, this system uses the lowpass filter H(z) before the M-fold decimator to suppress the
frequency contents above the frequency fs/(2M), which is the Nyquist frequency of the output signal. This
system produces the same results as an analog anti-aliasing filter with a cutoff frequency of fs/(2M) followed
by an analog-to-digital (A/D) converter with a sampling frequency
of fs/M. Because the system shown in the figure above is in the digital domain, H(z) is a digital anti- aliasing
filter.
PROGRAM:
Xlable(‘time’);
Ylabel(‘amplitude’);
RESULT: The decimator for a given sequence is observed for chosen factor M. Hence the
theory and practical is verified.
Outcome : At the end of the experiment the student is able to perform decimator for a given sequence is
observed for chosen factor M.
VIVA QUESTION:
1. What is the importance of decimation for a given signal/sequence?
2. What do you mean Aliasing? What is the condition to avoid aliasing for sampling?
3. How does poly phase filtering save computations in a decimation filter?
4. Give any practical application of decimation?
5. Which signals can be down sampled?
6. What happens if I violate the Nyquist criteria in down sampling or decimating?
7. Can we do decimate in multiple stages?
8. What are "decimation" and "downsampling"?
9. What is the "decimation factor"?
The process of increasing the sampling rate is called interpolation. Interpolation is upsampling
followed by appropriate filtering. obtained by interpolating , is generally represented as:
The simplest method to interpolate by a factor of L is to add L-1 zeros in between the samples, multiply the
amplitude by L and filter the generated signal, with a so-called anti-imaging low pass filter at the high
sampling frequency