Digital Signal Processing: Laboratory Manual
Digital Signal Processing: Laboratory Manual
LABORATORY MANUAL
A.Y 2014-2015
Prepared by
J.NARENDER
Asst Professor
ECE Dept
List of Experiments:
FG
3. While coming to the lab bring the lab manual cum observation book, record etc.
4. Take only the lab manual, calculator (if needed) and a pen or pencil to the work
area.
5. Before coming to the lab, prepare the pre-lab questions. Read through the lab
experiment to familiarize yourself with the components and assembly sequence.
6. Utilize 3 hours time properly to perform the experiment (both in software and
hardware) and note down the readings properly. Do the calculations, draw the
graph and take signature from the instructor.
7. If the experiment is not completed in the prescribed time, the pending work has to
be done in the leisure hour or extended hours.
8. You have to submit the completed record book according to the deadlines set up
by your instructor.
9. For practical subjects there shall be a continuous evaluation during the semester
for 25 sessional marks and 50 end examination marks.
10. Of the 25 marks for internal, 15 marks shall be awarded for day-to-day work and
10 marks to be awarded by conducting an internal laboratory test.
INDEX
DSP Processor 80
EXPERMENT NO-1
AIM: -
To write a “MATLAB” Program to generate various signals such as unit impulse,
unit step, unit ramp, sinusoidal, exponential growing signal, exponential decaying signal,
cosine signal.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
One of the more useful functions in the study of linear systems is the "unit impulse
function." An ideal impulse function is a function that is zero everywhere but at the origin,
where it is infinitely high. However, the area of the impulse is finite. This is, at first hard to
visualize but we can do so by using the graphs shown below.
If b>a, then
Solution:
And
The unit step function and the impulse function are considered to be fundamental
functions in engineering, and it is strongly recommended that the reader becomes very
familiar with both of these functions.
The unit step function, also known as the Heaviside function, is defined as such:
Sometimes, u(0) is given other values, usually either 0 or 1. For many applications, it is
irrelevant what the value at zero is. u(0) is generally written as undefined.
Derivative
The unit step function is level in all places except for a discontinuity at t = 0. For this
reason, the derivative of the unit step function is 0 at all points t, except where t = 0. Where t =
0, the derivative of the unit step function is infinite.
The derivative of a unit step function is called an impulse function. The impulse function will
be described in more detail next.
Integral
The sine wave or sinusoid is a mathematical function that describes a smooth repetitive
oscillation. It occurs often in pure mathematics, as well as physics, signal processing,
electrical engineering and many other fields. Its most basic form as a function of time (t)
Where:
• A, the amplitude, is the peak deviation of the function from its center position.
• ω, the angular frequency, specifies how many oscillations occur in a unit time
interval, in radians per second
• φ, the phase, specifies where in its cycle the oscillation begins at t = 0.
A sampled sinusoid may be written as:
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close all;
disp('unit step signals');
N=input('enter the no of samples');
x=ones(1,N);
stem(x);
xlabel('time');
ylabel('amplitude');
title('unit step sequence');
% sinusoidal signals%
clc;
clear all;
close all;
disp('sinusoidal signals');
N=input('enter the no of samples');
n=0:1:N;
x=sin(n);
stem(x);
xlabel('time');
ylabel('amplitude');
title('sinusoidal sequence');
clc;
clear all;
close all;
disp('unit ramp signals');
N=input('enter the no of samples');
n=0:1:N;
x=n;
stem(x);
xlabel('time');
ylabel('amplitude');
title('unit ramp sequence');
clc;
clear all;
close all;
disp('unit impuse signal');
N=input ('enter the no of samples');
n=-N:1:N;
x=[zeros(1,N) 1 zeros(1,N)];
stem(n,x);
xlabel('time');
ylabel('amplitude');
tittle('impulse sequence');
% exponentialsignals%
clc;
clear all;
close all;
disp('exponential signals');
N=input('enter the no of samples');
n=0:1:N;
n=-N:1:N;
a=0.5;
x=a.^n;
stem(x);
Dept ECE Page 9
DSPLAB
xlabel('time');
ylabel('amplitude');
title('exponential sequence');
OUTPUT:-
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
time
sinusoidal signals
enter the no of samples6
sinusoidal sequence
1
0.8
0.6
0.4
0.2
amplitude
-0.2
-0.4
-0.6
-0.8
-1
1 2 3 4 5 6 7
time
4
amplitude
0
1 2 3 4 5 6 7
time
impulse sequence
1
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
-6 -4 -2 0 2 4 6
time
exponential signals
enter the no of samples6
exponential sequence
70
60
50
40
amplitude
30
20
10
0
0 2 4 6 8 10 12 14
time
RESULT:-
Thus the MATLAB program for generation of all signals was performed and the
output was verified.
EXERCISE PROGRAM:-
Y=exp (-2*∏*f*t)+exp(-8*∏*f*)
Y= ((exp (-1.56∏f)*Sin(2∏f)+cos(2∏f)?
5. Write a matlab program for generating u(n)-u(n-1)?
6. Write program to get Discrete time co-Sinusoidal Signal?
7. Write program to get Discrete time saw tooth Signal?
8. Write program to get Discrete time triangular Signal?
9. Write program to get addition of two sinusoidal sequences?
10. Write program to get exponential sequence?
VIVA QUESTIONS:-
1. Define Signal?
2. Define determistic and Random Signal?
3. Define Delta Function?
4. What is Signal Modeling?
5. Define Periodic and a periodic Signal?
EXPERMENT NO-2
AIM:-
To find the DFT& IDFT of a sequence without using the inbuilt functions.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
The sequence f(n) can be calculated from F(k) using the Inverse Discrete Fourier Transform
(IDFT):
The DFT is the most important discrete transform, used to perform Fourier analysis in
many practical applications.[1] In digital signal processing, the function is any quantity or
signal that varies over time, such as the pressure of a sound wave, a radio signal, or daily
temperature readings, sampled over a finite time interval (often defined by a window
function). In image processing, the samples can be the values of pixels along a row or column
of a raster image. The DFT is also used to efficiently solve partial differential equations, and
to perform other operations such as convolutions or multiplying large integers.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%DFT%
clc;
clear all;
close all;
a=input ('enter the input sequence');
N=length(a);
disp('length of input sequence is ');
N
for k=1:N;
x(k)=0;
for i=1:N;
x(k)=x(k)+a(i)*exp((-j*pi*2/N)*((i-1)*(k-1)));
end;
end;
k=1:N;
disp('the output is');
x(k)
subplot(2,1,1);
stem(k,abs(x(k)));
grid;
xlabel ('discrete frequency');
ylabel('magnitude');
title('magnitude response of dft');
subplot(2,1,2);
stem(angle(x(k))*180/(pi));
grid;
xlabel('discrete frequency');
ylabel('phase angle');
title('phase response of dft');
%IDFT%
clc;
clear all;
close all;
a=input('enter the input sequence');
OUTPUT:-
N=
the output is
ans =
0
1 1.5 2 2.5 3 3.5 4
discrete frequency
phase response of dft
200
100
phase angle
-100
-200
1 1.5 2 2.5 3 3.5 4
discrete frequency
N=
the output is
ans =
3.5
2.5
magnitude
1.5
0.5
0
1 1.5 2 2.5 3 3.5 4
discrete time
RESULT:-
DFT&IDFT of a given discrete time signal are executed using mat lab software.
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-3
AIM: -
To study frequency response of second order system using MATLAB.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
Second order systems are the systems or networks which contain two or
more storage elements and have describing equations that are second order
differential equations.
A second order filter is a circuit that has a transfer function of the form:
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc ;
clear all;
b=[1,4];
a=[1,-5];
w=-2*pi:pi/8:2*pi;
[h]=freqz(b,a,w);
subplot(2,1,1);
stem(w,abs(h));
xlabel('freq/w');
ylabel('magnitude');
grid;
title('magnitude response of diffenrtial equataion');
subplot(2,1,2);
stem(w,angle(h));
xlabel('freq/w');
ylabel('phase in rad');
grid;
title('phase response of diffenrtial equataion');
OUTPUT:-
0.5
0
-8 -6 -4 -2 0 2 4 6 8
freq/w
phase response of diffenrtial equataion
4
2
phase in rad
-2
-4
-8 -6 -4 -2 0 2 4 6 8
freq/w
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-4
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%fft%
clc;
clear all;
close all;
xn=input('enter the input sequence');
N=input('enter the number of samples');
n=0:1:N-1;
xk=fft(xn,N);
k=0:1:N-1;
subplot(2,1,1);
stem(k,abs(xk));
xlabel('frq/w');
ylabel('magnitude');
title('magnitude response of fft');
subplot(2,1,2);
stem(k,angle(xk));
xlabel('frq/w');
ylabel('phase');
title('phase response of fft');
OUTPUT:-
0
0 1 2 3 4 5 6 7
frq/w
phase response of fft
4
2
phase
-2
-4
0 1 2 3 4 5 6 7
frq/w
RESULT:-
Hence the FFT of a given input sequence is performed & executed by using
MATLAB.
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-5
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
The power spectrum of a time-series x(t) describes how the variance of the data x(t) is
distributed over the frequency components into which x(t) may be decomposed. This
distribution of the variance may be described either by a measure µ or by a statistical
cumulative distribution function S(f) = the power contributed by frequencies from 0 up to f.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
% power spectrum %
clc;
clear all;
close all;
f1=input('enter the first frequencey f1=');
f2=input('enter the second frequencey f2=');
fs=input('enter the sampling frequencey fs=');
t=0:1/fs:1;
x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t));
psd1=abs(fft(x).^2);
subplot(2,1,1);
plot(t*fs,10*log(psd1));
xlabel('frequency');
ylabel('magnitude');
title('psd using square magnitude method');
psd2=abs(fft(xcorr(x),length(t)));
subplot(2,1,2);
plot(t*fs,10*log(psd2));
xlabel('frequency');
ylabel('magnitude');
title('psd using auto corelation method');
OUTPUT:-
100
50
0
0 100 200 300 400 500 600 700 800 900 1000
frequency
psd using auto corelation method
140
magnitude
120
100
80
0 100 200 300 400 500 600 700 800 900 1000
frequency
RESULT:-
Hence the power spectral density is performed & executed by using MATLAB.
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-6
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2.Windows XP SP2.
THEORY:-
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.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close all;
rp=input('enter the pass band ripple:rp=');
rs=input('enter the stop band ripple:rs=');
fp=input('enter the pass band freq :fp=');
fs=input('enter the stop band freq:fp=');
f=input('enter the sampling freq:f=');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end;
c=input('enter the type of window function 1.rectangular 2.trangular 3.kaiser:n=');
if(c==1);
y=rectwin(n1);
disp('rectangular window filter response');
end;
if(c==2);
y=triang(n1);
disp('triangular window filter response');
end;
if(c==3);
y=kaiser(n1);
OUTPUT:-
-10
-20
-30
gain in db
-40
-50
-60
-70
-80
-90
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
-5
-10
-15
gain in db
-20
-25
-30
-35
-40
-45
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
-10
-20
-30
gain in db
-40
-50
-60
-70
-80
-90
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
1. Give the expression for finding the magnitude & phase response of FIR filter?
2. Compare different windows & their characteristics?
3. How FIR filters are designed using rectangular window?
4. What is Gibbs phenomenon? How it can be reduced?
5. Compare FIR&IIR filters?
EXPERMENT NO-7
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
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,
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close all;
rp=input('enter the pass band ripple:rp=');
rs=input('enter the stop band ripple:rs=');
fp=input('enter the pass band freq :fp=');
fs=input('enter the stop band freq:fp=');
f=input('enter the sampling freq:f=');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end;
c=input('enter the type of window function 1.rectangular 2.trangular 3.kaiser:n=');
if(c==1);
y=rectwin(n1);
disp('rectangular window filter response');
end;
if(c==2);
y=triang(n1);
OUTPUT:-
-10
-20
gain in db
-30
-40
-50
-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
-5
-10
gain in db
-15
-20
-25
-30
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
-10
-20
-30
gain in db
-40
-50
-60
-70
-80
-90
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq output i
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-8
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close all;
rp=input('enter the pass band ripple:rp=');
rs=input('enter the stop band ripple:rs=');
fp=input('enter the pass band frequency:fp=');
fs=input('enter the stop band frequency:fs=');
f=input('enter the sampling frequency:f=');
wp=2*fp/f;
ws=2*fs/f;
[N,wc]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(N,wc,'low','s');
w=0:0.01:pi;[n,o]=freqz(b,1,256);
[n,omega]=freq(b,a,w);
m=20*log10(abs(n));
subplot(2,1,1);
Dept ECE Page 45
DSPLAB
plot(omega/pi,m);
xlabel('normalised frequency 0/pi');
ylabel('gain frequency in db');
title('magnitude response');
subplot(2,1,2);
plot(angle,(n));
xlabel('normalised frequency ');
ylabel('phase');
title('phase response');
OUTPUT:-
magnitude response
100
gain frequency in db
-100
-200
-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency 0/pi
phase response
4
2
phase
-2
-4
0 50 100 150 200 250 300 350
normalised frequency
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-9
AIM: -
To implement the analog & digital High Pass IIR filter.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close all;
disp('enter the sepecifications of iir filter');
rp=input('enter the pass band ripple:rp=');
rs=input('enter the stop band ripple:rs=');
wp=input('enter the pass band freq:wp=');
ws=input('enter the stop band freq:ws=');
fs=input('enter the sampling freq fs=');
w1=2*wp/fs;
w2=2*ws/fs;
[N,wc]=buttord(w1,w2,rp,rs,'s');
disp('freq resp of iir high pass filter is:');
[b,a]=butter(N,wc,'high','s');
w=0:0.001:pi;
[n,omega]=freqs(b,a,w);
m=20*log10(abs(n));
subplot(2,1,1);
plot(omega/pi,m);
xlabel('normalised freq');
ylabel('gain');
title('magnitude response');
subplot(2,1,2);
plot(angle(n));
xlabel('normalised freq');
ylabel('phase');
title('phase response');
OUTPUT:-
magnitude response
500
0
gain
-500
-1000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq
phase response
4
2
phase
-2
-4
0 500 1000 1500 2000 2500 3000 3500
normalised freq
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-10
AIM: -
Generation of Sine Wave & Illustration of the Sampling Process in the Time Domain.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
The sine wave or sinusoid is a mathematical function that describes a smooth repetitive
oscillation. It occurs often in pure mathematics, as well as physics, signal processing,
electrical engineering and many other fields. Its most basic form as a function of time (t)
where:
• A, the amplitude, is the peak deviation of the function from its center position.
• ω, the angular frequency, specifies how many oscillations occur in a unit time
interval, in radians per second
• φ, the phase, specifies where in its cycle the oscillation begins at t = 0.
A sampled sinusoid may be written as:
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
% Generation of Sine Wave & Illustration of the Sampling Process in the Time Domain
clc;
t=
0:0.0005:1; a
= 10
f = 13;
xa =
a*sin(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);grid
xlabel('Time,
msec');
ylabel('Amplitude')
;
title('Continuous-time signal
x_{a}(t)'); axis([0 1 -10.2 10.2])
subplot(2,1,2
); T = 0.01;
n = 0:T:1;
xs =
a*sin(2*pi*f*n); k
= 0:length(n)-1;
stem(k,xs);
grid
xlabel('Time index n');
ylabel('Amplitude');
title('Discrete-time signal
x[n]'); axis([0 (length(n)-1) -
10.2 10.2])
OUTPUT:-
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-11
AIM: -
The objective of this program is To Generate Dual Tone Multiple Frequency (DTMF)
Signals.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clearall;
closeall;
ty=[sin(y(1)*t),sin(y(2)*t),sin(y(3)*t),sin(y(4)*t)
]/2; for k=1:length(number)
switch
number(k)
case '1'
tone =
tx(:,1)+ty(:,1);
sound(tone);
stem(tone);
case '2'
tone =
tx(:,1)+ty(:,2);
sound(tone);
stem(tone);
case '3'
tone =
tx(:,1)+ty(:,3);
sound(tone);
stem(tone);
case '4'
OUTPUT:-
Input: 01234
RESULT:-
Dual Tone Multiple Frequency (DTMF) Signals are generated by using MAT LAB.
Dept ECE Page 61
DSPLAB
EXERCISE PROGRAM:-
1. Write a matlab program to generate a sine wave with amplitude = 3, frequency 20Hz?
2. Write a matlab program to generate a cos wave with amplitude = 3, frequency 20Hz?
3. Write a matlab program to generate a triangular wave with amplitude = 8, frequency
10Hz?
4. Write a matlab program to generate a square wave with amplitude = 2, frequency
10kHz?
5. Write a matlab program to generate a sinc wave with amplitude = -8, frequency5Khz?
6. Write a matlab program to generate a sine wave with amplitude = 7, frequency 29Hz.
7. Write a matlab program to generate a cos wave with amplitude = 9, frequency 50Hz.
8. Write a matlab program to generate a triangular wave with amplitude = 24, frequency
100Hz.
9. Write a matlab program to generate a square wave with amplitude = 12, frequency
10kHz.
10. Write a matlab program to generate a sinc wave with amplitude = 5, frequency5Khz.
VIVA QUESTIONS:-
1. Define Signal?
2. Define determistic and Random Signal?
3. Define Delta Function?
4. What is Signal Modeling?
5. Define Periodic and a periodic Signal?
EXPERMENT NO-12
INTERPOLATION
Dept ECE Page 62
DSPLAB
AIM: -
The objective of this program is To Perform up sampling on the Given Input Sequence.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%interpolation%
clc;
clear all;
close all;
N=input('enter sample value');
n=0:N-1;
L=input('enter up sampling factor');
x=sin(2*pi*0.043*n)+sin(2*pi*0.031*n);
y=interp(x,L);
subplot(2,1,1);
stem(n,x(1:N));
xlabel('time');
ylabel('amp');
title('input sequence');
t=0:(N*L)-1;
subplot(2,1,2);
stem(t,y(1:N*L));
xlabel('time');
ylabel('amp');
title('output sequence');
OUTPUT:-
input sequence
2
1
amp
-1
-2
0 5 10 15 20 25 30 35 40 45 50
time
output sequence
2
1
amp
-1
-2
0 50 100 150 200 250
time
RESULT:-
This MATLAB program has been written to perform interpolation on the Given
Input Sequence.
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-13
DECIMATION
AIM: -
The objective of this program is To Perform Decimation on the Given Input Sequence.
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
In digital signal processing, decimation is the process of reducing the sampling rate of a
signal. Complementary to interpolation, which increases sampling rate, it is a specific case of sample
rate conversion in a multi-rate digital signal processing system. Decimation utilizes filtering to
mitigate aliasing distortion, which can occur when simply down sampling a signal. A system
component that performs decimation is called a decimator.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%decimation%
clc;
clear all;
close all;
N=input('enter sample value');
n=0:N-1;
m=input('enter down sampling factor');
x=sin(2*pi*0.043*n)+sin(2*pi*0.031*n);
y=decimate(x,m,'fir');
subplot(2,1,1);
stem(n,x(1:N));
xlabel('time');
ylabel('amp');
title('input sequence');
t=0:(N/m)-1;
subplot(2,1,2);
stem(t,y(1:N/m));
xlabel('time');
ylabel('amp');
title('output sequence');
OUTPUT:-
input sequence
2
1
amp
-1
-2
0 10 20 30 40 50 60 70
time
output sequence
2
1
amp
-1
-2
0 2 4 6 8 10 12 14 16 18 20
time
RESULT:-
This MATLAB program has been written to perform Decimation on the Given
Input Sequence.
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
1. Define decimation?
2. Define multi rate signal processing?
3. What are the effects of coefficient quantization in FIR filters?
4. What is quantization process?
5. What is transmultiplexer? What is its use?
EXPERMENT NO-14
AIM: -
SOFTWARE REQURIED:-
1. MATLAB R2010a.
2. Windows XP SP2.
THEORY:-
"Up sampling" is the process of inserting zero-valued samples between original samples to
increase the sampling rate. (This is called "zero-stuffing".) Up sampling adds to the original signal
undesired spectral images which are centered on multiples of the original sampling rate.
"Interpolation", in the DSP sense, is the process of up sampling followed by filtering. (The
filtering removes the undesired spectral images.) As a linear process, the DSP sense of interpolation is
somewhat different from the "math" sense of interpolation, but the result is conceptually similar: to
create "in-between" samples from the original samples. The result is as if you had just originally
sampled your signal at the higher rate.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
% interpolation/dismation sampling %
subplot(2,1,2);
stem(t,y(1:N*l/m));
xlabel('time');
ylabel('amplitude');
title('input sampling sequence');
OUTPUT:-
input sequence
2
1
amplitude
-1
-2
0 5 10 15 20 25 30
time
input sampling sequence
2
1
amplitude
-1
-2
0 20 40 60 80 100 120
time
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
EXPERMENT NO-15
AUDIO APPLICATIONS
AIM: -
To perform audio applications such as to plot a time & frequency display of microphone plus a
cosine using DSP.
EQUIPMENTS:-
PROGRAM:-
Main()
{
For(i=0;i<PTS;i++) //set up twiddle constants in w
{
w[i].real=cos(2*PI*i/512.0); //Re component of twiddle constants
w[i].imagl=sin(2*PI*i/512.0); //Im component of twiddle constants
}
Comm._intr(); //init DSK,code,McBSP
While (!RTDX_is Outpu Enabled(&ochan)) //wait forPC to enable RTDX
RESULT:-
Thus audio application is performed & spectrogram of an input signal is plotted using
MATLAB.
EXPERMENT NO-16
NOISE REMOVAL
AIM: -
EQUIPMENTS:-
THEORY:-
Adaptive filters are best used in cases where signal conditions or system parameters are slowly
Changing and the filter are to be adjusted to compensate for the change. The least mean squares
(LMS) criterion is such algorithm that can be used to provide the strategy for adjusting the filter
coefficient.
.
PROGRAM:-
#include “NCefg.h”
#include”dsk6713.h”
#include” dsk6713_aic23.h”
#define beta IE-13 //rate of convergence
#define N 30 //adaptive FIR filter length-vary this parameter & observe
float delay [N];
float w[N};
DSK6713_AIC23_Config config={\
0x0017, /*0 DSK6713_AIC23_LEFTINVOL Left line input channel volume*/ \
0x0017, /*1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume*/ \
0x00d8, /*2 DSK6713_AIC23_LEFTINVOL Left channel headphone volume*/ \
0x00d8, /*3 DSK6713_AIC23_RIGHTINVOL Right channel headphone volume*/
\
0x0011, /*4 DSK6713_AIC23_ANAPATH Analog audio path control*/ \
0x0000, /*5 DSK6713_AIC23_DIGPATH Digital audio path control*/ \
0x0000, /*6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /*7DSK6713_AIC23_DIGIF Digital audio interface format*/ \
0x0081, /*8DSK6713_AIC23_SAMPLERATE Sample rate control*/ \
0x0001, /*9DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/*main()-Main code routine, Initializes BSL and generates tone*/
Void main()
{
DSK6713_AIC23_codecHandle hCodec;
Int I_input,r_input,I_output,r_output,T;
/*Initialize the board support library,must be called first*/
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config); /*start the code C*/
DSK6713_AIC23_setfreq(hCOde c,1);
For(T=0:T<30:T++) //Initialize the adaptive FIR Coeffs=0
{ w[T]=0; //init buffer for weights
Delay[T]=0; ////init buffer for delay samples
}
While(1)
{/*Read a sample to the left channel */
While(!DSK6713_AIC23_read(hCodec.&l_input));
{/*Read a sample to the right channel */
While(!DSK6713_AIC23_read(hCodec.&r_input));
l_output=(short int) adaptive_filter(l_input,r_input);
l_output=r_output;
While(!DSK6713_AIC23_write (hCodec.&l_output)); /*send output to the Left channel*/
While(!DSK6713_AIC23_write(hCodec.&r_output)); /*send output to the Right channel*/
}
\DSK6713_AIC23_closecodec(hcodec); /*close the codec*/
}
RESULT:-
EXPERMENT NO-17
IMPULSE RESPONSE
AIM: -
SOFTWARE REQURIED:-
1.MATLAB R2010a.
2.Windows XP SP2.
THEORY:-
Second order systems are the systems or networks which contain two or more
storage elements and have describing equations that are second order differential
equations.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
subplot(2,1,2);
zplane(b,a);
xlabel('real axis');
ylabel('imaginary axis');
title('pole zero in z-plane');
OUTPUT:-
Impulse Response
1
amplitude
0.5
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
discrete time
pole zero in z-plane
1
imaginary axis
0.5
2
0
-0.5
-1
-3 -2 -1 0 1 2 3
real axis
RESULT:-
EXERCISE PROGRAM:-
VIVA QUESTIONS:-
A signal can be defined as a function that conveys information, generally about the state or
behavior of a physical system. There are two basic types of signals viz Analog (continuous time
signals which are defined along a continuum of times) and Digital (discrete-time).
Feature Use
Fast-Multiply accumulate Most DSP algorithms, including filtering,
transforms, etc. are multiplication- intensive
Specialized addressing
modes Efficient handling of data arrays and first-in, first-out
buffers in memory
Specialized program
control Efficient control of loops for many iterative DSP
algorithms. Fast interrupt handling for frequent I/O
operations.
On-chip peripherals and On-chip peripherals like A/D converters allow for
I/O small
low cost system designs. Similarly I/O interfaces
interfaces tailored
for common peripherals allow clean interfaces to off-
chip
I/O devices.
ARCHITECTUREOF6713 DSPPROCESSOR
This chapter provides an overview of the architectural structure of the TMS320C67xx DSP,
which comprises the central processing unit (CPU), memory, and on-chip peripherals. The C67xE
DSPs use an advanced modified Harvard architecture that maximizes processing power with eight
buses. Separate program and data spaces allow simultaneous access to program instructions and
data, providing a high degree of parallelism. For example, three reads and one write can be
performed in a single cycle. Instructions with parallel store and application-specific instructions
fully utilize this architecture. In addition, data can be transferred between data and program spaces.
Such Parallelism supports a powerful set of arithmetic, logic, and bit-manipulation operations that
can all be performed in a single machine cycle. Also, the C67xx DSP includes the control
mechanisms to manage interrupts, repeated operations, and function calling.
Bus Structure
The C67xx DSP architecture is built around eight major 16-bit buses (four program/data
buses and four address buses):
_ The program bus (PB) carries the instruction code and immediate operands from program
memory.
_ Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU, data
address generation logic, program address generation logic, on-chip peripherals, and data memory.
_ The CB and DB carry the operands that are read from data memory.
_ The EB carries the data to be written to memory.
_ Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for instruction
execution.
The C67xx DSP can generate up to two data-memory addresses per cycle using the two
auxiliary register arithmetic units (ARAU0 and ARAU1). The PB can carry data operands stored in
program space (for instance, a coefficient table) to the multiplier and adder for multiply/accumulate
operations or to a destination in data space for data move instructions (MVPD and READA). This
capability, in conjunction with the feature of dual-operand read, supports the execution of single-
cycle, 3-operand instructions such as the FIRS instruction. The C67xx DSP also has an on-chip
bidirectional bus for accessing on-chip peripherals. This bus is connected to DB and EB through the
bus exchanger in the CPU interface. Accesses that use this bus can require two or more cycles for
reads and writes, depending on the peripheral’s structure.
The CPU is common to all C67xE devices. The C67x CPU contains:
The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit
(ALU) and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean
operations. The ALU uses these inputs:
Accumulators
Accumulators A and B store the output from the ALU or the multiplier/adder block. They
can also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder.
Each accumulator is divided into three parts:
Guard bits (bits 39–32) High-
order word (bits 31–16) Low-
order word (bits 15–0)
Instructions are provided for storing the guard bits, for storing the high- and the low- order
accumulator words in data memory, and for transferring 32-bit accumulator words in or out of data
memory. Also, either of the accumulators can be used as temporary storage for the other.
Barrel Shifter
The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data
memory (using CB or DB), and a 40-bit output connected to the ALU or to data memory (using
EB). The barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the
input data. The shift requirements are defined in the shift count field of the instruction, the shift
count field (ASM) of status register ST1, or in temporary register T (when it is designated as a shift
count register).The barrel shifter and the exponent encoder normalize the values in an accumulator
in a single cycle. The LSBs of the output are filled with 0s, and the MSBs can be either zero filled
or sign extended, depending on the state of the sign-extension mode bit (SXM) in ST1. Additional
shift capabilities enable the processor to perform numerical scaling, bit extraction, extended
arithmetic, and overflow prevention operations.
Multiplier/Adder Unit
The multiplier/adder unit performs 17 _ 17-bit 2s-complement multiplication with a 40- bit
addition in a single instruction cycle. The multiplier/adder block consists of several elements: a
multiplier, an adder, signed/unsigned input control logic, fractional control logic, a zero detector, a
rounder (2s complement), overflow/saturation logic, and a 16-bit temporary storage register (T).
AIM: -
EQUIPMENT REQUIRED:-
THEORY:-
In this equation, x1(k), x2(n-k) and y(n) represent the input to and output from the system at
time n. Here we could see that one of the input is shifted in time by a value every time it is
multiplied with the other input signal. Linear Convolution is quite often used as a method of
implementing filters of various types.
PROCEDURE:
1) Generate the first input sequence ‘x’.
2) Plot the sequence in discrete form. [Make use of stem( )]
3) Give some relevant names to x-axis and y-axis.
4) Generate second input sequence ‘y’.
5) Repeat steps (2) and (3) for second sequence ‘y’.
6) Use the inbuilt function ‘conv( )’ to compute linear convolution of ‘x’ and ‘y’.
z = conv(x,y)
7) Plot the output sequence ‘z’. [Repeat steps 2 and 3]
8) Make use of subplot ( ) to plot the inputs and output sequences in a single window.
PROGRAM:
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0; for(i=n;i<=m+n-
1;i++)
h[i]=0;
/* convolution operation
*/ for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
OUTPUT:
RESULT:-
VIVA QUESTIONS:-
EQUIPMENT REQUIRED:-
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:-
/* 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]);
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++)
{
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:-
RESULT:-
VIVA QUESTIONS:-
EQUIPMENT REQUIRED:-
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.
PROCEDURE:-
[Use „ceil( )‟ for rounding off the value of „n‟ to the nearest integer] if „n‟ is
an odd number, then reduce its value by „1‟.
6. Generate (n+1)th point window coefficients.For example boxcar(n+1) generates a rectangular
window. y=boxcar(n+1)
7. Design an nth order FIR filter using the previously generated (n+1) length window
function. b=fir1(n,wp,y)
8. Find the frequency response of the filter by using „freqz( )‟ function. [h,o]=freqz(b,a,k) This
function returns k-point complex frequency response vector „h‟ and k-point frequency vector „o‟
in radians/samples of the filter.
A(ejw) a(1)+a(2)e-jw+………….a(n+1)e-jnw
Where a, b are vectors containing the denominator and numerator
coefficients. Here a=1.
9. Calculate the magnitude of the frequency response in decibels (dB). m= 20*log10(abs(h))
10. Plot the magnitude response [magnitude in dB Vs normalized frequency (o/pi)]
11. Give relevant names to x- and y- axes and give an appropriate title for the plot.
#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);
RESULT: -
By using windowing techniques (Bartlett, Rectangular, Blackman) the filters are designed.
VIVA QUESTIONS:-
AIM:-
To design of Butterworth Digital (low pass & high pass) filter.
EQUIPMENTS:-
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:
Eq.2
The difference equation for such a system is described by the following:
Eq .3
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. That’s why the filters are named as butter worth filters. Filter coefficients can be
found and the response can be plotted.
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).
3. Get the sampling frequency (f).
4. Calculate the analog pass band edge frequencies, w1 and w2.
w1 = 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
//iirfilters
#include<stdio.h>
#include<math.h>
int
i,w,wc,c,N
; float
H[100];
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);
}
OUTPUT:-
RESULT: -
Thus IIR (LP/HP) filter is designed using low pass Butterworth and chebyshev filters
technique and verified using the DSP processor.
VIVA QUESTIONS:-
1. What are the properties of chebyshev filter?
2. Define signal flow graph?
3. Draw the signal flow graph of first order digital filter?
4. What is advantage of cascade realization?
5. What is the main disadvantage of direct-form realization?