Professional Documents
Culture Documents
DSP Rec
DSP Rec
ENGINEERING
REG NO :
NAME : CLASS:
UNIVERSITY REG. NO : SEM :
AIM :
To generate a discrete time signal sequence (Unit impulse ,Unit step, Unit ramp, Sine, Cosine, Exponential,)
using MATLAB function.
TOOLS REQUIRED :
ALGORITHM :
PROCEDURE :
1. Open MATLAB window.
2. Open a new editor window by clicking file->new project->new m-file. Type the program and save it as.
3. Run the program by selecting delay->Run.
4. Output will be displayed.
Exponential signal:
1. Assign the value of n.
2. Declare x as exponential function.
3. Plot the graph
.
Sinusoidal signal:
1. Assign the value of n.
2. Declare x as sine function.
3. Plot the graph.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Cosine wave:
1. Assign the value of n.
2. Declare x as cosine function.
3. Plot the graph.
PROGRAM:
DEPARTMENT OF ECE
OUTPUT :
DEPARTMENT OF ECE
I. Exponential Decaying Signal :
clc;
clear all;
close all;
disp('exponential decaying signal')
N=input('number of samples');
n=0:1:N
x=exp(-n)
stem(n,x);
xlabel('time');
ylabel('amplitude')
title('Exponential decaying signal response');
clc;
clear all;
close all;
disp('sine signal');
N=input('number of samples');
n=0:1:N
x=sin(n)
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('sine response');
:clc;clear all;
close all;
disp('cosine signal');
N=input('number of samples');
n=0:1:N
x=cos(n)
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('cosine response');
DEPARTMENT OF ECE
Exponentional Growing Signal :
Sine signal :
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Cosine Signal :
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT:
Thus, the various types of sequences have been generated by using MATLAB software.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO:2 LINEAR AND CIRCULAR CONVOLUTION
DATE :
AIM :
To implement linear convolution and circular convolution using MATLAB software.
TOOLS REQUIRED :
THEORY :
Linear convolution :
The linear convolution of two discrete time sequence x1(n) and x2(n) is defined as
x3(n)=x1(n).x2(n)=x2(n).x1(n)
Circular convolution :
The circular convolution of two discrete time sequence x1(n) and x2(n) with periodicity of n samples is defined as
x3(n)=∑𝑁−1
𝑚=0 𝑥1(𝑚). 𝑥2(𝑛 − 𝑚)N
DEPARTMENT OF ECE
OUTPUT :
Linear convolution :
DEPARTMENT OF ECE
ALGORITHM :
Linear convolution :
clc;
clear all;
close all;
x=input('Enter the first sample');
N1=length(x);
h=input('Enter the second sample');
N2=length(h);
n=0:1: N1-1
subplot(2,2,1);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('x sequence response');
n=0:1: N2-1
subplot(2,2,2);
stem(n,h);
xlabel('time');
ylabel('amplitude');
title('h sequence response');
y=conv(x,h);
N=N1+N2-1;
n=0:1:N-1;
subplot(2,2,3);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('Convolution of x and h response');
DEPARTMENT OF ECE
Circular convolution:
DEPARTMENT OF ECE
Circular convolution :
clc;
clear all;
close all;
x=input('Enter the first sequence');
N1=length(x);
h=input('Enter the second sequence');
N2=length(h);
n=0:1: N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('x sequence response');
n=0:1: N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('time');
ylabel('amplitude');
title('h sequence of response');
N=max(N1,N2);
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
for n=1: N
y(n)=0;
for i=1: N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(x(i)*h(j))];
end
end
disp('convolution of x and h is');
subplot(2,2,3);
stem(y);
xlabel('time');
ylabel('amplitude');
title('convolution of x and h response');
DEPARTMENT OF ECE
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus circular and linear convolution are implemented using MATLAB and the outputs verified displayed.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 3 Auto Correlation and Cross Correlation
DATE :
AIM :
TOOLS REQUIRED :
ALGORITHM :
PROCEDURE :
1. Open MATLAB window.
2. Open a new editor window by clicking file->new project->new m-file. Type the program and save it as.
3. Run the program by selecting delay->Run.
4. Output will be displayed.
DEPARTMENT OF ECE
CROSS – CORRELATION OUTPUT:
DEPARTMENT OF ECE
PROGRAM :
CROSS CORRELATION
clear all;
close all;
x=input(‘enter the 1st sequence’);
h=input(‘enter the 2nd sequence’);
y=xcorr(x,h);
figure;subplot(3,1,1);
stem(x);ylabel(‘Amplitude --.’);
xlabel(‘(a) n --.’);
subplot(3,1,2);
stem(h);ylabel(‘Amplitude --.’);
xlabel(‘(b) n --.’);
subplot(3,1,3);
stem(fliplr(y));ylabel(‘Amplitude --.’);
xlabel(‘(c) n --.’);
disp(‘The resultant signal is’);fliplr(y)
AUTO CORRELATION
DEPARTMENT OF ECE
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT:
Thus the auto correlation and cross correlation was performed using MATLAB and the results were
plotted
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 4
FREQUENCY ANALYSIS USING DFT
DATE :
AIM :
To study and plot the signal from DFT by using MATLAB software and also plot the magnitude and phase
spectrum plot.
TOOLS REQUIRED :
THEORY :
DFT :
The discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of
coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values.
It can be said to convert the sampled function from its original domain (often time or position along a line) to the
frequency domain.
ALGORITHM :
PROGRAM:
clc;
close all;
clear all;
x=input('Enter the sequence x= ');
N=input('Enter the length of the DFT N= ');
len=length(x);
if N>len
x=[x zeros(1,N-len)];
elseif N<len
x=x(1:N);
end
i=sqrt(-1);
w=exp(-i*2*pi/N);
n=0:(N-1);
k=0:(N-1);
nk=n'*k;
W=w.^nk;
DEPARTMENT OF ECE
OUTPUT:
DEPARTMENT OF ECE
X=x*W;
disp(X);
subplot(211);
stem(k,abs(X));
title('Magnitude Spectrum');
xlabel('Discrete frequency');
ylabel('Amplitude');
grid on;
subplot(212);
stem(k,angle(X));
title('Phase Spectrum');
xlabel('Discrete frequency');
ylabel('Phase Angle');
grid on;
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus the DFT signal is plotted and its magnitude and phase plot spectrum is obtained and the output is verified.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 5 DESIGN OF FIR FILTER
DATE :
AIM:
To design a FIR filter using MATLAB software.
1.Rectangular window
2.Hamming window
3.Hanning window
APPARATUS REQUIRED:
System with MATLAB software.
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter ‘N’.
4. Design the low pass, high pass, band pass and band stop filter.
5. Plot the magnitude response of all filters.
PROGRAM :
Rectangular Window :
clc;
clear all;
close all;
disp('the type of filters:');
disp('1)low pass filter');
disp('2)high pass filter');
disp('3)band pass filter');
disp('4)band stop filter');
k=input('enter the choice of filter');
N=input('enter the length of filter');
t=(N-1)/2;
switch k
case 1
wc=input('enter the lower cutoff frequency');
for n=1:N
if (n-1)==t
hd(n)=(wc)/pi;
else
hd(n)=sin(wc*(n-1)-t)/(pi*(n-1)-t);
end
end;
case 2
wc=input('enter the higher cutoff frequency');
DEPARTMENT OF ECE
OUTPUT :
Rectangular Window :
hd= -0.1283 -0.3529 1.1821 0.2503 0.1415 0.0958 0.0686 0.0496 0.0350 0.0233 0.0135 0.0054
w= 1 1 1 1 1 1 1 1 1 1 1 1
h= -0.1283 -0.3529 1.1821 0.2503 0.1415 0.0958 0.0686 0.0496 0.0350 0.0233 0.0135 0.0054
DEPARTMENT OF ECE
for n=1:N
if (n-1)==t
hd(n)=(pi-wc)/pi;
else
hd(n)=(sin(pi*(n-1)-t))-(sin(wc*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 3
wc1=input('enter the lower cutoff frequency');
wc2=input('enter the higher cutoff frequency');
for n=1:N
if (n-1)==t
hd(n)=(wc2-wc1)/pi;
else
hd(n)=(sin(wc2*(n-1)-t))-(sin(wc1*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 4
wc1=input('enter the lower cutoff frequency');
wc2=input('enter the higher cutoff frequency');
for n=1:N
if (n-1)==t
hd(n)=(pi+(wc2-wc1))/pi;
else
hd(n)=(sin(pi*(n-1)-t)*sin(wc2*(n-1)-t)+sin(wc1*(n-1)-t))/(pi*((n-1)-t));
end
end
end;
disp('rectangle window');
for n=1:1:N
w(n)=1;
end;
disp('hd=');
disp(hd);
disp('w=');
disp(w);
for n=1:1:N
h(n)=hd(n)*w(n);
end;
disp('h=');
disp(h);
N=linspace(-2*pi,2*pi);
[h1,w1]=freqz(h,1,1024);
subplot(2,1,1);
plot(w1,(10*log(abs(h1))));
grid;
title('magnitude plot');
xlabel('frequency in radians');
DEPARTMENT OF ECE
High Pass Filter :
Columns 17 through 20
0.0506 -0.0968 0.0578 -0.0873
w= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
h= Columns 1 through 16
0.0831 -0.1102 -0.0806 -9.8382 0.3694 0.0842 0.1808 -0.0032 0.1218 -0.0488 0.0850 -0.0785
0.0619 -0.0953 0.0510 -0.1006
Columns 17 through 20
0.0506 -0.0968 0.0578 -0.0873
DEPARTMENT OF ECE
ylabel('magnitude in db');
subplot(2,1,2);
plot(w1,angle(h1));
grid;
title('phase plot');
xlabel('frequency in radians');
ylabel('angle');
DEPARTMENT OF ECE
Band Pass Filter :
hd= -0.6869 -0.3378 0.0633 0.4553 0.7816 1.0034 1.1416 0.0637 0.3659 0.1149 -0.2429 -0.5948 -
0.8718 -1.0243 -1.0251
w= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
h= -0.6869 -0.3378 0.0633 0.4553 0.7816 1.0034 1.1416 0.0637 0.3659 0.1149 -0.2429 -0.5948 -
0.8718 -1.0243 -1.0251
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Band Stop Filter :
Columns 17 through 20
0.0458 0.0725 -0.0254 0.0916
w= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
h= Columns 1 through 16
0.0031 0.0323 -0.0286 0.1038 -0.0229 0.1405 0.0351 0.1449 0.1534 0.2865 -0.0839 -0.0519
0.1227 -0.0114 0.1106 0.0291
Columns 17 through 20
0.0458 0.0725 -0.0254 0.0916
DEPARTMENT OF ECE
Hamming Window :
clc;
clear all;close
all;
disp('the type of filters:'); disp('1)low pass filter');
disp('2)high pass filter'); disp('3)band pass filter');
disp('4)band stop filter'); k=input('enter the choice
of filter');N=input('enter the length of filter');t=(N-
1)/2;
switch k
case 1
wc=input('enter the lower cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(wc)/pi;else
hd(n)=sin(wc*(n-1)-t)/(pi*(n-1)-t); end
end;
case 2
wc=input('enter the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(pi-wc)/pi;else
hd(n)=(sin(pi*(n-1)-t))-(sin(wc*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 3
wc1=input('enter the lower cutoff frequency'); wc2=input('enter
the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(wc2-wc1)/pi; else
hd(n)=(sin(wc2*(n-1)-t))-(sin(wc1*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 4
wc1=input('enter the lower cutoff frequency'); wc2=input('enter
the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(pi+(wc2-wc1))/pi; else
hd(n)=(sin(pi*(n-1)-t)*sin(wc2*(n-1)-t)+sin(wc1*(n-1)-t))/(pi*((n-1)-t));
end
end
end;
disp('hamming window');for
n=1:1:N
w(n)=0.54-(0.46*cos(2*(n-1)*pi)/(N-1));
end; disp('hd=');
disp(hd);
DEPARTMENT OF ECE
Hamming window :
hd= -0.1283 -0.3746 1.2544 0.2532 0.1297 0.0741 0.0397 0.0155 -0.0021 -0.0147 -0.0231 -0.0278
w= 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982 0.4982
h= -0.0639 -0.1866 0.6249 0.1261 0.0646 0.0369 0.0198 0.0077 -0.0011 -0.0073 -0.0115 -0.0139
DEPARTMENT OF ECE
disp('w=');
disp(w); for
n=1:1:N
h(n)=hd(n)*w(n);
end; disp('h=');
disp(h);
N=linspace(-2*pi,2*pi);
[h1,w1]=freqz(h,1,1024);
subplot(2,1,1);
plot(w1,(10*log(abs(h1)))); grid;
title('magnitude plot'); xlabel('frequency
in radians');ylabel('magnitude in db');
subplot(2,1,2);
plot(w1,angle(h1)); grid;
title('phase plot'); xlabel('frequency in
radians');ylabel('angle');
DEPARTMENT OF ECE
High Pass Filter :
Columns 17 through 23
1.0036 -0.9859 1.0200 -0.9795 1.0162 -0.9913 1.0000
w= Columns 1 through 16
0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191
0.5191 0.5191 0.5191 0.5191
Columns 17 through 23
0.5191 0.5191 0.5191 0.5191 0.5191 0.5191 0.5191
h= Columns 1 through 16
0.5663 -0.4610 0.5790 -0.4943 0.6557 -0.4310 0.5845 -0.4748 0.5432 -0.5126 0.5120 0.4365
0.5004 -0.5361 0.5072 -0.5241
Columns 17 through 23
0.5210 -0.5118 0.5294 -0.5085 0.5275 -0.5146 0.5191
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Band Pass Filter :
Columns 17 through 25
-0.7357 -0.9962 -0.9246 -0.5374 0.0362 0.5999 0.9588 0.9877 0.6755
w= Columns 1 through 16
0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208
0.5208 0.5208 0.5208 0.5208
Columns 17 through 25
0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208 0.5208
h= Columns 1 through 16
0.2869 0.4920 0.5275 0.3807 0.1021 -0.2129 -0.4565 -0.5466 -0.4544 -0.2141 0.0911 0.3668
0.0166 0.3370 0.1510 -0.1275
Columns 17 through 25
-0.3832 -0.5188 -0.4815 -0.2799 0.0188 0.3125 0.4994 0.5144 0.3518
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Band Stop Filter :
Columns 17 through 24
0.7467 -0.9315 0.7531 -0.6440 0.2720 0.0079 -0.3962 0.6368
w= Columns 1 through 16
0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200
0.5200 0.5200 0.5200 0.5200
Columns 17 through 24
0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200 0.5200
h= Columns 1 through 16
0.3859 -0.4678 0.4182 -0.3689 0.1872 -0.0566 -0.1684 0.2788 -0.4323 0.4368 -0.4353 0.3731 -
0.2899 -0.0476 0.1263 -0.3589
Columns 17 through 24
0.3883 -0.4844 0.3916 -0.3349 0.1414 0.0041 -0.2060 0.3311
DEPARTMENT OF ECE
Hanning Window :
clc;
clear all;close
all;
disp('the type of filters:'); disp('1)low pass filter');
disp('2)high pass filter'); disp('3)band pass filter');
disp('4)band stop filter'); k=input('enter the choice
of filter');N=input('enter the length of filter');t=(N-
1)/2;
switch k
case 1
wc=input('enter the lower cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(wc)/pi;else
hd(n)=sin(wc*(n-1)-t)/(pi*(n-1)-t);
end
end;
case 2
wc=input('enter the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(pi-wc)/pi;else
hd(n)=(sin(pi*(n-1)-t))-(sin(wc*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 3
wc1=input('enter the lower cutoff frequency'); wc2=input('enter
the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(wc2-wc1)/pi; else
hd(n)=(sin(wc2*(n-1)-t))-(sin(wc1*(n-1)-t))/(pi*(n-1)-t);
end
end;
case 4
wc1=input('enter the lower cutoff frequency'); wc2=input('enter
the higher cutoff frequency');for n=1:N
if (n-1)==t
hd(n)=(pi+(wc2-wc1))/pi; else
hd(n)=(sin(pi*(n-1)-t)*sin(wc2*(n-1)-t)+sin(wc1*(n-1)-t))/(pi*((n-1)-t));
end
end
end;
disp('hanning window');for
n=1:1:N
w(n)=0.5-(0.5*cos(2*(n-1)*pi)/(N-1));
end; disp('hd=');
disp(hd);
disp('w=');
disp(w);
DEPARTMENT OF ECE
Hanning window :
hd= -0.1283 -0.3529 1.1821 0.2503 0.1415 0.0958 0.0686 0.0496 0.0350 0.0233 0.0135 0.0054
w= 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545 0.4545
h= -0.0583 -0.1604 0.5373 0.1138 0.0643 0.0435 0.0312 0.0226 0.0159 0.0106 0.0062 0.0025
DEPARTMENT OF ECE
for n=1:1:N
h(n)=hd(n)*w(n);
end; disp('h=');
disp(h);
N=linspace(-2*pi,2*pi);
[h1,w1]=freqz(h,1,1024);
subplot(2,1,1);
plot(w1,(10*log(abs(h1)))); grid;
title('magnitude plot'); xlabel('frequency
in radians');ylabel('magnitude in db');
subplot(2,1,2);
plot(w1,angle(h1)); grid;
title('phase plot'); xlabel('frequency in
radians');ylabel('angle');
DEPARTMENT OF ECE
High Pass Filter :
w= 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583 0.4583
0.4583
h= 0.1494 -0.0398 -1.1226 -0.2520 0.0585 -0.1742 0.4146 -0.1478 0.1175 -0.1313 0.1306 -0.1212
0.1378
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Band Pass Filter :
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Band Stop Filter :
hd= 0.8864 0.6424 -0.2142 -1.0288 -1.4165 0.2715 0.7940 1.0510 0.5454 -0.3565
w= 0.4444 0.4444 0.4444 0.4444 0.4444 0.4444 0.4444 0.4444 0.4444 0.4444
h= 0.3940 0.2855 -0.0952 -0.4572 -0.6296 0.1207 0.3529 0.4671 0.2424 -0.1585
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus the program for FIR filter was executed and the output was verified using MATLAB software.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 6
BUTTERWORTH DIGITAL IIR FILTER
DATE :
AIM:
To design a Butterworth digital IIR filter using MATLAB software.
APPARATUS REQUIRED:
System with MATLAB software.
ALGORITHM:
log √ [10 kp – 1 / 10 kp – 1]
N=
log s / p
PROGRAM:
Butterworth Filter :
clc;
clf;
close all;
t=input('enter the sampling time');
w1=input('enter the pass band frequency in radian');
w2=input('enter the stop band frequency in radian');
k1=input('enter the stop band attenuation in db');
k2=input('enter the pass band attenuation in db');
p=input('butterworth');
q=input('1.impulse invariant \n 2.bilinear transform');
if q==1
wp=w1/t;
ws=w2/t;
else
wp=(2/t)*tan(w1/2);
wn=(2/t)*tan(w2/2);
DEPARTMENT OF ECE
OUTPUT:
DEPARTMENT OF ECE
end;
x=(10^(0.1*k2)-1);
y=(10^(0.1*k1)-1);
k=wp/ws;
N=ceil(log10(x/y)/(2*log10(1/k)));
wc=wp/((10^(k1/10)-1)^(1/(2*N)));
[b,a]=butter(N,wc,'s');
if q==1
[c,d]=impinvar(b,a,t);
else
[c,d]=bilinear(b,a,t);
end;
w=linspace(-2*pi,2*pi);
h= freqz(c,d,w);
subplot(2,1,1);
plot(w,(10*log10(abs(h))));
title('magnitude plot');
xlabel('frequency in radian');
ylabel('magnitude in db');
grid;
disp('c=');
disp(c);
disp('d=');
disp(d);
subplot(2,1,2);
plot(w,angle(h));
title('phase plot');
xlabel('frequency in radian');
ylabel('angle');
grid;
DEPARTMENT OF ECE
OUTPUT:
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus the butterworth program was executed and the output was verified using MATLAB
software.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 7 CHEBYSHEV DIGITAL IIR FILTER
DATE :
AIM:
To design a digital IIR filter using Chebyshev filter with MATLAB software.
APPARATUS REQUIRED:
System with MATLAB software.
ALGORITHM:
log √ [10 kp – 1 / 10 kp – 1]
N=
log s /p
PROGRAM:
clc;
clear all;close
all;
t=input('enter the sampling time');
w1=input('enter the pass band frequency in radians');w2=input('enter
the stop band frequency in radians');k1=input('enter the stop band
attenuation in db'); k2=input('enter the pass band attenuation in db');
p=input('chebyshev');
q=input('1.impulse invariant \n 2.bilinear transform');if q==1
wp=w1/t;ws=w2/t;
else
wp=(2/t)*tan(w1/2);
ws=(2/t)*tan(w2/2);
end;
N=ceil(cosh(sqrt((10^(0.1*k2)-1)/(10^(0.1*k1)-1)))/cosh(wp/ws)); [b,a]=cheby1(N,k2,wp,'s');
if q==1
[c,d]=impinvar(b,a,t); else
[c,d]=bilinear(b,a,t);
DEPARTMENT OF ECE
OUTPUT:
Impulse Invarient :
1.chebychev1
1.impulse invariant
2.bilinear transform1
c= 0.0254 0
d= 1.0000 -0.9749
DEPARTMENT OF ECE
end;
w=linspace(-2*pi,2*pi);
h=freqz(c,d,w);
subplot(2,1,1);
plot(w,(10*log10(abs(h))));
title('magnitude plot'); xlabel('frequency
in radians');ylabel('magnitude in db');
grid;
disp('c='); disp(c);
disp('d='); disp(d);
subplot(2,1,2);
plot(w,angle(h));
title('phase plot');
xlabel('frequency in radians');
ylabel('angle');
grid;
DEPARTMENT OF ECE
Bilinear Transform:
DEPARTMENT OF ECE
S.No Mark Allocation Max. Marks
Marks Awarded
1 Preparation 2
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus the chebyshev program was executed and the output was verified using MATLAB
software.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 8
AIM :
To study the architecture of DSP processor TMS320c54xx.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
DSP COMPUTATIONAL BUILDING BLOCKS
Each computational block of the DSP should be optimized for functionality and speed and in the meanwhile the
design should be sufficiently general so that it can be easily integrated with other blocks to implement overall
DSP systems.
Multipliers
The advent of single chip multipliers paved the way for implementing DSP functions on a VLSI chip. Parallel
multipliers replaced the traditional shift and add multipliers now days. Parallel multipliers take a single
processor cycle to fetch and execute the instruction and to store the result. They are also called as Array
multipliers. The key features to be considered for a multiplier are
a. Accuracy
b. Dynamic range
c. Speed
Shifters
Shifters are used to either scale down or scale up operands or the results.
Barrel Shifters
In conventional microprocessors, normal shift registers are used for shift operation. As it requires one clock
cycle for each shift, it is not desirable for DSP applications, which generally involves more shifts. In other
words, for DSP applications as speed is the crucial issue, several shifts are to be accomplished in a single
execution cycle. This can be accomplished using a barrel shifter, which connects the input lines representing a
word to a group of output lines with the required shifts determined by its control inputs.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Arithmetic and Logic Unit
A typical DSP device should be capable of handling arithmetic instructions like ADD, SUB,
INC, DEC etc and logical operations like AND, OR , NOT, XOR etc.
On-chip Memories
In order to have a faster execution of the DSP functions, it is desirable to have some memory located on chip.
As dedicated buses are used to access the memory, on chip memories are faster. Speed and size are the two key
parameters to be considered with respect to the on-chip memories.
Speed:
On-chip memories should match the speeds of the ALU operations in order to maintain the single cycle
instruction execution of the DSP.
Size:
In a given area of the DSP chip, it is desirable to implement as many DSP functions as possible. Thus the area
occupied by the on-chip memory should be minimum so that there will be a scope for implementing more
number of DSP functions on-chip.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Circular Addressing Mode
While processing the data samples coming continuously in a sequential manner, circular buffers are used.
In a circular buffer the data samples are stored sequentially from the initial location till the buffer gets filled up.
Once the buffer gets filled up, the next data samples will get stored once again from the initial location. This
process can go forever as long as the data samples are processed in a rate faster than the incoming data rate.
4 Viva-Voce 2
Total 10
Date Sign
RESULT :
Thus, the architecture of digital signal processor was studied.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 9
AIM
To Study the various addressing modes of TMS320C67XX DSP processor.
THEORY:
Addressing Modes The TMS320C67XX DSP supports three types of addressing modes
that enable flexible access to data memory, to memory-mapped registers, to register bits, and to
I/O space.The absolute addressing mode allows you to reference a location by supplying all or
part of an address as a constant in an instruction.The direct addressing mode allows you to
reference a location using an address offset. The indirect addressing mode allows you to reference
a location using a pointer.Each addressing mode provides one or more types of operands. An
instruction that supports an addressing-mode operand has one of the following syntax elements
listed below. Baddr
When an instruction contains Baddr, that instruction can access one or two bits in an
accumulator (AC0–AC3), an auxiliary register (AR0–AR7), or a temporary register (T0–T3). Only
the register bit test/set/clear/complement instructions support Baddr. As you write one of these
instructions, replace Baddr with a compatible operand.
Cmem
When an instruction contains Cmem, that instruction can access a single word (16 bits)of
data from data memory. As you write the instruction, replace Cmem with a compatible operand.
Lmem
When an instruction contains Lmem, that instruction can access a long word (32 bits) of
data from data memory or from a memory-mapped registers. As you write the instruction, replace
Lmem with a compatible operand.
Smem
When an instruction contains Smem, that instruction can access a single word (16 bits) of
data from data memory, from I/O space, or from a memory-mapped register. As you write the
instruction, replace Smem with a compatible operand.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Xmem and Ymem
When an instruction contains Xmem and Ymem, that instruction can perform two
simultaneous 16-bit accesses to data memory. As you write the instruction, replace Xmem and
Ymem with compatible operands.
Absolute Addressing Modes k16 absolute
This mode uses the 7-bit register called DPH (high part of the extended data page register)
and a 16-bit unsigned constant to form a 23-bit data space address. This mode is used to access a
memory location or a memory-mapped register.
k23 absolute
This mode enables you to specify a full address as a 23-bit unsigned constant. This mode is
used to access a memory location or a memory-mapped register.
I/O absolute
This mode enables you to specify an I/O address as a 16-bit unsigned constant. This mode
is used to access a location in I/O space.
Direct Addressing Modes DP direct
This mode uses the main data page specified by DPH (high part of the extended data page
register) in conjunction with the data page register (DP).This mode is used to access a memory
location or a memory-mapped register.
SP direct
This mode uses the main data page specified by SPH (high part of the extended stack
pointers) in conjunction with the data stack pointer (SP). This mode is used to access stack values
in data memory.
Register-bit direct
This mode uses an offset to specify a bit address. This mode is used to access one register
bit or two adjacent register bits.
PDP direct
This mode uses the peripheral data page register (PDP) and an offset to specify an I/O
address. This mode is used to access a location in I/O space. The DP direct and SP direct
addressing modes are mutually exclusive. The mode selected depends on the CPL bit in status
register ST1_67: 0 DP direct addressing mode 1 SP direct addressing mode The register-bit and
PDP direct addressing modes are independent of the CPL bit.
.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Indirect Addressing Modes
AR indirect
This mode uses one of eight auxiliary registers (AR0–AR7) to point to data. The way the
CPU uses the auxiliary register to generate an address depends on whether you are accessing data
space (memory or memory-mapped registers), individual register bits, or I/O space.
Dual AR indirect
This mode uses the same address-generation process as the AR indirect addressing mode.
This mode is used with instructions that access two or more data-memory locations.
CDP indirect
This mode uses the coefficient data pointer (CDP) to point to data. The way the CPU uses
CDP to generate an address depends on whether you are accessing data space (memory or
memory-mapped registers), individual register bits, or I/O space.
Coefficient indirect
This mode uses the same address-generation process as the CDP indirect addressing mode.
This mode is available to support instructions that can access a coefficient in data memory at the
same time they access two other data-memory values using the dual AR indirect addressing
mode.
Circular Addressing
Circular addressing can be used with any of the indirect addressing modes. Each of the
eight auxiliary registers (AR0–AR7) and the coefficient data pointer (CDP) can be independently
configured to be linearly or circularly modified as they act as pointers to data or to register bits,
see Table 3−10. This configuration is done with a bit (ARnLC) in status register ST2_67. To
choose circular modification, set the bit. Each auxiliary register ARn has its own linear/circular
configuration bit in ST2_67: 0 Linear addressing 1 Circular addressing The CDPLC bit in status
register ST2_67 configures the DSP to use CDP for linear addressing or circular addressing: 0
Linear addressing 1 Circular addressing You can use the circular addressing instruction qualifier,
.CR, if you want every pointer used by the instruction to be modified circularly, just add .CR to
the end of the instruction mnemonic (for example, ADD.CR). The circular addressing instruction
qualifier overrides the linear/circular configuration in ST2_67.
DEPARTMENT OF ECE
ADDITION
INPUT
Data Memory :
A000h 0004h - 24
A001h 0004h - 21
OUTPUT:
Data Memory :
A002h 0008h - 45
SUBTRACTION
INPUT
Data Memory :
A000h 0004h - 24
A001h 0004h - 21
OUTPUT:
Data Memory :
A002h 0008h - 03
DEPARTMENT OF ECE
ADDITION:
INP1 .SET 0H INP2 .SET
1HOUT .SET 2H
.mmregs
.textSTART:
LD #140H,DPRSBX
CPL NOP
NOPNOPNOP
LD INP1,A ADD
INP2,ASTL A,OUT
HLT: B HLT
SUBTRACTION:
INP1 .SET 0H INP2 .SET
1HOUT .SET 2H
.mmregs
.textSTART:
LD #140H,DPRSBX
CPL NOP
NOPNOPNOP
LD INP1,A SUB
INP2,ASTL A,OUT
HLT: B HLT
4 Viva-Voce 2
Total 10
Date Sign
RESULT:
Thus, the various addressing mode of DSP processor TMS320C67XX was studied
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO:10
IMPLEMENTATION OF LINEAR CONVOLUTION
DATE
Aim:
To write a program to find the Linear Convolution of two sequences X(n) and H(n) using
TMS320C67XX.
Apparatus required:
1. System with TMS 320C67XX debugger software
2.TMS 320C67XX Kit.
3.Code Composer Studio 3.3v
Algorithm:
Linear convolution :
1. Start the program.
2. Enter the length of the sequences.
3. Check if the length of both sequences are equal.
4. Find linear convolution.
Program:
Linear Convolution :
#include<fastmath67x.h>
#include<math.h>
void main()
{
int *Xn,*Hn,*Output;
int *XnLength,*HnLength;
int i,k,n,l,m;
Xn=(int *)0x80010000; //input x(n)
Hn=(int *)0x80011000; //input h(n)
XnLength=(int *)0x80012000; //x(n) length
HnLength=(int *)0x80012004; //h(n) length
Output=(int *)0x80013000; // output address
DEPARTMENT OF ECE
OUTPUT:
Linear convolution
DEPARTMENT OF ECE
MAX MARKS
PREPARATION 2
VIVA-VOCE 2
TOTAL 10
DATE SIGN
RESULT:
Thus a program of the Linear Convolution of two sequences X(n) and H(n) using TMS320C67XX
was performed and output was verified.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EX:NO: 11 WAVEFORM GENERATION
DATE:
Aim:
To write the programs to generate various waveforms using TMS320C67XX debugger.
Apparatus required:
1. System with TMS 320C67XX driver software
2.TMS 320C67XX Kit.
3.Code Composer Studio 3.3v
4.CRO
5.Function Generator
Algorithm:
wave generation:
2. Open Code Composer Studio, make sure the DSP kit is turned on.
3. Load program using ‘File load_program. Which is saved in project file
4. Connect CRO and Function generator with kit.
5. Take the readings and draw the graph.
Program:
Sine wave generation:
#include
"VSK_6748.h"
#include <math.h>
#define SPIFLASH_SPI
(SPI1
) #define SPIFLASH_SPI0
(SPI0
)
#define PI
3.14; int
main(void)
{
int count; // declare
variables int nSamp;
int fi=1000; //input frequency
short *sin_out,val;
const float fSamp = 100000.0; //sampling
frequency float tSamp;
double ang;
spi_regs_t
*spi=SPIFLASH_SPI0; spi_regs_t
*spi1=SPIFLASH_SPI; uint32_t
spi_data1 = spi->SPIDAT1;
sin_out = (short *)0x80001000; // output buffer
DEPARTMENT OF ECE
DEPARTMENT OF ECE
nSamp = fSamp / fi; //no. of
samples tSamp = 1 / fSamp; // sampling
time
}
USTIMER_init(); // timer init
Spi_inti(); // spi init
while(1)
short Count,Out,Val;
short *sawtoothOut;
spi_regs_t *spi=SPIFLASH_SPI0;
spi_regs_t *spi1=SPIFLASH_SPI;
uint32_t spi_data1 = spi->SPIDAT1;
Out = 0;
for (Count = 0; Count < 4096; Count++)
{
*(sawtoothOut + Out) = Count;
Out++;
}
Spi_inti();
while(1) {
for(Count = 0; Count < 4096; Count++)
DEPARTMENT OF ECE
DEPARTMENT OF ECE
{
Val = *(sawtoothOut + Count) ;
#include "VSK_6748.h"
#include <math.h>
#define SPIFLASH_SPI (SPI1)
#define SPIFLASH_SPI0 (SPI0)
int main(void)
{
uint32_t j,k;
spi_regs_t *spi=SPIFLASH_SPI0;
spi_regs_t *spi1=SPIFLASH_SPI;
while(1) {
// copy the tmp reg to the real thing.
spi1->SPIDAT1 = 0x0fff | 0x1000;//_data1;
#include "VSK_6748.h"
#include <math.h>
#define SPIFLASH_SPI (SPI1)
#define SPIFLASH_SPI0 (SPI0)
int main(void)
{
short Count,Out,Val;
short *TriangularOut;
spi_regs_t *spi=SPIFLASH_SPI0;
spi_regs_t *spi1=SPIFLASH_SPI;
DEPARTMENT OF ECE
DEPARTMENT OF ECE
uint32_t spi_data1 = spi->SPIDAT1;
TriangularOut = (short *)0x80010000;
Out = 0;
for (Count = 0; Count < 4096; Count++)
{
*(TriangularOut + Out) = Count;
Out++;
}
Out = 4095;
for (Count = 4095; Count >= 0; Count--)
{
*(TriangularOut + Out) = Count;
Out++;
}
USTIMER_init();
Spi_inti();
while(1)
{
for(Count = 0; Count < 8192; Count++)
{
Val = *(TriangularOut + Count) ;
spi1->SPIDAT1 = Val | 0x1000 ; } }}
DEPARTMENT OF ECE
DEPARTMENT OF ECE
MAX MARKS
PREPARATION 2
VIVA-VOCE 2
TOTAL 10
DATE SIGN
RESULT:
Thus the programs executed for various waveforms using TMS320C67XX debugger.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
EXP NO: 12
Aim:
Apparatus required:
Algorithm:
1. Open 67XX debugger software, make sure the DSP kit is turned on.
2. Create new project save
3. Go to file create new C file.
4. Type the program
5. Add files-program file, linker command file and header file.
6. Build the project
7. Go to file and Load the program.
8. Set input waveform using CRO and Function generator
9. Connect CRO to DAC 1,FG to CH1,GND.
10. See the filter output.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
PROGRAM: (IIR Filters)
#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 cut off frequency");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); }
DEPARTMENT OF ECE
INPUT: (IIR Filters)
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF: 1
DEPARTMENT OF ECE
MAX MARKS
PREPARATION 2
VIVA-VOCE 2
TOTAL 10
DATE SIGN
RESULT:
Thus the program for IIR filter was implemented using TMS320C67XX kit and output was
verified.
DEPARTMENT OF ECE
DEPARTMENT OF ECE
Ex. No.: 13
Aim
To design an FIR filter using TMS 320C67XX processsor
Apparatus required:
1. Open 67XX debugger software, make sure the DSP kit is turned on.
2. Create new project save
3. Go to file create new C file.
4. Type the program
5. Add files-program file, linker command file and header file.
6. Build the project
7. Go to file and Load the program.
8 See the filter output.
DEPARTMENT OF ECE
OUTPUT: (FIR Filters)
DEPARTMENT OF ECE
DEPARTMENT OF ECE
MARK ALLOCATION MAX MARKS
MARKS AWARDED
PREPARATION 2
VIVA-VOCE 2
TOTAL 10
DATE SIGN
RESULT:
Thus the program for FIR filter was implemented using TMS320C67XX kit and output was
verified.
DEPARTMENT OF ECE