V semester
Lab In charge:
PRAVEEN K B
Lecturer, DEPT Of TCE
USN NUMBER
BATCH
17
V semester
Syllabus
Part A
LIST OF EXPERIMENTS USING MATLAB
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Part B
B. LIST OF EXPERIMENTS USING DSP PROCESSOR
1.
2.
3.
4.
5.
6.
Noise: Add noise above 3kHz and then remove; Interference suppression
using 400 Hz tone.
7.
17
V semester
Table of Contents
SL.
No.
List of Experiments :
Page
No.
Staff
signature
Part A(Cycle-1)
1
2
3
4
5
6
7
8
9
10
11
12
09
12
14
17
19
21
24
27
32
32
35
39
Part B(Cycle-2)
CCS Introduction
1
2
3
4
5
43
44
45
46
47
49
Noise: Add noise above 3kHz and then remove; Interference suppression
51
17
V semester
Introduction to MATLAB
The name MATLAB stands for MATrix LABoratory. MATLAB is a highperformance language for technical computing. It integrates computation,
visualization, and programming environment. It has powerful built-in routines
that enable a very wide variety of computations. It also has easy to use
graphics commands that make the visualization of results immediately
available. Matlab is especially designed for matrix computations: solving
systems of linear equations, computing eigenvalues and eigenvectors,
factoring matrices, and so forth. In addition, it has a variety of graphical
capabilities, and can be extended through programs written in its own
programming language. Many such programs come with the system; a
number of these extend Matlab's capabilities to nonlinear problems, such as
the solution of initial value problems for ordinary differential equations.
Typical uses:
1. Math and computation
2. Algorithm development
3. Data acquisition
4. Modeling, simulation, and prototyping
5. Data analysis, exploration and visualization
6. Scientific and engineering graphics
7. Application development
17
V semester
How to Program?
S1:
17
S2:
V semester
17
V semester
S4: Enter the code in editor and save it with appropriate name.
17
V semester
S5: Run the code in Command window by typing the name of the code.
17
V semester
Part A
17
V semester
Converting back x[n] into analog (resulting in x (t ) ) is the process of reconstruction. (D/A
converter)
Techniques for reconstruction-(i) ZOH (zero order hold) interpolation results in a staircase
waveform, is implemented by MATLAB plotting function stairs(n,x), (ii) FOH (first order
hold) where the adjacent samples are joined by straight lines is implemented by MATLAB
plotting function plot(n,x),(iii) spline interpolation, etc.
For x (t ) to be exactly the same as x(t), sampling theorem in the generation of x(n) from
x(t) is used. The sampling frequency fs determines the spacing between samples.
Aliasing-A high frequency signal is converted to a lower frequency, results due to under sampling.
Though it is undesirable in ADCs, it finds practical applications in stroboscope and sampling
oscilloscopes.
Algorithm:
1. Input the desired frequency fd (for which sampling theorem is to be verified).
2. Generate an analog signal xt of frequency fd for comparison.
3. Generate oversampled, nyquist & under sampled discrete time signals.
4. Plot the waveforms and hence prove sampling theorem.
MATLAB Program:
tfinal=0.05;
t=0:0.00005:tfinal;
fd=input('Enter analog freuency');
%define analog signal for comparison
xt=sin(2*pi*fd*t);
%simulate condition for undersampling i.e., fs1<2*fd
fs1=1.3*fd;
%define the time vector
n1=0:1/fs1:tfinal;
%Generate the undersampled signal
xn=sin(2*pi*n1*fd);
%plot the analog & sampled signals
subplot(3,1,1);
plot(t,xt,'b',n1,xn,'r*-');
title('undersampling plot');
%condition for Nyquist plot
fs2=2*fd;
n2=0:1/fs2:tfinal;
xn=sin(2*pi*fd*n2);
subplot(3,1,2);
plot(t,xt,'b',n2,xn,'r*-');
title('Nyquist plot');
Dept. of TCE, Dr.AIT
17
V semester
Result:
Enter analog frequency 200
The plots are shown in Fig.1.1
17
17
V semester
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];
equation). H ( z )
X ( z ) 1 a1 z 1 a 2 z 2
o A frequency response function obtained by applying DTFT on the impulse response
h[n] (or by replacing z with ej in H(z)) to get
Y (e j ) b0 b1e j b2 e 2 j
H ( e j )
X (e j ) 1 a1e j a 2 e 2 j
Given the difference equation or H(z), the impulse response of the LTI system is found
using filter or impz MATLAB functions. This is elaborated in experiment no.7 - Solving
a given difference equation. If the difference equation contains past samples of output, i.e.,
y[n-1], y[n-2], etc , then its impulse response is of infinite duration (IIR). For such systems
the impulse response is computed for a large value of n, say n=100 (to approximate n=).
Given only the input sequence x[n] and the output sequence y[n], we can find the impulse
function h[n] by using the inverse operation deconv. (The conv operation convolves 2
sequences x[n] and h[n] to obtain the output y[n]. for convolution operation refer
experiment no 3: Linear convolution of two given sequences). If both y[n] and x[n] are
finite then the impulse response is finite (FIR).
The deconvolution operation is valid only if the LTI system is invertible.
17
V semester
MATLAB Programs:
y= input('The output sequence y(n) of the system=');
x=input('the input sequence of the system=');
h=deconv(y,x);
disp('the impulse response of the system is=');
disp(h);
%graphical display part
N=length(h);
n=0:1:N-1;
stem(n,h);
xlabel('Time index n');
ylabel('Amplitude');
title('impulse response of a system')
%Verification
yv=conv(x,h);
disp('the verified output sequence is');
disp(yv)
Fig. 2.1 Impulse Response (Program 1)
Result:
The output sequence y(n) of the system=[1 2 1 1 0
the input sequence of the system=[1 1 1 1]
the impulse response of the system is= 1 1 -1
the verified output sequence is 1 2 1 1 0 -1
The plots are shown in Fig.2.1
-1]
17
V semester
Algorithm:
1. Input the two sequences as x1, x2
2. Convolve both to get output y.
3. Plot the sequences.
MATLAB Program:
Level 1 Program (both sequences are right sided)
%main part of computation
x1=input('Enter first sequence')
x2=input('Enter second sequence')
y=conv(x1,x2);
disp('linear con of x1 & x2 is y=');
disp(y);
%graphical display part
subplot (2,1,1);
stem(y);
xlabel('time index n');
ylabel('amplitude ');
title('convolution output');
subplot(2,2,3);
stem(x1);
xlabel('time index n');
ylabel('amplitude ');
title('plot of x1');
subplot(2,2,4);
Dept. of TCE, Dr.AIT
17
V semester
Result
Enter first sequence [1 2 3 4]**
x1 = 1 2 3 4
Enter second sequence[ 2 3 2 4]
x2 = 2 3 2 4
linear con of x1 & x2 is y=
2 7 14 25 26 20 16
**-Entered by user.
Fig.3.1Shows the plot For right sided sequences (Without time information)
17
V semester
17
V semester
x[k ]h[n k ]
x[n k ]h[k ]
. To compute this equation, the linear convolution involves the following operations:
o Folding- fold h[k] to get h[-k] ( for y[0])
o Multiplication vk[n] = x[k] h[n-k] (both sequences are multiplied sample by
sample)
o Addition- Sum all the samples of the sequence vk[n] to obtain y[n]
o Shifting the sequence h[-k] to get h[n-k] for the next n.
x[k ]h[
nk
] where the
where the index n k N implies circular shifting operation and k N implies folding
the sequence circularly.
Steps for circular convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel".
o Plot f [m] and h [m] as shown in Fig. 4.1. (use f(m) instead of x(k))
o Multiply the two sequences
o Add to get y[m]
o "Spin" h[m] n times Anti Clock Wise (counter-clockwise) to get h[n-m].
x[n] and h[n] can be both finite or infinite duration sequences. If infinite sequences, they
should be periodic, and the N is chosen to be at least equal to the period. If they are finite
sequences N is chosen as >= to max(xlength, hlength). Whereas in linear convolution N>=
xlength+hlength-1.
Say x[ n] {2,3, 1,1} and N = 5, then the x[-1] and x[-2] samples are plotted at x[N-1] =
x[-4] and x[N-2] =x[-3] places. Now x[n] is entered as x[n] {1,1,0,2,3} .
17
V semester
Algorithm:
1. Input the two sequences as x and h.
2. Circularly convolve both to get output y.
3. Plot the sequences.
MATLAB Program:
%Circular Convolution Program
x=[1 2 3 4];
h= [1 2 3 4];
N=max(length(x1),length(x2));
%compute the output
for n=0:N-1
y(n+1)=0;
for k=0:N-1
i=mod((n-k),N); %calculation of x index
if i<0
i=i+N;
end %end of if
y(n+1)=y(n+1)+h(k+1)*x(i+1);
end
%end of inner for loop
end
%end of outer for loop
disp('circular convolution of x1 &x2 is y=');
disp(y);
%plot
n1=0:N-1;
stem(n1,y);
title('Circular convolution output y(n)');
Result:
circular convolution of x1 &x2 is
y= 26 28 26 20
The plot is as shown in Fig. 4.1
17
V semester
The parameter l called lag indicates the time shift between the pair.
x[n]x[n l ]; l 0,1,2,...
[ n] .
This is verified in Fig. 5.1, where the autocorrelation of the rectangular pulse (square) has a
maximum value at l=0. All other samples are of lower value. Also the maximum value = 11 =
energy of the pulse [12+12+12..].
o A time shift of a signal does not change its autocorrelation sequence. For example, let
y[n]=x[n-k]; then ryy[l] = rxx[l] i.e., the autocorrelation of x[n] and y[n] are the same regardless
of the value of the time shift k. This can be verified with a sine and cosine sequences of same
amplitude and frequency will have identical autocorrelation functions.
o For power signals the autocorrelation sequence is given by
k
1
rxx [l ] lim
x[ n] x[ n l ]; l 0,1,2,... and for periodic signals with period N it
k 2 k 1
n k
1 N 1
is rxx [l ]
x[n]x[n l ]; l 0,1,2,... and this rxx[l] is also periodic with N. This is
N n 0
verified in Fig. 5.3 where we use the periodicity property of the autocorrelation sequence to
determine the period of the periodic signal y[n] which is x[n] (=cos(0.25*pi*n)) corrupted by
an additive uniformly distributed random noise of amplitude in the range [-0.5 0.5]
Algorithm:
1. Input the sequence as x.
2. Use the xcorr function to get auto correlated output r.
3. Plot the sequences.
17
V semester
MATLAB Programs
%Energy signals
%simple sequence
x2=[3,-1,2,1];
>> xcorr(x2)
ans = 3 5 -3 15
-3
%Computation of Autocorrelation of a
% rectangular Sequence
n = -5:5;
N=10;
% Generate the square sequence
x = ones(1,11);
% Compute the correlation sequence
%r = conv(x, fliplr(x));
r=xcorr(x);
disp('autocorrelation sequence r=');
disp(r);
%plot the sequences
subplot(2,1,1)
stem(n,x);
title('square sequence');
subplot(2,1,2)
k = -N:N;
stem(k, r);
title('autocorrelation output');
xlabel('Lag index'); ylabel('Amplitude');
Fig.5.1 Autocorrelation output
Result:
autocorrelation sequence r = 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000
8.0000 9.0000 10.0000 11.0000 10.0000 9.0000 8.0000 7.0000 6.0000 5.0000
4.0000 3.0000 2.0000 1.0000
17
V semester
x[n] y[n l ] x[n] y[(l n)] x[l ] y[l ] . i.e., convolving the
reference signal with a folded version of sequence to be shifted (y[n]) results in cross
correlation output. (Use fliplr function for folding the sequence for correlation).
The properties of cross correlation are 1) the cross correlation sequence sample values are
upper bounded by the inequality rxx [l ] rxx [0]ryy [0] x y
2) The cross correlation of two sequences x[n] and y[n]=x[n-k] shows a peak at the value
of k. Hence cross correlation is employed to compute the exact value of the delay k
between the 2 signals. Used in radar and sonar applications, where the received signal
reflected from the target is the delayed version of the transmitted signal (measure delay to
determine the distance of the target).
3) The ordering of the subscripts xy specifies that x[n] is the reference sequence that
remains fixed in time, whereas the sequence y[n] is shifted w.r.t x[n]. If y[n] is the
reference sequence then ryx [l ] rxy [l ] . Hence ryx[l] is obtained by time reversing the
sequence rxy[l].
Algorithm:
1. Input the sequence as x and y.
2. Use the xcorr function to get cross correlated output r.
3. Plot the sequences.
MATLAB Programs
% Computation of Cross-correlation Sequence using folded sequence and convolution
x = input('Type in the reference sequence = ');
y = input('Type in the second sequence = ');
17
V semester
17
V semester
17
V semester
Algorithm:
1. Input the two sequences as a and b representing the coefficients of y and x.
2. If IIR response, then input the length of the response required (say 100, which can be made
constant).
3. Compute the output response using the filter command.
4. Plot the input sequence & impulse response (and also step response, etc if required).
Given Problem
1)Difference equation y(n) - y(n-1) + 0.9y(n-2) = x(n);
Calculate impulse response h(n) and also step response at n=0,..,100
2)Plot the steady state response y[n] to x[n]=cos(0.05n)u(n), given y[n]-0.8y[n-1]=x[n]
17
V semester
MATLAB Program:
%To find Impulse Response
N=input('Length of response required=');
b=[1];
%x[n] coefficient
a=[1,-1,0.9]; %y coefficients
%impulse input
x=[1,zeros(1,N-1)];
%time vector for plotting
n=0:1:N-1;
%impulse response
h=filter(b,a,x);
*note
%plot the waveforms
subplot(2,1,1);
stem(n,x);
title('impulse input');
xlabel('n');
ylabel('(n)');
subplot(2,1,2);
stem(n,h);
title('impulse response');
xlabel('n');
ylabel('h(n)');
Result:
Length=100
Plots in Fig. 7.1
Fig.7.1 Impulse Response
17
V semester
17
V semester
X (k ) x[ n]e
j 2kn
N
; k 0,1,2,....N - 1
n 0
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. Compute the DFT using the fft command.
4. Plot the magnitude & phase spectra.
Matlab Program:
x=[1,2,3,6]; %x[n] sequence
N=4
%N points for DFT
xk=fft(x,N); %computes DFT
% compute & plot amplitude spectrum
n=0:1:N-1;
figure(1);
stem(n,abs(xk));
Dept. of TCE, Dr.AIT
17
V semester
Result:
Run1: with N =4, plots are as shown in Fig. 8.1
Run2: with N =8, plots are as shown in Fig. 8.2
Run 3: with n1=0:7; x=cos(2*pi*n*250/8000); %x[n] sequence of 250Hz with fs=8kHz,
& N=8 point DFT, Fig. 8.3 is the output, which shows a frequency of 0Hz, i.e., a peak at k=0 in the
magnitude spectrum.
Run 4: with n1=0:7; x=cos(2*pi*n*250/8000); %x[n] sequence of 250Hz with fs=8kHz,
17
Fig.8.1
Fig.8.2
Dept. of TCE, Dr.AIT
17
V semester
Fig.8.3
Fig.8.4
17
V semester
Fig.8.5
Fig 8.6
17
V semester
Algorithm:
1. Input the two sequences as x1, x2
2. Compute N = xlength + hlength -1
(for circular convolution, N=max(xlength + hlength))
3. Obtain N-point DFTs (X1, X2) of both the sequences.
4. Multiply both the DFTs (Y=X1X2).
5. Perform IDFT on Y to get y[n] (the linearly convolved sequence) in time domain.
6. Verify using the conv command.
7. Plot the sequences.
MATLAB Program:
%Linear Convolution Program using DFT
x1=[1 2 3 4];
x2= [1 2 3 4];
N=length(x1)+length(x2)-1;
%obtain DFTs
X1= fft(x1,N);
X2= fft(x2,N);
%Perform vector multiplication
y= X1.*X2;
%ifft to get y[n]
yn= ifft(y,N);
disp('linear convolution of x1 &x2 is yn=');
disp(yn);
%verify
disp('output using conv');
yv=conv(x1,x2);
disp(yv);
%plot
stem(yn);
Dept. of TCE, Dr.AIT
17
V semester
Result:
linear convolution of x1 &x2 is yn=
1.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000
output using conv
1 4 10 20 25 24 16
The output plot is shown in Fig. 9.1
Fig. 9.1
17
V semester
Fig. 9.2
17
V semester
17
Window
Name
Rectangular
Bartlett
Hanning
Hamming
Blackman
8
M
8
M
12
M
8
M
1.8
M
21db
6.1
M
6.2
M
6.6
M
B = FIR1(N,Wn,boxcar)
25db
B = FIR1(N,Wn,bartlett)
44db
B = FIR1(N,Wn,hanning)
53db
B= FIR1(N,Wn,hamming)
11
M
74db
B =
FIR1(N,Wn,blackman)
Matlab Program
%Design and implementation of FIR filter Method 1
%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);
Dept. of TCE, Dr.AIT
17
V semester
Result:
Plots are in Fig.10.3 & 10.4
Notice that freqs below 150 Hz are passed & above 150 are cutoff
%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;
%compute the normalized cut off frequency
wc=wc/pi;
%calculate & plot the window
hw=hamming(N+1);
stem(hw);
title('Fir filter window sequence- hamming window');
%find h(n) using FIR
h=fir1(N,wc,hamming(N+1));
%plot the frequency response
figure(2);
[m,w]=freqz(h,1,128);
mag=20*log10(abs(m));
plot(ws1*w/(2*pi),mag);
title('Fir filter frequency response');
grid;
Result:
Dept. of TCE, Dr.AIT
17
V semester
Fig.10.1
Fig.10.2
17
V semester
17
V semester
17
17
V semester
17
V semester
Part B
17
V semester
CCS INTRODUCTION
Procedure
1. Double click on CCS icon
2. Create a new project: project New
Type the project name (x.pjt) & store in myprojects folder
To open an existing project: project open
3. Files to be added to the project: project Add Files to project
a. c: \ CCStudio \ c5400 \ cgtools \ lib \ rts.lib
<Select type of file as: library>
b. c: \ ti \ c5400\ tutorial \ hello1 \ hello.cmd
< Select type of file as: Linker Command file>
4. File New source file same as xx.c
( Select type of file as: C/C++ file before saving) & add this C file to your project
5. Project Build. (obtain Build successful)
6. To execute ; File load program (select pjtname.out file)
7. To Run : Debug Run
8. Observe the output on the stdout window or waveforms using graph or CRO
9. To view waveforms View Graph
17
V semester
EXPERIMENT NO 1
Aim: To perform linear convolution for the given sequences
The linear convolution sum is y[n] x[n] h[ n]
C Program
# include<stdio.h>
# include<math.h>
main()
{//the two sequences can be of different lengths, no need to zero pad for this program
float h[4] = { 2,2,2,2}; float x[4] ={1,2,3,4};
float y[10];
int xlen=4; int hlen=4;
int N=xlen+hlen-1;
int k,n;
for(n=0;n<N;n++)
//outer loop for y[n] array
{
y[n]=0;
for(k=0;k<hlen;k++)
//inner loop for computing each y[n] point
{
if (((n-k)>=0) & ((n-k)<xlen))
y[n]=y[n]+h[k]*x[n-k];
//compute output
}
//end of inner for loop
printf("%f\t", y[n]);
}
//end of outer for loop
}
//end of main
Result
6.000000
12.000000
20.000000
18.000000
Verify with MATLAB / theoretical verification
14.000000
8.000000
17
V semester
EXPERIMENT NO 2
Aim: To perform circular convolution of two given sequences
The circular convolution sum is y[n] x[n] N h[n]
h[k ]x
nk
C Program
# include<stdio.h>
# include<math.h>
main()
{ //input the two sequences, if of uneven lengths zero pad the smaller one such that both are of
same size
float x[5]={1,2,3,4,5};
float h[5]={2,1,3,4,5};
float y[10];
//output sequence
int N=5;
// N=max of xlen and hlen//
nt k,n,i;
for(n=0;n<N;n++)
//outer loop for y[n] array
{
y[n]=0;
for(k=0;k<N;k++)
//inner loop for computing each y[n] point
{
i=(n-k)%N;
//compute the index modulo N
if(i<0)
//if index is <0, say x[-1], then convert to x[N-1]
i=i+N;
y[n]=y[n]+h[k]*x[i];
//compute output
}
//end of inner for loop
printf("%f\t",y[n]);
}
//end of outer for loop
}
//end of main
Result
41.000000
51.000000
51.000000
46.000000
Verify with MATLAB / theoretical verification
36.000000
17
V semester
X (k ) x[ n]e
j 2kn
N
; k 0,1,2,....N - 1
n 0
Where N is chosen such that N L , where L=length of x[n]. To implement using C program we
j 2kn
2kn
2kn
use the expression e N cos
j sin
and allot memory space for real and
N
N
imaginary parts of the DFT X(k)
C Program
#include <stdio.h>
#include <math.h>
main()
{
float y[16]; //for 8 point DFT to store real & imaginary
float x[4]={1,3,2,5}; //input only real sequence
float w;
int n,k,k1,N=8,xlen=4;
for(k=0;k<2*N;k=k+2)
{
y[k]=0; y[k+1]=0;
//initialize real & imag parts
k1=k/2; //actual k index
for(n=0;n<xlen;n++)
{
w=-2*3.14*k1*n/N; //careful about minus sign
y[k]=y[k]+x[n]*cos(w);
y[k+1]=y[k+1]+x[n]*sin(w);
}
printf("%f+j%f \n",y[k],y[k+1]);
}
}//end of main
Result: (on std out)
11.000000+j0.000000
2.424618+j-3.646700
-0.971311+j-2.009436
-0.407551+j-7.660230
-4.999950+j-0.022297
-0.460726+j7.633037
-1.009554+j1.996801
2.396780+j3.673694
MATLAB verification
>> x=[1 3 2 5];
>> fft(x,8) 11.0000
-0.4142 - 7.6569i
-1.0000 + 2.0000i 2.4142 - 3.6569i -5.0000
2.4142 + 3.6569i
-1.0000 - 2.0000i
-0.4142 + 7.6569i
17
V semester
EXPERIMENT 4
Aim: To find the Impulse response of the given first order / second order
system
Theory:A linear constant coefficient difference equation representing a second order system is
given by y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[n 1] b2 x[n 2];
For a first order system the coefficients a2 and b2 are zero.
Since the difference equation contains past samples of output, i.e., y[n-1], y[n-2], its impulse
response is of infinite duration (IIR). For such systems the impulse response is computed for a
large value of N, say N=100 (to approximate n=).
Impulse response implies x[n]= [n], an impulse, and the initial conditions x[-1], x[-2], y[-1] and
y[-2] are zero.
(refer expt 2 &7of part A - h=impz(b,a,N); %impulse response verification in MATLAB)
To implement in C the following algorithm is used.
Algorithm
1. Input the coefficients b0 b1 b2, a1 a2 (Say the coefficients from a 2nd order butterworth filter.
Note coefficient of y[n] is a0=1 always)
2. Generate the impulse input of size n (1st element=1, rest all=0)
3. Compute the output as y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[ n 1] b2 x[n 2];
4. Repeat step 3 for n=0 through N (say 50,100, etc)
C Program
#include <stdio.h>
float x[60],y[60];
main()
{
float a1,a2,b0,b1,b2;
int i,j,N=20;
a1= -1.1430; a2= 0.4128;
b0= 0.0675;b1=0.1349;b2=0.0675;
//generate impulse input
x[0]=1;
for(i=1;i<N;i++)
x[i]=0;
//generate output
for(j=0;j<N;j++)
{
y[j]=b0*x[j];
if(j>0)
y[j]=y[j]+b1*x[j-1]-a1*y[j-1];
if ((j-1)>0)
y[j]=y[j]+b2*x[j-2]-a2*y[j-2];
printf("%f \t",y[j]);
}
}
//end of main
17
V semester
17
V semester
EXPERIMENT NO 5
Aim: Realization of an FIR filter ( any type ) to meet given specifications. The
input can be a signal from function generator / speech signal .
Pre-requisite: Input is given from the signal generator of amplitude 1 v p-p and frequency > 20
Hz.
DSK kit: Plug in the signal generator o/p to line in and line out of TMS to CRO Before compiling,
Copy header files dsk6713.h and dsk6713_aic23.h from
C:\CCStudio_v3.1\c6000\dsk6713\include and paste it in the current project folder
C Program
#include "FIRcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728, 0.011139, 0.010502,0.000000, -0.018003,-0.033416,-0.031505,0.000000,0.063010, 0.144802,
0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,
-0.018003, 0 ,0.010502, 0.011139,0.005728,0.000000, -0.002423,-0.001591, 0.0};
static short in_buffer[100];
DSK6713_AIC23_Config config = { \
0x0017,
0x0017,
0x00d8,
0x00d8,
0x0011,
0x0000,
0x0000,
0x0043,
0x0081,
0x0001
};
/* main() - Main code routine, initializes BSL and generates tone */
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
Dept. of TCE, Dr.AIT
17
V semester
}
DSK6713_AIC23_closeCodec(hCodec); /* Close the codec */
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0; signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=31;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
Result: The output plot is observed on the CRO. This behaves as a highpass filter. See the effect
of filtering by giving a sinusoidal input to DSP kit and slowly varying its frequency in the range
from 0 to 3.5 kHz. What is the cutoff frequency of the filter? Change the filter co-efficients for
different types of window & Cut-off frequencies (refer FIR filter design part from experiment 11
in part A-MATLAB)
Dept. of TCE, Dr.AIT
17
V semester
EXPERIMENT NO 6
Noise removal programs:
(i)
Add noise above 3kHz and then remove (using adaptive filters)
(ii)
Theory:
In the previous experiments involving IIR & FIR filters, the filter coefficients were
determined before the start of the experiment and they remained constant. Whereas Adaptive filters
are filters whose transfer function coefficients or taps change over time in response to an external
error signal. Typical applications of these filters are Equalization, Linear Prediction, Noise
Cancellation, Time-Delay Estimation, Non-stationary Channel Estimation, etc. Different types of
adaptive filter algorithms are the Kalman adaptive filter algorithm, LMS adaptive filter algorithm
and RLS adaptive filter algorithm.
17
V semester
C Program
#include "NCcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#define beta 1E-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_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL 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, /* 7 DSK6713_AIC23_DIGIF
Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */
\
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/* main() - Main code routine, initializes BSL and generates tone*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input,l_output, r_output,T;
/* Initialize the board support library, must be called first */
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config); /* Start the codec */
DSK6713_AIC23_setFreq(hCodec, 1);
for (T = 0; T < 30; T++)
{
w[T] = 0;
delay[T] = 0;
}
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);
r_output=l_output;
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send o/p to the left channel */
Dept. of TCE, Dr.AIT
17
V semester
//ISR
//desired+noise
//noise as input to adapt FIR
Result:
Observe the waveform that appears on the CRO screen. Verify that the 3 KHz noise signal is being
cancelled gradually.
17
V semester
What is MATLAB?
2.
3.
4.
5.
What do you mean Aliasing? What is the condition to avoid aliasing for sampling?
6.
7.
What is meant by linearity of a system and how it is related to scaling and superposition?
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
What is the length of linear and circular convolutions if the two sequences are having the
length n1 and n2?
20.
21.
What are the advantages and special applications of Fourier transform, Fourier series, Z
transform and Laplace transform?
22.
23.
24.
What is auto-correlation?
25.
What is cross-correlation?
26.
What are the advantages of using autocorrelation and cross correlation properties in signal
processing fields?
27.
28.
29.
30.
17
V semester
32.
What is window method? How you will design an FIR filter using window method.
33.
What are low-pass and band-pass filter and what is the difference between these two?
34.
35.
17
V semester
Question Bank
PART A:
01. Write a MATLAB program to sample a continuous signal band limited to fm = _____ Hz,
under the following conditions:
a) Under sampling (Half the Nyquist rate)
b) Critical sampling (Nyquist rate)
c) Over sampling (> Twice the Nyquist rate)
02. Compute and verify using MATLAB program for the impulse response of a system described
by the following difference equation.
03. Compute and verify using MATLAB program the linear convolution of two given sequences
with/without using functions.
04. Compute and verify using MATLAB program the circular convolution between the two given
sequences with/without using function file.
05. Compute and verify using MATLAB program for the cross correlation for a given
Sequence.
06. Compute and verify using MATLAB program for the auto correlation for a given
Sequence.
07. Obtain the solution of the following difference equation for an arbitrary input x(n) and verify
using MATLAB program.
y (n) + 0.7 y(n-1) 0.45 y(n-2) 0.6 y(n-3) = 0.8 x(n) 0.44 x(n-1) + 0.36
x(n-2) + 0.02 x(n-3)
a) Calculate and plot the impulse response h (n) at n = 0:40
b) Calculate and plot the unit step response h (n) at n = 0:40
08. Compute and verify using MATLAB program the solution of a difference equation given the
initial conditions:
Difference equation is y(n) 1.5 y(n-1) + 0.5 y(n-2) = x(n), n>0 and given that
x(n) = (1/4) ^ n u(n) subject to y(-1) = 4 and y(-2) = 10. plot the output.
09. Compute and verify using MATLAB program the N point DFT of a given sequence and plot
its magnitude and phase spectrum.
10. Compute and verify using MATLAB program the N point IDFT of a given sequence and plot
its magnitude and phase spectrum.
11. Compute and verify using MATLAB program the linear convolution between the two given
sequences using DFT and IDFT.
12. Compute and verify using MATLAB program the circular convolution between the two given
sequences using DFT and IDFT.
17
PART B:
01. Compute and verify using C program the linear convolution of the two given sequences.
02. Compute and verify using C program the circular convolution of the two given sequences.
03. Compute a verify using C program the DFT of a given sequence.
04. Compute and verify using C program to find the impulse response of the given first / second
order system.
05. Compute and verify using C program to Realization of an FIR filter (any type) to meet given
specifications .The input can be a signal from function generator / speech signal.
17