Professional Documents
Culture Documents
CONTENTS
0
BIET DSPA LAB MANUAL
1.INRODUCTION
MATLAB
Toolbox
Signal processing Image processing
Statistics Control system
Neural networks Communications
1
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at
some later time. Furthermore, it allows you to run such lists of commands such that you
pass in data and/or get data back out (i.e. the list of commands is like a function in most
programming languages). Once you save a function, it becomes part of your toolbox (i.e.
it now looks to you as if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that MATLAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It
simply reads through each line of the function, executes it, and then goes on to the next
line. (In practice, a form of compilation occurs when you first run a function, so that it
can run faster the next time you run it.)
MATLAB Windows:
MATLAB works with through three basic windows
Command Window : This is the main window .it is characterized by MATLAB
command prompt >> when you launch the application program MATLAB puts you in
this window all commands including those for user-written programs ,are typed in this
window at the MATLAB prompt
Graphics window: the output of all graphics commands typed in the command window
are flushed to the graphics or figure window, a separate gray window with white
background color the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files
called M files.
Input-output:
MATLAB supports interactive computation taking the input from the screen and
flushing, the output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, charcter strings, structures and
cells.There is no need to declare variables as real or complex, MATLAB automatically
sets the variable to be real.
2
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value
10 with an increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
3. T= 0:1/pi: 1
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose
values are zero
Output= [0 0 0]
5. zeros( 2,4)
Output = 0000
0000
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 11
11
11
11
11
7. a = [ 1 2 3]
b = [4 5 6]
a.*b = [4 10 18]
8 if C= [2 2 2]
9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
1 2` 3 4
4
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
11. Subplot: This function divides the figure window into rows and columns
1 2
(2 2 1) (2,2,2)
3 4
(2 2 3) ( 2 2 4)
Subplot(3, 1, 3)
1 (3, 1, 1)
2 (3, 1, 2)
3 (3, 1, 3)
12 Filter
Syntax: y = filter(b,a,X)
Description: y = filter(b,a,X) filters the data in vector X with the filter described by
numerator coefficient vector b and denominator coefficient vector a.If a(1) is not equal to
1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error.
13. Impz
Syntax: [h,t] = impz(b,a,n)
Description: [h,t] = impz(b,a,n) computes the impulse response of the filter with
numerator coefficients b and denominator coefficients a and computes n samples of the
impulse response when n is an integer (t = [0:n-1]'). If n is a vector of integers, impz
computes the impulse response at those integer locations, starting the response
5
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
computation from 0 (and t = n or t = [0 n]).If, instead of n, you include the empty vector
[] for the second argument, the number of samples is computed automatically by default.
14. Fliplr
Syntax: B = fliplr(A)
Description: B = fliplr(A) returns A with columns flipped in the left-right direction, that
is, about a vertical axis.If A is a row vector, then fliplr(A) returns a vector of the same
length with the order of its elements reversed. If A is a column vector, then fliplr(A)
simply returns A.
15. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the
same operation as multiplying the polynomials whose coefficients are the elements of u
and v.
16.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a
text string, the string is displayed.Another way to display an array on the screen is to type
its name, but this prints a leading "X=," which is not always desirable.Note that disp does
not display empty arrays.
17.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
18. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
19.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current
axes.
20.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
6
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-2
Theory: Description
Fourier analysis is a family of mathematical techniques, all based on decomposing
signals into sinusoids. The discrete Fourier transform (DFT) is the family member used
with digitized signals. A signal can be either continuous or discrete, and it can be either
periodic or Aperiodic. The combination of these two features generates the four
categories, described below
Aperiodic-Continuous
This includes, decaying exponentials and the Gaussian curve. These signals extend to
both positive and negative infinity without repeating in a periodic pattern. The Fourier
Transform for this type of signal is simply called the Fourier Transform.
Periodic-Continuous
This includes: sine waves, square waves, and any waveform that repeats itself in a regular
pattern from negative to positive infinity. This version of the Fourier transform is called
the Fourier series.
Aperiodic-Discrete
These signals are only defined at discrete points between positive and negative infinity,
and do not repeat themselves in a periodic fashion. This type of Fourier transform is
called the Discrete Time Fourier Transform.
Periodic-Discrete
These are discrete signals that repeat themselves in a periodic fashion from negative to
positive infinity. This class of Fourier Transform is sometimes called the Discrete Fourier
Series, but is most often called the Discrete Fourier Transform.
Matlab Code
clf;
a=[1 1 2 2];
x=fft(a,4);
n=0:3;
subplot(2,1,1);
stem(n,abs(x));
xlabel('time index n');
7
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
ylabel('Amplitude');
title('amplitude obtained by dft');
grid;
subplot(2,1,2);
stem(n,angle(x));
xlabel('time index n'); ylabel('Amplitude');
title('Phase obtained by dft');
8
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-3
clf;
num=input('numerator coefficiuents b = ');
den=input('denominator coefficients a = ');
w = -pi:8*pi/511:pi;
output
freqresp
numerator coefficiuents b = [2 1]
denominator coefficients a = [1 -0.6]
9
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
10
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-4
Theory:
A discrete time LTI system (also called digital filters) as shown in Fig.2.1 is
represented by
o A linear constant coefficient difference equation, for example,
y[n] + a1 y[n 1] a 2 y[n 2] = b0 x[n] + b1 x[n 1] + b2 x[n 2];
o A system function H(z) (obtained by applying Z transform to the
Y ( z ) b0 + b1 z 1 + b2 z 2
difference equation). H ( z ) = =
X ( z ) 1 + a1 z 1 + a 2 z 2
Given the difference equation or H(z), the impulse response of the LTI system is
found using filter or impz MATLAB functions.
MATLAB Programs:
Program 1
Result:
11
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
12
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-5
Theory:
Discrete Fourier Transform (DFT) is used for performing frequency analysis of
discrete time signals. DFT gives a discrete frequency domain representation
whereas the other transforms are continuous in frequency domain.
The N point DFT of discrete time signal x[n] is given by the equation
N -1 j 2kn
X (k ) = x[n]e N
; k = 0,1,2,....N - 1
n =0
Where N is chosen such that N L , where L=length of x[n].
The inverse DFT allows us to recover the sequence x[n] from the frequency
samples.
j 2kn
1 N 1
x[n] = x[n]e N ; n = 0,1,2,....N - 1
N k =0
X(k) is a complex number (remember ejw=cosw + jsinw). It has both magnitude
and phase which are plotted versus k. These plots are magnitude and phase
spectrum of x[n]. The k gives us the frequency information.
Here k=N in the frequency domain corresponds to sampling frequency (fs).
Increasing N, increases the frequency resolution, i.e., it improves the spectral
characteristics of the sequence. For example if fs=8kHz and N=8 point DFT, then
in the resulting spectrum, k=1 corresponds to 1kHz frequency. For the same fs
and x[n], if N=80 point DFT is computed, then in the resulting spectrum, k=1
corresponds to 100Hz frequency. Hence, the resolution in frequency is increased.
Since N L , increasing N to 8 from 80 for the same x[n] implies x[n] is still the
same sequence (<8), the rest of x[n] is padded with zeros. This implies that there
is no further information in time domain, but the resulting spectrum has higher
frequency resolution. This spectrum is known as high density spectrum
(resulting from zero padding x[n]). Instead of zero padding, for higher N, if more
number of points of x[n] are taken (more data in time domain), then the resulting
spectrum is called a high resolution spectrum.
Algorithm:
1. Input the sequence for which DFT is to be computed.
2. Input the length of the DFT required (say 4, 8, >length of the sequence).
3. Implement FFT algorithm.
13
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
MATLAB Program:
Y=y;
Y=[Y, zeros(1, N - n)];
N2=N/2;
YY = -pi*sqrt(-1)/N2;
WW = exp(YY);
JJ = 0 : N2-1;
W=WW.^JJ;
for L = 1 : p-1
u=Y(:,1:N2);
v=Y(:,N2+1:N);
t=u+v;
S=W.*(u-v);
Y=[t ; S];
U=W(:,1:2:N2);
W=[U ;U];
N=N2;
N2=N2/2;
end;
u=Y(:,1);
v=Y(:,2);
Y=[u+v;u-v];
Y
subplot(3,1,1)
stem(y);grid
title('input sequence y')
xlabel('n');
ylabel('Amplitude');
subplot(3,1,2)
stem(abs(Y));grid
14
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
title('Magnitude of FFT')
xlabel('N');
ylabel('Amplitude');
subplot (3,1,3)
stem(angle(Y));grid
title('phase of FFT')
xlabel('N');
ylabel('phase');
Result:
>> fft1
enter input sequence:[1 2 3 4 5 6 7]
size of fft(e.g . 2,4,8,16,32):8
Y=
28.0000
-9.6569 + 4.0000i
-4.0000 - 4.0000i
1.6569 - 4.0000i
4.0000
1.6569 + 4.0000i
-4.0000 + 4.0000i
-9.6569 - 4.0000i
15
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
16
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-6
Experiment No. 5 Power Density Spectrum Using MATLAB
Algorithm:
1. Generate a signal
2. find DFT of the signal
3. PSD is given by the formula
y(n) = x(k ) x(k n)
k =
where n = - (N-1) to (N-1)
PSD= |Y(w)|2
Where Y(w) = fft of y(n)
Matlab program
% computation of psd of signal corrupted with random noise
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
figure,plot(1000*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
figure,plot(f,Pyy(1:257))
title('power spectrum of y');
xlabel('frequency (Hz)');
output
17
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
18
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-7
Theory:
There are two types of systems Digital filters (perform signal filtering in time domain)
and spectrum analyzers (provide signal representation in the frequency domain). The
design of a digital filter is carried out in 3 steps- specifications, approximations and
implementation.
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the
window.
Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz,
fs=8000Hz
Wc = 2** fc / fs = 2* * 400/8000 = 0.1* radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is
computed as wc = Wc /
Step 2: Compute the Impulse Response h(n) of the required FIR filter using the
given Window type and the response type (lowpass, bandpass, etc). For example
given a rectangular window, order N=20, and a high pass response, the
coefficients (i.e., h[n] samples) of the filter are computed using the MATLAB
inbuilt command fir1 as
h =fir1(N, wc , 'high', boxcar(N+1));
Note: In theory we would have calculated h[n]=hd[n]w[n], where hd[n] is the
desired impulse response (low pass/ high pass,etc given by the sinc function) and
w[n] is the window coefficients. We can also plot the window shape as
stem(boxcar(N)).
Plot the frequency response of the designed filter h(n) using the freqz function and
observe the type of response (lowpass / highpass /bandpass).
Method 2:
Given the pass band (wp in radians) and Stop band edge (ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.
19
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
MATLAB IMPLEMENTATION
FIR1 Function
B = FIR1(N,Wn) designs an N'th order lowpass 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, i.e., even symmetric coefficients obeying B(k) = B(N+2-k), k = 1,2,...,N+1.
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,'high') designs a highpass filter. B =
FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. 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.
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 whose numerator and denominator coefficients are 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.
For FIR filter enter A=1 and B = h[n] coefficients. Appropriately choose N as 128, 256,
etc
20
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
4 1.8
Rectangular 21db B = FIR1(N,Wn,boxcar)
M M
8 6.1
Bartlett 25db B = FIR1(N,Wn,bartlett)
M M
8 6.2
Hanning 44db B = FIR1(N,Wn,hanning)
M M
8 6.6
Hamming 53db B= FIR1(N,Wn,hamming)
M M
12 11
Blackman 74db B = FIR1(N,Wn,blackman)
M M
Program:
%Method 2: the following program gives only the design of the FIR filter- for
implementation continue with the next program (after h[n])
%input data to be given: Passband & Stopband frequency
% Data given: Passband ripple & stopband attenuation As. If As>40 dB, Choose
hamming
clear
wpa=input('Enter passband edge frequency in Hz');
wsa= input('Enter stopband edge frequency in Hz');
ws1= input('Enter sampling frequency in Hz');
%Calculate transmission BW,Transition band tb,order of the filter
wpd=2*pi*wpa/ws1;
wsd=2*pi*wsa/ws1;
tb=wsd-wpd;
N=ceil(6.6*pi/tb)
wc=(wsd+wpd)/2;
21
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
%generate simulated input of 50, 300 & 200 Hz, each of 30 points
n=1:30;
f1=50;f2=300;f3=200;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
%y=conv(h,x);
y=filter(h,1,x);
subplot(2,1,2);
stem(y);
title('output');
Result:
Enter passband edge frequency in Hz100
Enter stopband edge frequency in Hz200
Enter sampling frequency in Hz1000
N = 33
Plots are as in Fig.11.1 and 11.2
Inference:
Notice the maximum stopband attenuation of 53 dB from plot 11.2
22
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
%generate filter coefficients for the given %order & cutoff Say N=33, fc=150Hz,
%fs=1000 Hz, Hamming window
h=fir1(33, 150/(1000/2),hamming(34));
%generate simulated input of 50, 300 & 200 Hz, each of 30 points
n=1:30;
f1=50;f2=300;f3=200;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
%y=conv(h,x);
y=filter(h,1,x);
subplot(2,1,2);
stem(y);
title('output');
Result:
Plots are in Fig.11.3 & 11.4
Notice that freqs below 150 Hz are passed & above 150 are cutoff
Fig.11.1 Fig.11.2
23
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
24
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
Result:
25
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
26
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-8
Theory:
There are two methods of stating the specifications as illustrated in previous program. In
the first program, the given specifications are directly converted to digital form and the
designed filter is also implemented. In the last two programs the butterworth and
chebyshev filters are designed using bilinear transformation (for theory verification).
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the IIR
filter type (butterworth, cheby1, cheby2).
Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Wc = 2** fc / fs = 2* * 400/8000 = 0.1* radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed
as wc = Wc /
Step 2: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type (lowpass, bandpass, etc) using the appropriate butter, cheby1,
cheby2 command. For example given a butterworth filter, order N=2, and a high pass
response, the coefficients [b,a] of the filter are computed using the MATLAB inbuilt
command butter as [b,a] =butter(N, wc , 'high');
Method 2:
Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.
Step 1: Since the frequencies are in radians divide by to obtain normalized
frequencies to get wp=Wp/pi and ws=Ws/pi
If the frequencies are in Hz (note: in this case the sampling frequency should be
given), then obtain normalized frequencies as wp=fp/(fs/2), ws=fstop/(fs/2),
where fp, fstop and fs are the passband, stop band and sampling frequencies in Hz
Step 2: Compute the order and cut off frequency as
[N, wc] = BUTTORD(wp, ws, Rp, Rs)
Step 3: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type as [b,a] =butter(N, wc , 'high');
27
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
MATLAB IMPLEMENTATION
BUTTORD Butterworth filter order selection.
[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 passband and has at least Rs dB of
attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies,
normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example,
Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: 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.
BUTTER Butterworth digital and analog filter design.
[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. [B,A] =
BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].
BUTTER(N,Wn,'s'), BUTTER(N,Wn,'high','s') and BUTTER(N,Wn,'stop','s') design
analog Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0.
[b,a]=butter(2, 150/(1000/2));
%generate simulated input of 100, 300 & 170 Hz, each of 30 points
n=1:30;
f1=100;f2=300;f3=170;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
28
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
y=filter(b,a,x);
subplot(2,1,2);
stem(y);
title('output');
Result:
Plot is in Fig. 12.1, which shows that 100 Hz is passed, while 300 is cutoff and 170
has slight attenuation.
Plot is in Fig.12.2 where only 170 is passed, while 100 & 300 are cutoff.
29
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
30
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
31
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
% Prewrapped frequency
pw1 = 2*tan(aw1/2);
pw2 = 2*tan(aw2/2);
%Calculate order and cutoff freq
[n,wc]= buttord (pw1,pw2,rp,rs,'s');
32
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
%Analog frequencies
aw1= 2*pi*w1/ws;
aw2=2*pi*w2/ws;
[b,a] = cheby1(n,rp,wc,'s');
33
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-9
EXPERIMENT NO 10: Generation of sinusoidal wave using recursive difference
equation
Theory:
There exists different techniques to generate a sine wave on a DSP processor.
Using a lookup table, interpolation, polynomials, or pulse width modulation are some of these techniques
utilized to generate a sine wave. When a slightly sufficient processing power is considered, it is possible to
utilize another technique which makes use of an IIR filter.
In this technique, a second order IIR filter as shown in Figure 1 is designed to be
marginally stable which is an undesirable situation for a normal filtering operation. For this second order
filter to be marginally stable, its poles are located in the unit circle. After choosing the suitable filter
coefficients for the filter to be marginally stable, a unit
impulse is applied to the filter as an input at time t = 0, and then the input is
disconnected. Then the filter starts to oscillate with a fixed frequency.
The difference equation of the second order filter shown in Figure 1 will be:
34
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
Where F0 is the frequency, Fs is the sampling frequency and A is the amplitude of the
sine wave.
Matlab Program
plot (y);
title('Sinusoidal waveform')
xlabel('samples n');
ylabel('y(n)');
result :
36
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-10
Experiment No. 11 Generation of DTMF signals
A DTMF signal consists of the sum of two sinusoids - or tones - with frequencies taken
from two mutually exclusive groups. These frequencies were chosen to prevent any
harmonics from being incorrectly detected by the receiver as some other DTMF
frequency. Each pair of tones contains one frequency of the low group (697 Hz, 770 Hz,
852 Hz, 941 Hz) and one frequency of the high group (1209 Hz, 1336 Hz, 1477Hz) and
represents a unique symbol. The frequencies allocated to the push-buttons of the
telephone pad are shown below:
We will right the program to generate and visualize the DTMF tones for all 12 Symbols.
Also we will estimate its energy content using Gortzets Algorithm
The minimum duration of a DTMF signal defined by the ITU standard is 40 ms.
Therefore, there are at most 0.04 x 8000 = 320 samples available for estimation and
detection. The DTMF decoder needs to estimate the frequencies contained in these short
signals.
At this point we could use the Fast Fourier Transform (FFT) algorithm to calculate the
DFT. However, the popularity of the Goertzel algorithm in this context lies in the small
37
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
number of points at which the DFT is estimated. In this case, the Goertzel algorithm is
more efficient than the FFT algorithm.
Plot Goertzel's DFT magnitude estimate of each tone on a grid corresponding to the
telephone pad.
MATLAB Program
tones = zeros(N,size(f,2));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
% Plot tone
subplot(4,3,toneChoice),plot(t*1e3,tones(:,toneChoice));
title(['Symbol "', symbol{toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'Xlim', [0 25]);
ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitHeightToText','on');
% estimation of DTMF tone using Gortzel's Algorithm
Nt = 205;
original_f = [lfg(:);hfg(:)] % Original frequencies
k = round(original_f/Fs*Nt); % Indices of the DFT
38
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
Output:
39
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
40
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
CHAPTER-11
Experiment No. 12,13,14: Implementation of Interpolation, decimation and
I/D sampling rate converters
Theory:
Multirate : Changing the Sampling Rate of the Discrete Time Signal.
The process of converting a signal from a given rate to a different rate is
called sampling rate conversion.
Systems that employ multiple sampling rates in the processing of digital
signals are called multirate digital signal processing systems.
41
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
42
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
43
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
INTERPOLATION
Process of increasing the sampling rate of the signal by a factor of L i.e. from F s to LFs
Upsampling by a factor L means inserting L-1 zeros between two samples
44
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
45
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
MATLAB program:
% % m-file to illustrate simple interpolation and
% decimation operations
% File name:
%
Fs=input('Enter Sampling Frequency:'); % sampling frequency
I= input('interpolation factor:');
A=1.5; % relative amplitudes
B=1;
f1=50; % signal frequencies
f2=100;
t=0:1/Fs:1; % time vector
x=A*cos(2*pi*f1*t)+B*cos(2*pi*f2*t); % generate signal
y=resample(x,I,1); % interpolate signal by 4
stem(x(1:100)) % plot original signal
xlabel('Discrete time, nT ')
ylabel('Input signal level')
figure
stem(y(1:400)) % plot interpolated signal.
Result
>> decimation
Enter Sampling Frequency:1000
interpolation factor:4
Enter the decimation factor:2
46
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
47
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
BIET DSPA LAB MANUAL
48
BHARAT INSTITUTE OF ENGINEERING AND TECHNOLOGY