0% found this document useful (0 votes)
167 views

Manual For DSP LAB 3rd Year

This document contains details about Experiment 3 of a Digital Signal Processing lab course. The aim is to implement an IIR low pass filter with a 4 kHz cutoff frequency and compare it to an FIR filter of the same type, using a chirp signal as input. The document provides theory on IIR filters and their structure. It includes sample code in C to design the IIR filter and plots its frequency response. The results show frequency response plots of the IIR filter designed.

Uploaded by

Vinay Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views

Manual For DSP LAB 3rd Year

This document contains details about Experiment 3 of a Digital Signal Processing lab course. The aim is to implement an IIR low pass filter with a 4 kHz cutoff frequency and compare it to an FIR filter of the same type, using a chirp signal as input. The document provides theory on IIR filters and their structure. It includes sample code in C to design the IIR filter and plots its frequency response. The results show frequency response plots of the IIR filter designed.

Uploaded by

Vinay Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 53

B.Tech.

(EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

DIGITAL SIGNAL
PROCESSING LAB
(EEC-652)
B.Tech.
(EC-6th SEM)
[2011]
[Strictly in accordance with the GBTU Syllabus]

[KEC/EC/Prabhat/Student Lab Manual]

Page 1

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
DIGITAL SIGNAL PROCESSING LAB (EEC-652)

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.

[KEC/EC/Prabhat/Student Lab Manual]

Page 2

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

Experiment No- (1):


To evaluate DFT and IDFT.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)
[KEC/EC/Prabhat/Student Lab Manual]

Page 3

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (1): EVALUATE 4 POINT DFT OF AND IDFT


OF X (n) = 1, 0 n 3; 0 ELSEWHERE.
AIM-: EVALUATE 4 POINT DFT OF AND IDFT OF X (n) = 1, 0 n 3; 0
ELSEWHERE.
APPARATUS-: Operating System Windows XP
Constructor Simulator
Software - Matlab
THEORY:
The discrete Fourier transform (DFT) computes the values of the z-transform
for evenly spaced points around the unit circle for a given sequence.
If the sequence to be represented is of finite duration ,i.e. has only a finite
numbers of non-zero values, the transform used is discrete Fourier transform
(DFT) . DFT finds its application in digital signal processing including linear
filtering, correlation analysis and spectrum analysis.
Let x(n) be a finite duration sequence. The N-point DFT of the sequence x(n)
Is expressed by
, k=0,1,N-1.
And the corresponding IDFT is
, n=0,1,..,N-1
Following notations will be used to represent the operations of taking the DFT
& IDFT of sequences:
X (k)= DFT[x(n)]
X (n)=IDFT[X(k)]
X (n)..X (k)
All the algorithms which are used to determine DFT in computationally efficient
manner are called Fast Fourier Transform (FFT) algorithms.DFT of a sequence
x(n) i.e. the complex function of discrete frequency. Therefore, X (k) is
expressed as
Say X(k)=
Where

(k) and

(k) +

(k)

(k) are the real and imaginary parts of X (k),

Manitude of X(k) is given by


|X(k)| =
Phase of X (k) is given by

[KEC/EC/Prabhat/Student Lab Manual]

Page 4

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
|X (k)| =

Magnitude Spectrum: This spectrum is drawn between magnitude of X(k) and


discrete frequency variable k.
Phase Spectrum: This spectrum is drawn between phase of X(k) and discrete
frequency variable k.
Frequency spectrum of a complex valued DFT can be drawn by two spectrum s
1. Magnitude or Amplitude Spectrum
2. Phase Spectrum
DFT of N-point sequence will have same number points
PROGRAM:
% Illustration of DFT Computation
%
% Read in the length N of sequence and the desired
% length M of the DFT
N = input('Type in the length of the sequence = ');
M = input('Type in the length of the DFT = ');
% Generate the length-N time-domain sequence
u = [ones(1,N)];
% Compute its M-point DFT
U = fft(u,M);
% Plot the time-domain sequence and its DFT
t = 0:1:N-1;
stem(t,u)
title('Original time-domain sequence')
xlabel('Time index n'); ylabel('Amplitude')
pause
subplot(2,1,1)
k = 0:1:M-1;
stem(k,abs(U))
title('Magnitude of the DFT samples')
xlabel('Frequency index k'); ylabel('Magnitude')
subplot(2,1,2)
stem(k,angle(U))
title('Phase of the DFT samples')
xlabel('Frequency index k'); ylabel('Phase')
%--------------- End of the program ------------------------------------% Illustration of IDFT Computation
%
% Read in the length K of the DFT and the desired
% length N of the IDFT

[KEC/EC/Prabhat/Student Lab Manual]

Page 5

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
K = input('Type in the length of the DFT = ');
N = input('Type in the length of the IDFT = ');
% Generate the length-K DFT sequence
k = 0:K-1;
V = [ones(1,K)];
% Compute its N-point IDFT
v = ifft(V,N);
% Plot the DFT and its IDFT
stem(k,V)
xlabel('Frequency index k'); ylabel('Amplitude')
title('Original DFT samples')
pause
subplot(2,1,1)
n = 0:N-1;
stem(n,real(v))
title('Real part of the time-domain samples')
xlabel('Time index n'); ylabel('Amplitude')
subplot(2,1,2)
stem(n,imag(v))
title('Imaginary part of the time-domain samples')
xlabel('Time index n'); ylabel('Amplitude')
RESULTS:

[KEC/EC/Prabhat/Student Lab Manual]

Page 6

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

[KEC/EC/Prabhat/Student Lab Manual]

Page 7

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 8

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (2):


To IMPLEMENT THE FIR FILTERS FOR 2
KHz CUT OFF FREQUENCY.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 9

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (2): To IMPLEMENT THE FIR FILTERS FOR


2 KHz CUT OFF FREQUENCY.
AIM-: To IMPLEMENT THE FIR FILTERS FOR 2 KHz CUT OFF FREQUENCY.
APPARATUS-: Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.1
THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system
whose output is based on the weighted summation of a finite number of past
inputs.
An FIR transversal filter structure can be obtained directly from the equation
for
discrete-time convolution.

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);

[KEC/EC/Prabhat/Student Lab Manual]

Page 10

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
printf("\n elements of window function are:");
switch(c)
{
case 1:
for(n=0;n<=N-1;n++)
{
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
}
break;
case 2:
for(n=0;n<=N-1;n++)
{
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
}
break;
}
}
RESULT:

[KEC/EC/Prabhat/Student Lab Manual]

Page 11

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

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

[KEC/EC/Prabhat/Student Lab Manual]

Page 12

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->');

RESULT:

[KEC/EC/Prabhat/Student Lab Manual]

Page 13

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

[KEC/EC/Prabhat/Student Lab Manual]

Page 14

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************
[KEC/EC/Prabhat/Student Lab Manual]

Page 15

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (3):


To implement IIR low pass filter for 4KHz
cutoff frequency.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 16

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

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:

The difference equation for such a system is described by the following:

M and N are order of the two polynomials


bk and ak are the filter coefficients. These filter coefficients are generated
using FDS
(Filter Design software or Digital Filter design package).
IIR filters can be expanded as infinite impulse response filters. In designing IIR
filters, cutoff frequencies of the filters should be mentioned. The order of the
filter
can be estimated using butter worth polynomial. Thats why the filters are
named as
butter worth filters. Filter coefficients can be found and the response can be
plotted.
PROGRAM:
//iirfilters
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];

[KEC/EC/Prabhat/Student Lab Manual]

Page 17

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
float mul(float, int);
void main()
{
printf("\n enter order of filter ");
scanf("%d",&N);
printf("\n enter the cutoff freq ");
scanf("%d",&wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
{
case 1:
for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
case 2:
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
}}
float mul(float a,int x)
{
for(i=0;i<x-1;i++)
a*=a;
return(a);
}
RESULT:

[KEC/EC/Prabhat/Student Lab Manual]

Page 18

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

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;

[KEC/EC/Prabhat/Student Lab Manual]

Page 19

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
[n,wn]=buttord(w1,w2,rp,rs,'s');
c=input('enter choice of filter 1. LPF 2. HPF \n ');
if(c==1)
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
RESULT:

[KEC/EC/Prabhat/Student Lab Manual]

Page 20

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 21

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (4):


VERIFY BLACKMAN AND HAMMING
WINDOWING TECHNIQUES FOR
SQUARE WAVE

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)
Experiment No- (4): VERIFY BLACKMAN AND HAMMING
WINDOWING TECHNIQUES FOR SQUARE WAVE.
AIM-: VERIFY BLACKMAN AND HAMMING WINDOWING TECHNIQUES FOR
SQUARE WAVE.
APPARATUS-: Operating System Windows XP
Constructor Simulator
Software - Matlab
THEORY:

represents the width, in samples, of a discrete-time window function.


Typically it is an integer power-of-2, such as 210 = 1024.

is an integer, with values 0 n N-1. So these are the time-shifted


forms of the windows:
, where
is maximum
at n=0.
o Some of these forms have an overall width of N1, which makes
them zero-valued at n=0 and n=N1. That sacrifices two data
samples for no apparent gain, if the DFT size is N. When that

[KEC/EC/Prabhat/Student Lab Manual]

Page 22

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

happens, an alternative approach is to replace N1 with N in the


formula.
Each figure label includes the corresponding noise equivalent bandwidth
metric (B), in units of DFT bins. As a guideline, windows are divided into
two groups on the basis of B. One group comprises
, and the
other group comprises
.

Hamming window function


The "raised cosine" with these particular coefficients was proposed by Richard
W. Hamming. The window is optimized to minimize the maximum (nearest)
side lobe, giving it a height of about one-fifth that of the Hann window, a raised
cosine with simpler coefficients.

Note that:

[KEC/EC/Prabhat/Student Lab Manual]

Page 23

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Hamming window; B=1.37

Blackman window function


Blackman window; = 0.16; B=1.73
Blackman windows are defined as:[note 1]

By common convention, the unqualified term Blackman window refers to


=0.16.

[KEC/EC/Prabhat/Student Lab Manual]

Page 24

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

HAMMING WINDOW PROGRAM:


clc;clear all; close all;
rp=input (enter the passband ripple);
rs=input (enter the stopband ripple);
fp=input (enter the passband freq);
fs=input (enter the stopband freq);
f=input (enter the 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
y=hamming(n1);
%LOW-PASS FILTER
b=fir1(n,wp,y);
[h,0]=freqz(b,1,256);

[KEC/EC/Prabhat/Student Lab Manual]

Page 25

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
m=20*log10(abs(h));
subplot(2,2,1); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(a) Normalised frequency-->');
%HIGH-PASS FILTER
b=fir1(n,wp,'high',y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(b) Normalised frequency-->');
%BANDPASS FILTER
wn=[wp ws];
b=fir1(n,wn,y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(c) Normalised frequency-->');
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(d) Normalised frequency-->');

BLACKMAN WINDOW PROGRAM:


clear all; close all;
Clc;
rp=input (enter the passband ripple);
rs=input (enter the stopband ripple);
fp=input (enter the passband freq);
fs=input (enter the stopband freq);
f=input (enter the 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)

[KEC/EC/Prabhat/Student Lab Manual]

Page 26

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
n1=n;
n=n-1;
end
y=blackman(n1);
%LOW-PASS FILTER
b=fir1(n,wp,y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(a) Normalised frequency-->');
%HIGH-PASS FILTER
b=fir1(n,wp,'high',y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(b) Normalised frequency-->');
%BANDPASS FILTER
wn=[wp ws];
b=fir1(n,wn,y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(c) Normalised frequency-->');
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,0]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4); plot(o/pi,m); ylabel('Gain in dB-->');
xlabel('(d) Normalised frequency-->');

RESULTS:

[KEC/EC/Prabhat/Student Lab Manual]

Page 27

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

[KEC/EC/Prabhat/Student Lab Manual]

Page 28

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 29

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (5):


To implement the simplest low pass filter.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 30

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (5): To implement the simplest low pass filter.


AIM: To implement the simplest low pass filter
.
APPARATUS REQUIRED: Operating System Windows XP
Constructor Simulator
Software - Matlab
THEORY:
We will implement (in Matlab) the simplest low pass filter

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

[KEC/EC/Prabhat/Student Lab Manual]

Page 31

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
With these settings, the filter function implements

% simplpm1.m - matlab main program implementing


%
the simplest lowpass filter:
%
%
y(n) = x(n)+x(n-1)}
N=10;
% length of test input signal
x = 1:N; % test input signal (integer ramp)
B = [1,1]; % transfer function numerator
A = 1;
% transfer function denominator
y = filter(B,A,x);
for i=1:N
disp(sprintf('x(%d)=%f\ty(%d)=%f',i,x(i),i,y(i)));
end
%
%
%
%
%
%
%
%
%
%
%
%

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

[KEC/EC/Prabhat/Student Lab Manual]

Page 32

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
accommodates this usage with an additional optional input and output
argument:
[y, Sf] = filter (B, A, x, Si)
Si denotes the filter initial state, and Sf denotes its final state.
% simplpm2.m - block-oriented version of simplpm1.m
N=10;
% length of test input signal
NB=N/2;
% block length
x = 1:N; % test input signal
B = [1,1]; % feedforward coefficients
A = 1;
% feedback coefficients (no-feedback case)
[y1, Sf] = filter(B,A,x(1:NB));
% process block 1
y2 = filter(B,A,x(NB+1:N),Sf); % process block 2
for i=1:NB % print input and output for block 1
disp(sprintf('x(%d)=%f\ty(%d)=%f',i,x(i),i,y1(i)));
end
for i=NB+1:N % print input and output for block 2
disp(sprintf('x(%d)=%f\ty(%d)=%f',i,x(i),i,y2(i-NB)));
end

RESULT:
Hence low pass filter is implemented.

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 33

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (6):


To generate DTMF sequence 1234567890*# and
observe its spectrogram.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 34

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (6): To generate DTMF sequence 1234567890*#


and observe its spectrogram.
AIM: To generate DTMF sequence 1234567890*# and observe its spectrogram.
APPARATUS REQUIRED: Operating System Windows XP
Constructor - Simulator
Software Matlab 7
THEORY:
Sampling and Generation
In mathematics a signal is a real function of a real variable f(t). In electronics it
represents the evolution of a voltage (or a current) over the time.
Simplified diagram to generate an arbitrary signal v(t) from a digital format v(i)
is the following:

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).

[KEC/EC/Prabhat/Student Lab Manual]

Page 35

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
A possible solution for this problem consists to use Matlab with a PC sound
card. Matlab is a numerical calculation environment based on matrix
structures. It's able to easily generate a time function (unidimensional vector).
Furthermore, through specialized functions, Matlab is able to generate a .wav
format of the signal compatible with all sound player for PC through the sound
card. Often, depending on the specific situations, it's necessary an auxilary
output stage for the audio signal conditioning.
Matlab supplies different internal functions to generate a waveform. Most of
these require a preliminary statement of a time vector. Considering a sample
frequency of fs[Hz] it's possible to produce a time vector by writing:
t=linspace(0, end, end*fs . This command generates a time vector from zero to
end second, divided in end*fs points.
The source code to generate a 20Hz, 2 seconds tone is:
t=linspace(0, 2, 2*10000)
y=sin(2*pi*20*t)
plot(t, y)
wavwrite(y, 10000, prova.wav)
The function wavwrite(y,fs,'nomefile') generates an audio nomefile.wav file
from the y vector sampled at the fs frequency.

Example: DTMF tones generation


As example, we consider the generation of DTMF tones of the telephone
keyboard. Dual-Tone Multi-Frequency is a decoding method used in the
telephony to code numerical digits by means of sound signals in the audio

[KEC/EC/Prabhat/Student Lab Manual]

Page 36

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
band. The DTMF keyboard consists of a 4x4 matrix where each row represents
a low frequency while each column represents an high frequency. For example,
pressing the button one are sent two waves at 697 and 1209 Hz. The
Multifrequency term comes from the simultaneous use of two waves.

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);

%-- signal length in second


%-- sampling frequency in HZ
%-- generating the time axis

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

[KEC/EC/Prabhat/Student Lab Manual]

Page 37

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
y7 = sin(2*pi*fc3*t) + sin(2*pi*fr1*t); % 7
y8 = sin(2*pi*fc3*t) + sin(2*pi*fr2*t); % 8
y9 = sin(2*pi*fc3*t) + sin(2*pi*fr3*t); % 9
y_start = sin(2*pi*fc3*t) + sin(2*pi*fr1*t);
y_canc = sin(2*pi*fc3*t) + sin(2*pi*fr3*t);

%*
%#

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');

[KEC/EC/Prabhat/Student Lab Manual]

Page 38

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
RESULT:

[KEC/EC/Prabhat/Student Lab Manual]

Page 39

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

Experiment No- (7):


GENERATE AN Amplitude Modulation.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 40

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (7): GENERATE AN Amplitude Modulation.


AIM: GENERATE AN Amplitude Modulation.
APPARATUS REQUIRED:
THEORY:
Amplitude modulation (AM) is a technique used in electronic communication, most commonly
for transmitting information via a radio carrier wave. AM works by varying the strength of the
transmitted signal in relation to the information being sent. For example, changes in the signal
strength can be used to specify the sounds to be reproduced by a loudspeaker, or the light intensity
of television pixels.
A carrier is described by
v

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

{Vc + Vm Sin ( m t )} * Sin ( c t )

Vc Sin ( c t ) + Vm Sin ( m t ) * Sin ( c t )

Eqn. 1

Using Sin A * Sin B = Cos (A - B) - Cos (A + B) this becomes


v

Vc Sin ( c t ) + Vm Cos ( (c - m) t ) - Vm Cos ((c + m)t)

Eqn. 2

[KEC/EC/Prabhat/Student Lab Manual]

Page 41

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
v

Vc Sin ( c t ) + Vm Cos ( ( c - m) t ) - Vm Cos (( c

+ m)t)
Equation of modulated wave.

This is a signal made up of 3 signal components


carrier at

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)

[KEC/EC/Prabhat/Student Lab Manual]

Page 42

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

Experiment No- (8):


Generate Frequency Modulation.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
[KEC/EC/Prabhat/Student Lab Manual]

Page 43

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 44

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (8): Generate Frequency Modulation.


AIM: Generate Frequency Modulation.
APPARATUS REQUIREDTHEORY:
In telecommunications and signal processing, frequency modulation (FM)
conveys information over a carrier wave by varying its instantaneous
frequency. This is in contrast with amplitude modulation, in which
the amplitude of the carrier is varied while its frequency remains constant.
In analog applications, the difference between the instantaneous and the base
frequency of the carrier is directly proportional to the instantaneous value of
the input signal amplitude.
The baseband data signal (the message) to be transmitted is xm(t) and
the sinusoidal carrier is
, where fc is the carrier's base
frequency and Ac is the carrier's amplitude. The modulator combines the
carrier with the baseband data signal to get the transmitted signal:

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.

Sinusoidal baseband signal

[KEC/EC/Prabhat/Student Lab Manual]

Page 45

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
While it is an over-simplification, a baseband modulated signal may be
approximated by a sinusoidal Continuous Wave signal with a frequency fm.
The integral of such a signal is

Thus, in this specific case, equation (1) above simplifies to:

where the amplitude


of the modulating sinusoid, is represented by the
peak deviation
(see frequency deviation).
The harmonic distribution of a sine wave carrier modulated by such
a sinusoidal signal can be represented with Bessel functions - this provides a
basis for a mathematical understanding of frequency modulation in the
frequency domain.
Modulation index
As with other modulation indices, this quantity indicates by how much the
modulated variable varies around its unmodulated level. It relates to the
variations in the frequency of the carrier signal:

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.

[KEC/EC/Prabhat/Student Lab Manual]

Page 46

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 47

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (9):


Generate an FSK wave form.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 48

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (9): Generate an FSK wave form.


AIM: Generate an FSK wave form.
APPARATUS REQUIRED:
Theory:
Frequency-shift keying (FSK) is a frequency modulation scheme in which digital
information is transmitted through discrete frequency changes of a carrier
wave. The simplest FSK is binary FSK (BFSK). BFSK literally implies using a pair
of discrete frequencies to transmit binary (0s and 1s) information. With this
scheme, the "1" is called the mark frequency and the "0" is called the space
frequency.
Minimum-shift keying
Minimum frequency-shift keying or minimum-shift keying (MSK) is a particular
spectrally efficient form of coherent FSK. In MSK the difference between the
higher and lower frequency is identical to half the bit rate. Consequently, the
waveforms used to represent a 0 and a 1 bit differ by exactly half a carrier
period. This is the smallest FSK modulation index that can be chosen such that
the waveforms for 0 and 1 are orthogonal.

[KEC/EC/Prabhat/Student Lab Manual]

Page 49

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

************

Experiment No- (10):


To study Circular Convolution.

DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
B.Tech. (EC-6th SEM)

[KEC/EC/Prabhat/Student Lab Manual]

Page 50

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)

Experiment No- (10): To study Circular Convolution.


AIM: To study Circular Convolution.
APPARATUS REQUIRED: Operating System Windows XP
Constructor Simulator
Software - CCStudio 3
Theory:
Circular convolution is another way of finding the convolution sum of two input
signals. It
resembles the linear convolution, except that the sample values of one of the
input signals is folded and right shifted before the convolution sum is found.
Also note that circular convolution could also be found by taking the DFT of the
two input signals and finding the product of the two frequency domain signals.
The Inverse DFT of the product would give the output of the signal in the time
domain which is the circular convolution output. The two input signals could
have been of varying sample lengths. But we take the DFT of higher point,
which ever signals levels to. For eg. If one of the signal is of length 256 and the
other spans 51 samples, then we could only take 256 point DFT. So the output
of IDFT would be containing 256 samples instead of 306 samples, which follows
N1+N2 1 where N1 & N2 are the lengths 256 and 51 respectively of the two
inputs. Thus the output which should have been 306 samples long is fitted into
256 samples. The 256 points end up being a distorted version of the correct
signal. This process is called circular convolution.
PROCEDURE:
1. Open Code Composer Studio; make sure the DSP kit is turned on.
2. Start a new project using Project-new pull down menu, save it in a
separate directory (c:\ti\myprojects) with name cir conv.pjt.
3. Add the source files Circular Convolution.C to the project using
Projectadd files to project pull down menu.
4. Add the linker command file hello.cmd.
(Path: c:\ccstudio\tutorial\dsk6713\hello1\hello.cmd)
5. Add the run time support library file rts6700.lib.
(Path: c:\ccstudio\c6000\cgtools\lib\rts6700.lib)
6. Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
7. Build the program using the Project-Build pull down menu or by clicking
the shortcut icon on the left side of program window.
8. Load the program (cir conv.out) in program memory of DSP chip using
the Fileload program pull down menu.
9. Run the program using the Debugrun.

[KEC/EC/Prabhat/Student Lab Manual]

Page 51

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
PROGRAM:
/* program to implement circular convolution */
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j, k,x2[30],a[30];
void main()
{
printf(" Enter the length of the first sequence\n");
scanf("%d",&m);
printf(" Enter the length of the second sequence\n");
scanf("%d",&n);
printf(" Enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" Enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
/*If length of both sequences are not equal*/
{
if(m>n)
/* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
/*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{

[KEC/EC/Prabhat/Student Lab Manual]

Page 52

B.Tech. (EC-6th Sem)/DIGITAL SIGNAL PROCESSING LAB


(EEC-652)
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" The circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
OUTPUT:
Enter the length of the first sequence
4
Enter the length of the second sequence
3
Enter the first sequence
1234
Enter the second sequence
123
The circular convolution is
18 16 10 16

************

[KEC/EC/Prabhat/Student Lab Manual]

Page 53

You might also like