Manual For DSP LAB 3rd Year
Manual For DSP LAB 3rd Year
DIGITAL SIGNAL
PROCESSING LAB
(EEC-652)
B.Tech.
(EC-6th SEM)
[2011]
[Strictly in accordance with the GBTU Syllabus]
Page 1
List of Experiments
As per GBTU Syllabus
1. EVALUATE 4 POINT DFT OF AND IDFT OF X (n) = 1, 0 n 3; 0
ELSEWHERE.
2. IMPLEMENT THE FIR FILTERS FOR 2 KHz CUT OFF FREQUENCY
AND 2 KHz BANDWIDTH FOR BAND PASS FILTER.
3. IMPLEMENT IIR LOW PASS FILTER FOR A 4 KHZ CUTOFF
FREQUENCY AND COMPARE IT THE FIR FILTER WITH THE SAME
TYPE USE CHIRP AS INPUT SIGNAL.
4. VERIFY BLACKMAN AND HAMMING WINDOWING TECHNIQUES
FOR SQUARE WAVE AS AN INPUT WHICH WINDOW WILL GIVE
GOOD
RESULTS.
5. IMPLEMENT THE FILTER FUNCTIONS.
6. GENERATE DTMF SEQUENCE 1234567890*# AND OBSERVE ITS
SPECTROGRAM.
7. GENERATE AN AMPLITUDE MODULATION HAVING SIDE LOW
FREQUENCIES 1200 HZ AND 800 HZ. OBSERVE AND VERIFY
THE THEORETICAL FFT CHARACTERISTICS WITH THE
OBSERVED ONES.
8. GENERATE FREQUENCY MODULATION HAVING CARRIER
FREQUENCIES 1 KHZ AND MODULATING FREQUENCY 200 HZ
WITH THE MODULATION INDEX OF 0.7. OBSERVE AND VERIFY
THE THEORETICAL FFT CHARACTERISTICS WITH THE
OBSERVED ONES.
9. GENERATE AN FSK WAVE FORM FOR TRANSMITTING THE
DIGITAL DATA OF THE GIVEN BIT SEQUENCE. PREDICT AND
VERIFY THE FFT FOR THE SAME ONE.
10. To STUDY THE CIRCULAR CONVOLUTION.
Page 2
************
Page 3
(k) and
(k) +
(k)
Page 4
Page 5
Page 6
Page 7
************
Page 8
Page 9
In this equation, x(k) and y(n) represent the input to and output from the filter
at time
n. h(n-k) is the transversal filter coefficients at time n. These coefficients are
generated by using FDS (Filter Design Software or Digital filter design
package).
FIR filter is a finite impulse response filter. Order of the filter should be
specified.
Infinite response is truncated to get finite impulse response. Placing a window
of
finite length does this. Types of windows available are Rectangular, Barlett,
Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter.
PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
int n,N,c;
float wr[64],wt[64];
void main()
{
printf("\n enter no. of samples,N= :");
scanf("%d",&N);
printf("\n enter choice of window function\n 1.rect \n 2. triang \n c= :");
scanf("%d",&c);
Page 10
Page 11
PROGRAM:
%fir filt design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
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
c=input('enter your choice of window function 1. rectangular 2. triangular
3.kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
Page 12
RESULT:
Page 13
Page 14
************
[KEC/EC/Prabhat/Student Lab Manual]
Page 15
Page 16
Experiment No- (3): To implement IIR low pass filter FOR A 4 KHZ
cut off frequency and compare it. The FIR filter with the same type
use CHIRP as input signal.
AIM: To implement IIR low pass filter FOR A 4 KHZ CUTOFF FREQUENCY AND
COMPARE IT THE FIR FILTER WITH THE SAME TYPE USE CHIRP AS INPUT SIGNAL.
APPARATUS REQUIRED: Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7
THEORY:
The IIR filter can realize both the poles and zeroes of a system because it has a
rational transfer function, described by polynomials in z in both the numerator
and
the denominator:
Page 17
Page 18
PROGRAM:
% IIR filters LPF & HPF
clc;
clear all;
close all;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
Page 19
Page 20
************
Page 21
Page 22
Note that:
Page 23
Page 24
Page 25
Page 26
RESULTS:
Page 27
Page 28
************
Page 29
Page 30
For the simplest low pass filter, we had two program listings:
Sample for filtering one block of data, and
A main program for testing sample.
In matlab, there is a built-in function called filter which will implement sample
as a special case. The syntax is
y = filter (B, A, x)
where
x is the input signal (a vector of any length),
y is the output signal (returned equal in length to x),
A is a vector of filter feedback coefficients, and
B is a vector of filter feed forward coefficients.
The filter function performs the following iteration over the elements of x to
implement any causal, finite-order, linear, time-invariant digital filter:
where
length of B,
is the length of A, and
and A are divided through by A(1).
is the
is assumed to be 1. (Otherwise, B
The feed forward coefficients needed for the simplest lopes filter are
Page 31
Output:
octave:1> simplpm1
x(1)=1.000000
y(1)=1.000000
x(2)=2.000000
y(2)=3.000000
x(3)=3.000000
y(3)=5.000000
x(4)=4.000000
y(4)=7.000000
x(5)=5.000000
y(5)=9.000000
x(6)=6.000000
y(6)=11.000000
x(7)=7.000000
y(7)=13.000000
x(8)=8.000000
y(8)=15.000000
x(9)=9.000000
y(9)=17.000000
x(10)=10.000000
y(10)=19.000000
Main matlab program for implementing the simplest low-pass filter
.
Note that the input signal is processed in one big block, rather than being
broken up into two blocks .If we want to process a large sound file block by
block, we need some way to initialize the state of the filter for each block
using the final state of the filter from the preceding block. The filter function
Page 32
RESULT:
Hence low pass filter is implemented.
************
Page 33
Page 34
First of all, the information is available in digital format, inside a file in the
vector numbers format (samples). Through a memory buffer, samples move to
a digital-to-analog converter that produces a voltage signal to output to the
external world, after an appropriate amplification stage. Shannon's theorem
states that the sampling frequency fs must satisfy the following relation:
fs 2B, where B is the absolute band of the output signal.
Even if the DAC can assure high sampling frequency, the absolute band of the
signal that has to be generated depends on the performances of the output
stage of the audio card. Because it's designed for sound applications, it's
equipped with an amplifier with a 200Hz-20KHz bandwidth (in the ideal case).
It must be also taken into account that the output signal will be distorted in
amplitude and phase, more around the upper cutoff frequency. All that limits
the generation of signals having with bandwidth lower than about 10KHz.
At this point, the most important issues are:
1- to generate a file with the signal in the digital format.
2- to setup a hw/sw sysytem able to perform the digital to analog conversion
chain (DAC).
Page 35
Page 36
The following source allows to generate with Matlab a 12 seconds dtmf.wav file
that reproduces, at interval of one second, the sequence of the DTMF tones of
the buttons:
PROGRAM:
0-1-2-3-4-5-6-7-8-9-*-#
%-----------------------------%-- EXAMPLE OF DTMF GENERATION
%-----------------------------l=12;
fs=10000;
t=linspace(0,l,l*fs);
fc1=697;
fc2=770;
fc3=852;
fc4=941;
fr1=1209;
fr2=1336;
fr3=1477;
y0
y1
y2
y3
y4
y5
y6
=
=
=
=
=
=
=
%-- frequencies
sin(2*pi*fc3*t)
sin(2*pi*fc1*t)
sin(2*pi*fc1*t)
sin(2*pi*fc1*t)
sin(2*pi*fc2*t)
sin(2*pi*fc2*t)
sin(2*pi*fc2*t)
+
+
+
+
+
+
+
sin(2*pi*fr2*t);
sin(2*pi*fr1*t);
sin(2*pi*fr2*t);
sin(2*pi*fr3*t);
sin(2*pi*fr1*t);
sin(2*pi*fr2*t);
sin(2*pi*fr3*t);
%
%
%
%
%
%
%
0
1
2
3
4
5
6
Page 37
%*
%#
y=zeros(1,length(t));
k=0;
s=length(y)-1;
s=s+1;
for i=1:s
if k < s/12
y(i)=y0(i);
elseif k >= s/12 && k <((2*s)/12)
y(i)=y1(i);
elseif k >= ((2*s)/12) && k <((3*s)/12)
y(i)=y2(i);
elseif k >= ((3*s)/12) && k <((4*s)/12)
y(i)=y3(i);
elseif k >= ((4*s)/12) && k <((5*s)/12)
y(i)=y4(i);
elseif k >= ((5*s)/12) && k <((6*s)/12)
y(i)=y5(i);
elseif k >= ((6*s)/12) && k <((7*s)/12)
y(i)=y6(i);
elseif k >= ((7*s)/12) && k <((8*s)/12)
y(i)=y7(i);
elseif k >= ((8*s)/12) && k <((9*s)/12)
y(i)=y8(i);
elseif k >= ((9*s)/12) && k <((10*s)/12)
y(i)=y9(i);
elseif k >= ((10*s)/12) && k <((11*s)/12)
y(i)=y_start(i);
else
y(i)=y_canc(i);
end
k=k+1;
end
plot(t,y*0.4); wavwrite(y*0.4,fs,'dtmf.wav');
Page 38
Page 39
************
Page 40
Vc Sin ( c t + )
To amplitude modulate the carrier its amplitude is changed in accordance with the level of the
audio signal, which is described by
v
Vm Sin ( m t )
The amplitude of the carrier varies sinusoidally about a mean of Vc. When the carrier is modulated
its amplitude is varied with the instantaneous value of the modulating signal. The amplitude of the
variation of the carrier amplitude is Vm and the angular frequency of the rate at which the
amplitude varies is m. The amplitude of the carrier is then:
Carrier amplitude = Vc + Vm Sin ( m t )
and the instantaneous value (value at any instant in time) is
v
Eqn. 1
Eqn. 2
Page 41
+ m)t)
Equation of modulated wave.
c (rad/s)
Frequency is
c + m (rad/s)
Frequency is (c + m)/2
fc =
c/2 Hz
upper side frequency
= fm + fc Hz
lower side frequency
c - m
(rad/s)
Frequency is (c -
m)/2 = fm - fc Hz
The bandwidth (the difference between the highest and the lowest frequency) is
BW = (c + m ) - (c - m)
2 * m Rad/s
( = m/ Hz)
Page 42
************
Page 43
Page 44
In this equation,
is the instantaneous frequency of the oscillator
and
is the frequency deviation, which represents the maximum shift
away from fc in one direction, assuming xm(t) is limited to the range 1.
Although it may seem that this limits the frequencies in use to fc f, this
neglects the distinction between instantaneous frequency and spectral
frequency. The frequency spectrum of an actual FM signal has components
extending out to infinite frequency, although they become negligibly small
beyond a point.
Page 45
where
is the highest frequency component present in the modulating
signal xm(t), and
is the Peak frequency-deviation, i.e. the maximum
deviation of the instantaneous frequency from the carrier frequency. If
,
the modulation is called narrowband FM, and its bandwidth is
approximately
. If
, the modulation is called wideband FM and its
bandwidth is approximately
. While wideband FM uses more bandwidth, it
can improve signal-to-noise ratio significantly.
Page 46
************
Page 47
Page 48
Page 49
************
Page 50
Page 51
Page 52
************
Page 53