Professional Documents
Culture Documents
Ubm1512 DSP Lab Manual
Ubm1512 DSP Lab Manual
Ubm1512 DSP Lab Manual
(UBM1512)
III YEAR BME (VI SEMESTER)
PREPARED
BY
M.DHANALAKSHMI
ASSISTANT PROFESSOR
AIM:
APPARATUS REQUIRED:
MATLAB Software
ALGORITHM:
1. For the discrete signals, like the unit impulse waveform, specify the time scale and plot
the signal
2. For the continuous signals, the frequency, amplitude and the time scale and other
parameters are specified and these waveforms are plotted.
3. For each waveform, add appropriate “title”, and label x-axis as “time” and the y-axis as
“amplitude”.
PROGRAM:
%Generation Of Signals
%Sine wave:
a=10;
f=1000;
t=0:0.000001:0.01;
s=a*sin(2*pi*f*t);
figure;
subplot(331);
plot(t,s);
title(‘sine wave’);
xlabel(‘time’);
ylabel(‘amplitude’);
%Cosine wave:
a=10;
f=1000;
t=0:0.00001:0.01;
u=a*cos(2*pi*f*t);
subplot(332);
plot(t,u);
title(‘cosine wave’);
xlabel(‘time’);
ylabel(‘amplitude’);
%square wave
f=1000;
t=0:0.01:0.1;
a=10;
y=a*square(2*pi*f*t);
subplot(3,3,8);
plot(t,y);
title(“square wave”);
x label(“time”);
y label (“amplitude”);
%Sinc function
t=linspace(-10,10);
y=sinc(t);
subplot(3,3,9);
plot(t,y);
title(“sine wave”);
x label(“time”);
y label (“amplitude”);
OUTPUT:
RESULT:
Thus a MATLAB program was coded to generate the following signals:
1.Sine wave
2.Cosine wave
3.Rising exponential
4.Decreasing exponential
5.Square wave
6.Sinc wave
7.Unit step
8.Unit ramp
9.Unit impulse, and the outputs were verified.
EXPT NO:2
DATE:
LINEAR AND CIRCULAR CONVOLUTION
AIM:
To write a MATLAB program to perform linear and circular convolution.
APPARATUS REQUIRED:
Matlab software.
ALGORITHM :
Linear convolution :
1. Get the first input sequence x(n) using input function and second inpt sequence h(n) using
input function.
2. The length of each sequence is checked and the number of terms in the output sequence is
(N1+N2-1).
3. Zeros are added in a particular sequence to make the 2 sequences equal.
4. The ‘for’ loop is used for folding, shifting and multiplication of 2 sequences.
5. The output sequence is displayed using ‘disp’ function.
Circular convolution:
1. Obtain the 2 input sequences using input function.
2. The length of sequences must be same, or else zero padding is done to sequence whose
length is less, to equalise.
3. The ‘for’ loop is used for keeping one stationary and other sequence is shifted and
multiplied.
4. The output sequence is displayed using ‘disp’ function.
PROGRAM:
%Linear convolution
COMMAND WINDOW:
OUTPUT:
%Circular Convolution
COMMAND WINDOW:
RESULT:
Thus linear and circular convolution has been performed for the given sequences and
output has been verified using MATLAB.
EXPT NO:3
DATE:
AUTO CORRELATION AND CROSS CORRELATION
AIM:
To generate the auto correlation and cross correlation of periodic and aperiodic signals.
APPARATUS REQUIRED:
Matlab software.
ALGORITHM :
PROGRAM:
%Correlation
y=xcorr(x);
subplot(442);
plot(y);
axis tight;
title('autocorrelation of periodic signal');
xlabel('time');
ylabel('amplitude');
y=xcorr(x);
subplot(446);
plot(y);
axis tight;
title ('autocorrelation of aperiodic signal');
xlabel('time');
ylabel('amplitude');
y=randn(1,length(x-1));
subplot(4,4,10);
plot(y);
axis tight;
title('noise');
xlabel('time');
ylabel('amplitude');
z=x+y;
subplot(4,4,11);
plot(z);
axis tight;
title('added periodic and noise');
xlabel('time');
ylabel('amplitude');
xz=xcorr(z);
subplot(4,4,12);
plot(xz);
axis tight;
title('autocorrelation of periodic signal with noise');
xlabel('time');
ylabel('amplitude');
t=0:.01:100;
f=600;
fs=1500;
y=cos(2*pi*(f/fs)*t);
subplot(4,4,14);
plot(y);
axis tight;
title('periodic signal cosine');
xlabel('time');
ylabel('amplitude');
z=xcorr(x,y);
subplot(4,4,15);
plot(z);
axis tight;
title('cross correlation of two periodic signal');
xlabel('time');
ylabel('amplitude');
OUTPUT:
RESULT:
Thus auto-correlation and cross-correlation has been executed and output was verified
using MATLAB.
EXPT NO:4
DATE:
DISCRETE FOURIER TRANSFORM
AIM:
To perform discrete fourier transform and inverse fourier transform using decimation in time and
frequency algorithm.
APPARATUS REQUIRED:
MATLAB software
ALGORITHM:
1. Accept the sequence from the command window.
2. Find the length of the sequence, ‘n’.
3. Zero padding is done if ‘a’ is not equal to ‘n’.
4. Divide the sequence into two sets.
5. Assume weighting factor to be W.
6. Radix butterfly structure is used to obtain the data points.
7. Bit reversal should be done for the given sequence in the case of DIT and it should be
done after the butterfly structure in the case of DIF.
8. The values of WNnk are obtained by initialising ‘for’ loop for the corresponding radix
butterfly structures.
PROGRAM:
%DIT-FFT
x=input('enter the sequence');
N=input('enter the length of the sequence');
a=length(x);
if a<N
X=[x,zeros(1,(N-a))];
else
end
x=bitrevorder(x);
w=1;
div=N/2;
for st=1:3
n=1;
for r=1:div
k=0;
for j=1:w
y(n)=x(n)+(x(n+w)*exp(-((2*pi*i*k)/(N/div))));
k=k+1;
n=n+1;
end
for j=1:w
y(n)=x(n)*exp(-((2*pi*i*k)/(N/div)))+x(n-w);
]k=k+1;
n=n+1;
end
end
x=y;
w=w*2;
div=div/2;
end
disp(x);
subplot(311);
stem(real(x));
title('dft');
z=conj(x);
z=bitrevorder(z);
w=1;
div=N/2;
for st=1:3
n=1;
for r=1:div
k=0;
for j=1:w
a(n)=z(n)+z(n+w)*exp(-((2*pi*i*k)/(N/div)));
k=k+1;
n=n+1;
end
for j=1:w
a(n)=z(n)*exp(-((2*pi*i*k)/(N/div)))+z(n-w);
k=k+1;
n=n+1;
end
end
z=a;
w=w*2;
div=div/2;
end
%a=bitrevorder(z);
disp(z);
subplot(312);
c=abs(z);
stem(c/N);
title('idft');
%mag resp
fs=1000;
for i=1:512
freq(i)=((i/512)*fs/2);
end
y1=fft(x,1024);
y2=abs(y1);
subplot(313);
plot(freq,y2(1:512));
xlabel('freq');
ylabel('mag');
title('spectrum');
COMMAND WINDOW:
OUTPUT:
%DIF-FFT
%mag resp
fs=1000;
for i=1:512
freq(i)=((i/512)*fs/2);
end
y1=fft(x,1024);
y2=abs(y1);
subplot(313);
plot(freq,y2(1:512));
xlabel('freq');
ylabel('mag');
title('spectrum');
COMMAND WINDOW:
OUTPUT:
RESULT:
The code for DFT and IDFT using DIT and DIF was written and executed for the given
sequence and the output was verified.
EXPT NO.:5
DATE:
APPARATUS REQUIRED:
Matlab software.
ALGORITHM:
1. Open MATLAB m- file and type in the source code for the filter design.
2. Get the inputs from the user which includes pass band ,stop band , N values , cut off frequency
and sampling frequency.
3. According to the required filter for example- low pass filter , try using all windows and their
equations.
4. Similarly try designing for high pass filter, band pass filter and band stop filter units with
similar window functions.
5. Display the normal ideal response of each filter and their response for the given input signal
frequencies.
PROGRAM:
%rectangular
w1=rectwin(N)
hn=hd.*w1'
subplot(455);
plot(hn);
xlabel('samples');
ylabel('amp');
title('periodic convolution');
h=freqz(hn,1,N);
subplot(456);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(457);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(458);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hanning
w2=hanning(N)
hn=hd.*w2'
subplot(459);
plot(hn);
xlabel('samples');
ylabel('amp');
title('periodic convolution');
h=freqz(hn,1,N);
subplot(4,5,10);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,11);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,12);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hamming
w3=hamming(N)
hn=hd.*w3'
subplot(4,5,13);
plot(hn);
xlabel('samples');
ylabel('amp');
title('periodic convolution');
h=freqz(hn,1,N);
subplot(4,5,14);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,15);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,16);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
COMMAND WINDOW:
OUTPUT:
PROGRAM:
%rectangular
w1=rectwin(N)
hn=hd.*w1'
subplot(455);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(456);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(457);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(458);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hanning
w2=hanning(N)
hn=hd.*w2'
subplot(459);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,10);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,11);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,12);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hamming
w3=hamming(N)
hn=hd.*w3'
subplot(4,5,13);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,14);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,15);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,16);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
COMMAND WINDOW:
OUTPUT:
PROGRAM:
%rectangular
w1=rectwin(N)
hn=hd.*w1'
subplot(455);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(456);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(457);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(458);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hanning
w2=hanning(N)
hn=hd.*w2'
subplot(459);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,10);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,11);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,12);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hamming
w3=hamming(N)
hn=hd.*w3'
subplot(4,5,13);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,14);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,15);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,16);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
COMMAND WINDOW:
OUTPUT:
PROGRAM:
%rectangular
w1=rectwin(N)
hn=hd.*w1'
subplot(455);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(456);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(457);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(458);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hanning
w2=hanning(N)
hn=hd.*w2'
subplot(459);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,10);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,11);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,12);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
%hamming
w3=hamming(N)
hn=hd.*w3'
subplot(4,5,13);
plot(hn);
xlabel('samples');
ylabel('amp');
title('convolved signal');
h=freqz(hn,1,N);
subplot(4,5,14);
plot(abs(h));
xlabel('samples');
ylabel('amp');
title('magnitude response of window');
y=conv(c,hn);
subplot(4,5,15);
plot(y);
xlabel('samples');
ylabel('amp');
title('output signal');
y1=abs(fft(y,1024));
subplot(4,5,16);
plot(freq,y1(1:512));
xlabel('freq');
ylabel('amp');
title('spectrum of output signal');
COMMAND WINDOW:
OUTPUT:
RESULT:
Thus FIR filters were designed using windows for low pass filter, high pass filter, band
pass filter and band stop filter and also the responses of the filters were analysed.
EXPT NO:6
DATE:
IIR FILTER DESIGN
AIM:
To generate a MATLAB code for the infinite impulse response (IIR) filter design using
Butterwoth and Chebyshev filters.
APPARATUS REQUIRED:
Matlab software.
ALGORITHM:
1. Open MATLAB m- file and type in the source code for the filter design.
2. Get the inputs from the user which includes pass band ,stop band , N values , cut off frequency
and sampling frequency.
3. According to the required filter for example-Chebyshev and Butterworth low pass filter.
4. Similarly try designing for high pass filter, band pass filter and band stop filter units with
similar filter designs.
5. Display the normal ideal response of each filter and their response for the given input signal
frequencies.
PROGRAM:
%Lowpass filter
clc;
clear all;
close all;
f1=input('Enter the input frequency for the first signal =');
f2=input('Enter the input frequency for the second signal =');
fs=input('Enter the sampling frequency =');
fc=input('Enter the cutoff frequency =');
t=0:300;
c1=sin(2*pi*t*(f1/fs));
c2=sin(2*pi*t*(f2/fs));
c=c1+c2;
subplot(221);
plot(t,c);
xlabel('time');
ylabel('amplitude');
title('input signal');
f=abs(fft(c,1024));
for i=1:512
freq(i)=(i/1024)*fs;
end
subplot(222);
plot(freq,f(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of input signal');
%lpf butterworth
w=0:.001:pi;
[Bl1,Al1]=butter(5,((2*fc)/fs));
p3=freqz(Bl1,Al1,w);
figure;
subplot(221);
plot((w/pi),abs(p3));
title('butterworth lpf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot((w/pi),phase(p3));
title('butterworth lpf phase response');
xlabel('normalized freq');
ylabel('phase');
l=filter(Bl1,Al1,c);
l1=abs(fft(l,1024));
subplot(223);
plot(freq,l1(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of lpf output through butterworth');
a=filter(BL,AL,c);
a1=abs(fft(a,1024));
subplot(223);
plot(freq,a1(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of lpf output through chebyshev type 1');
b=filter(BL2,AL2,c);
b1=abs(fft(b,1024));
subplot(223);
plot(freq,b1(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of lpf output through chebyshev type 2');
OUTPUT:
Input data:
Input:
Butterworth filter:
Chebyshev filter – type 1:
%hpf butterworth
w=0:.001:pi;
[Bl1,Al1]=butter(5,((2*fc)/fs),'high');
p3=freqz(Bl1,Al1,w);
figure;
subplot(221);
plot((w/pi),abs(p3));
title('butterworth hpf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot((w/pi),phase(p3));
title('butterworth hpf phase response');
xlabel('normalized freq');
ylabel('phase');
l=filter(Bl1,Al1,c);
l1=abs(fft(l,1024));
subplot(223);
plot(freq,l1(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of hpf output through butterworth');
a=filter(BL,AL,c);
a1=abs(fft(a,1024));
subplot(223);
plot(freq,a1(1:512));
xlabel('freq');
ylabel('amplitude');
title('fft of hpf output through chebyshev type 1');
OUTPUT:
Input data:
Input:
Butterworth filter:
Chebyshev – type 1:
Chebyshev – type 2:
PROGRAM:
%Bandpass filter:
clc;
clear all;
close all;
fp1=3000;
fs1=2000;
fp2=4000;
fs2=5000;
fsamp=11000;
rp=3;
rs=45;
wp1=2*fp1/fsamp;
wp2=2*fp2/fsamp;
ws1=2*fs1/fsamp;
ws2=2*fs2/fsamp;
wp=[wp1 wp2];
ws=[ws1 ws2];
t=0:1/fsamp:0.01;
x=sin(2*pi*1000*t)+sin(2*pi*3000*t)+sin(2*pi*5000*t);
%butterworth
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn);
h=freqz(b,a,512);
ha=20*log10(abs(h(1:512)));
hp=20*log10(phase(h(1:512)));
y=filter(b,a,x);
figure;
subplot(211);
plot(t,x);
xlabel('time');
ylabel('amplitude');
title('input signal');
for i=1:1024
freq(i)=(i/1024)*fsamp;
end
xf=(fft(x,1024));
subplot(212);
plot(freq(1:512),abs(xf(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of input signal');
figure;
subplot(221);
plot(freq(1:512),ha(1:512));
title('butterworth bpf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp(1:512));
title('butterworth bpf phase response');
xlabel('normalized freq');
ylabel('phase');
yf=(fft(y,1024));
subplot(223);
plot(freq(1:512),abs(yf(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bpf output through butterworth');
%cheby1
[n1,wn1]=cheb1ord(wp,ws,rp,rs);
[b1,a1]=cheby1(n1,rp,wn1);
h1=freqz(b1,a1,512);
ha1=20*log10(abs(h1(1:512)));
hp1=20*log10(phase(h1(1:512)));
y1=filter(b1,a1,x);
for i=1:512
freq(i)=(i/1024)*fsamp;
end
figure;
subplot(221);
plot(freq(1:512),ha1(1:512));
title('chebyshev type 1 bpf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp1(1:512));
title('chebyshev type 1 bpf phase response');
xlabel('normalized freq');
ylabel('phase');
yf1=(fft(y1,1024));
subplot(223);
plot(freq(1:512),abs(yf1(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bpf output through chebyshev type 1');
%cheby2
[n2,wn2]=cheb2ord(wp,ws,rp,rs);
[b2,a2]=cheby2(n2,rp,wn2);
h2=freqz(b2,a2,512);
ha2=20*log10(abs(h2(1:512)));
hp2=20*log10(phase(h2(1:512)));
y2=filter(b2,a2,x);
for i=1:512
freq(i)=(i/1024)*fsamp;
end
figure;
subplot(221);
plot(freq(1:512),ha2(1:512));
title('chebyshev type 2 bpf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp2(1:512));
title('chebyshev type 2 bpf phase response');
xlabel('normalized freq');
ylabel('phase');
yf1=(fft(y2,1024));
subplot(223);
plot(freq(1:512),abs(yf1(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bpf output through chebyshev type 2');
OUTPUT:
Input:
Butterworth filter:
PROGRAM:
%Bandstop filter
clc;
clear all;
close all;
fp1=2000;
fs1=3000;
fp2=5000;
fs2=4000;
fsamp=11000;
rp=3;
rs=45;
wp1=2*fp1/fsamp;
wp2=2*fp2/fsamp;
ws1=2*fs1/fsamp;
ws2=2*fs2/fsamp;
wp=[wp1 wp2];
ws=[ws1 ws2];
t=0:1/fsamp:0.01;
x=sin(2*pi*1000*t)+sin(2*pi*3000*t)+sin(2*pi*5000*t);
%butterworth
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'stop');
h=freqz(b,a,512);
ha=20*log10(abs(h(1:512)));
hp=20*log10(phase(h(1:512)));
y=filter(b,a,x);
figure;
subplot(211);
plot(t,x);
xlabel('time');
ylabel('amplitude');
title('input signal');
for i=1:1024
freq(i)=(i/1024)*fsamp;
end
xf=(fft(x,1024));
subplot(212);
plot(freq(1:512),abs(xf(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of input signal');
figure;
subplot(221);
plot(freq(1:512),ha(1:512));
title('butterworth bsf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp(1:512));
title('butterworth bsf phase response');
xlabel('normalized freq');
ylabel('phase');
yf=(fft(y,1024));
subplot(223);
plot(freq(1:512),abs(yf(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bsf output through butterworth');
%cheby1
[n1,wn1]=cheb1ord(wp,ws,rp,rs);
[b1,a1]=cheby1(n1,rp,wn1,'stop');
h1=freqz(b1,a1,512);
ha1=20*log10(abs(h1(1:512)));
hp1=20*log10(phase(h1(1:512)));
y1=filter(b1,a1,x);
for i=1:512
freq(i)=(i/1024)*fsamp;
end
figure;
subplot(221);
plot(freq(1:512),ha1(1:512));
title('chebyshev type 1 bsf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp1(1:512));
title('chebyshev type 1 bsf phase response');
xlabel('normalized freq');
ylabel('phase');
yf1=(fft(y1,1024));
subplot(223);
plot(freq(1:512),abs(yf1(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bsf output through chebyshev type 1');
%cheby2
[n2,wn2]=cheb2ord(wp,ws,rp,rs);
[b2,a2]=cheby2(n2,rp,wn2,'stop');
h2=freqz(b2,a2,512);
ha2=20*log10(abs(h2(1:512)));
hp2=20*log10(phase(h2(1:512)));
y2=filter(b2,a2,x);
for i=1:512
freq(i)=(i/1024)*fsamp;
end
figure;
subplot(221);
plot(freq(1:512),ha2(1:512));
title('chebyshev type 2 bsf magnitude response');
xlabel('normalized freq');
ylabel('amplitude');
subplot(222);
plot(freq(1:512),hp2(1:512));
title('chebyshev type 2 bsf phase response');
xlabel('normalized freq');
ylabel('phase');
yf1=(fft(y2,1024));
subplot(223);
plot(freq(1:512),abs(yf1(1:512)));
xlabel('freq');
ylabel('amplitude');
title('fft of bsf output through chebyshev type 2');
OUTPUT:
Input:
Butterworth filter:
APPARATUS REQUIRED:
Matlab software.
ALGORITHM:
1. Open MATLAB m- file and type in the source code for ECG generation.
2. Import the required data from the data file and run the code.
3. ECG signal will be generated and the outputs will be displayed in a separate window.
PROGRAM CODE:
close all;clear;clc;
sig=load('ecg_60hz_200.dat');
N=length(sig);
fs=200;
t=[0:N-1]/fs;
figure(1);subplot(4,2,1);plot(sig)
title('Original Signal')
%%
% Low Pass Filter
b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
a=[1 -2 1];
sigL=filter(b,a,sig);
subplot(4,2,3);plot(sigL)
title('Low Pass Filter')
subplot(4,2,4);zplane(b,a)
%%
% High Pass Filter
b=[-1/32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1/32];
a=[1 -1];
sigH=filter(b,a,sigL);
subplot(4,2,5);plot(sigH)
title('High Pass Filter')
subplot(4,2,6);zplane(b,a)
%%
% Derivative Base Filter
OUTPUT:
RESULT:
APPARATUS REQUIRED:
Matlab software.
ALGORITHM:
4. Open MATLAB m- file and type in the source code for EEG generation.
5. Import the required data from the data file and run the code.
6. ECG signal will be generated and the outputs will be displayed in a separate window.
PROGRAM CODE:
clc;
clear;
clear all;
fs = 512;
T = 1/fs;
ls = size(EEGsig); N = length(EEGsig);
t = [0:N-1]/fs;
fx = fs*(0:N-2)/N;
x=EEGsig;
y = fft(x);
plot(f,power)
xlabel('Frequency')
ylabel('Power')
figure();
grid on;
hold on;
plot(EEGsig);
ylabel('Amplitude (microvolt)');
xlabel('Time (s)');
title('EEG Signal');
OUTPUT:
RESULT:
ARCHITECTURE:
FUNCTIONAL UNIT:
MEMORY SYSTEM:
The memory system of the TMS320C671x series processor implements a modified Harvard
architecture, providing separate address spaces for instruction and data memory. The processor
uses a two-level cache-based architecture and has a powerful and diverse set of peripherals. The
Level 1 program cache (L1P) is a 4K-byte direct-mapped cache and Level 1 data cache (L1D) is
a 4K-byte 2-way set-associative cache. The Level 2 memory/cache (L2) consists of a 256K-byte
memory space that is shared between program and data space. 64K bytes of the 256K bytes in L2
memory can be configured as mapped memory, cache or combinations of the two. The remaining
192K bytes in L2 serve as mapped SRAM.
CONCLUSION:
There are many applications for which Digital Signal Processor becomes an ideal choice as they
provide the best possible combination of performance, power and cost. Most of the DSP
applications can be simplified into multiplications and additions, so the MAC formed is a main
functional unit in early DSP processors. The designers later incorporated more features like
pipelining, SIMD, VLIW etc, in the processors to deliver improved performance.
Power issues are gaining importance as DSP processors are incorporated in to handheld, mobile
and portable devices. This leads to development of an important class of DSP processors namely
fixed-point processors.
Based on the current trends seen in the DSP processor development we may predict that the
manufacturers will follow the path of general purpose processors. With new IC manufacturing
technologies available we may expect to see more on-chip peripherals and memory; and in fact
the system on chip may not be too far away.
SIMULATION MODE:
Step 1: Click on the CC Studio icon to open it.
Step 2: On the left part of the window, free the existing system configurations if any by selecting
Remove All.
Step 3: On the top part of the window, select the following
Family: C67XX
Platform: Simulator
Endian: Little
Step 4: From the list, select C67XX CPU cycle. Accurate simulate and give ‘ADD’.
Step 5: Select the icon of the simulator in the left window and click on save and exit.
Step 6: In the pop-up showing “Start CC Studio on exit” click ‘YES’.
Step 11:
I. Give the folder path under ‘Location’.
II. Give the ‘Project Name’.
III. Under ‘target’, select TMS 320C67CC.
Step 12: Three files are to be created:
Configuration, Linker Command and source files
Step 13: Creating configuration file:
MAC OPERATION
AIM:
To perform MAC operation using Code Composer Studio.
APPARATUS REQUIRED:
VMWare software
CC Studio.
THEORY :
Multiple-Accumulate (MAC) operation is the most often used operation in DSP. The processor
has specialised hardware to perform single cycle multiplication. An accumulator register is
included in DSP architecture. DSP processor instruction set includes an explicit MAC
instruction. Mac instruction distinguishes early DSP processor and general purpose processor(
GPP).
ALGORITHM:
1. Perform initial steps of CCS.
2. Type in the MAC program.
3. Rebuild all program.
4. Files to be added:
i. C: CCS → tutorial → dsk6713 → hello1 → hello → cmd
ii. C: C6750 → cgtools → lib → rts6750.lib
5. Run the program.
6. Give necessary inputs.
PROGRAM:
% mac operation
//dotpfunc.c Optimized dot product function
intdotpfunc(const short *a, const short *b, intncount)
{
int sum = 0;
inti;
_nassert((int)(a)%4 == 0);
_nassert((int)(b)%4 == 0);
_nassert((int)(ncount)%4 == 0);
for ( i = 0; i<ncount; i++)
{
sum += (a[i] * b[i]); //sum of products
}
return (sum); //return sum as result
}
// header file:
/*#define x_array
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,
67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,
98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120
,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,
143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,1
65,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,18
7,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209
,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,
232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,2
54,255,256
/*#define y_array
256,255,254,253,252,251,250,249,248,247,246,245,244,243,242,241,240,239,238,237,236,235,2
34,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,214,213,21
2,211,210,209,208,207,206,205,204,203,202,201,200,199,198,197,196,195,194,193,192,191,190
,189,188,187,186,185,184,183,182,181,180,179,178,177,176,175,174,173,172,171,170,169,168,
167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151,150,149,148,147,146,1
45,144,143,142,141,140,139,138,137,136,135,134,133,132,131,130,129,128,127,126,125,124,12
3,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101
,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,7
0,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,3
9,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7
,6,5,4,3,2,1*/
#define x_array 1,2,3,4
#define y_array 1,2,3,4
OUTPUT:
RESULT:
Thus the MAC operation has been performed using CC Studio and outputs have been
verified.
EXPT NO:3
DATE:
GENERATION OF SIGNALS
AIM:
APPARATUS REQUIRED:
VMWare software
CC Studio.
ALGORITHM:
1. Perform initial steps of CCS.
2. Type in the sine wave generation program.
3. Rebuild all program.
4. Files to be added:
i. C: CCS → tutorial → dsk6713 → hello1 → hello → cmd
ii. C: C6750 → cgtools → lib → rts6750.lib
5. Compile, build and run the program.
6. Repeat the above process for ramp wave , square wave, triangular wave as well.
7. Record the output waves.
PROGRAM:
%Waveform generation
#include<stdio.h>
#include<math.h>
float a[500];
float b[500];
float c[500];
float d[500];
void main()
{
int i=0,j=0;
//sine wave
for(i=0;i<500;i++)
a[i]=sin(2*3.14*10000*i);
//square wave
for(i=0;i<500;){
for(j=0;j<10;j++) {
b[j]=1;
b[i]=b[j];
i++;
}
for(j=10;j<20;j++){
b[j]=-1;
b[i]=b[j];
i++;}
}
//ramp wave
for(i=0;i<200;){
for(j=0;j<10;j++){
c[j]=((2*j)-10);
c[i]=c[j];
i++;
}
}
//triangular wave
for(i=0;i<200;)
{
for(j=0;j<10;j++)
{
d[i]=((2*j)-10);
d[i]=d[j];
i++;
}
for(j=10;j<20;j++)
{
d[j]=(30-(2*j));
d[i]=d[j];
i++;
}
}
}
OUTPUT:
i) Triangular Wave:
AIM:
To perform linear and circular convolution using Code Composer Studio.
APPARATUS REQUIRED:
VMWare software
CC Studio.
ALGORITHM:
1. Perform initial steps of CCS.
2. Type in the convolution program.
3. Rebuild all program.
4. Files to be added:
i. C: CCS → tutorial → dsk6713 → hello1 → hello → cmd
ii. C: C6750 → cgtools → lib → rts6750.lib
5. Compile, build and run the program.
6. Give necessary sequences for circular convolution.
7. Go to view → Graph; type in the necessary values in the time/frequency graph
properties to view the graph.
PROGRAM:
%Linear convolution
#include<stdio.h>
int m=4;
int n=4;
inti=0,j;
int x[10]={1,2,3,4,0,0,0,0};
int h[10]={1,2,3,4,0,0,0,0};
int y[10];
main()
{
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
OUTPUT:
PROGRAM:
% circular convolution
#include<stdio.h>
intm,n,x[30],h[30],y[30],i,j, k,x2[30],a[30];
void main(){
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n"
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) {
if(m>n){
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
//Circular convolution
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
//circular shift
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
//Displaying output
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
OUTPUT:
RESULT:
Thus the linear and circular convolution is performed using Code Composer Studio for
the given sequences and the output has been verified.
EXPT NO:5
DATE:
APPARATUS REQUIRED:
1. VMWare software
2. CC Studio
THEORY:
The infinite impulse response of the IIR Filter is of an infinite duration.
Where,
y(n) – Impulse response of filter
x(n) – Input to the filter
akand bkare filter coefficients
The digital signal kit features the TMS320C6713 DSP, a 225 Mhz device delivering 1800 MIPS
and 1350 M flops.
PROCEDURE:
1. Start a new project. Create a new source file.
2. Go to new DSP/BIOS DSK6713 system MEMS and set no dynamic
heaps for memory.
3. Save the configuration.
4. Add files to project C6000 DSK6713 include dsk.aie23 and dsk6713 and
in lib dsk6713.
5. Go to add files to project and add the source file to the ‘ new project’ created under
‘my projects’.
PROGRAM:
%IIR filter
#include "Configuration1cfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/*float filter_Coeff[]={-0.0157524150924022,-0.0238685132826490,-
0.0181758635681563,1.02306744372008e-17, .0214805660350939, 0.0334159185957086
0.0262540251540036, -1.02306744372008e-17, -0.0337551751980046, -0.0556931976595143,
-0.0472572452772064, 1.02306744372008e-17, 0.0787620754620107, 0.167079592978543,
0.236286226386032, 0.262448010933082, 0.236286226386032, 0.167079592978543,
0.0787620754620107, 1.02306744372008e-17, -0.0472572452772064, -0.0556931976595143,
-0.0337551751980046, -1.02306744372008e-17, 0.0262540251540036, 0.0334159185957086,
0.0214805660350939, 1.02306744372008e-17, -0.0181758635681563,-0.0238685132826490,-
0.0157524150924022};*/
const signed intfilter_Coeff[]=
{
//12730,-12730,12730,2767,-18324,21137 /*HP 2500 */
//312,312,312,32767,-27943,24367 /*LP 800 */
1455,1455,1455,32767,-23140,21735 /* LP 2500 */
//9268,-9268,9268,32767,-7395,18367 /*HP 4000 */
//7215,-7215,7215,32767,5039,6171, /* HP 7000 */
};
DSK6713_AIC23_Config config={
0x0017,
0x0017,
0x00d8,
0x00d8,
0x0011,
0x0000,
0x0000,
0x0043,
0x0081,
0x0001
};
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
intl_input, r_input, l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec,3);
while(1) {
while (!DSK6713_AIC23_read(hCodec,&l_input));
while (!DSK6713_AIC23_read(hCodec,&r_input));
l_output = IIR_FILTER(&filter_Coeff,l_input);
r_output = l_output;
while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signedint IIR_FILTER(const signed int *h,signedint x1)
{
static signed int x[6]={0,0,0,0,0,0};
static signed int y[6]= {0,0,0,0,0,0};
int temp=0;
temp =(short int)x1;
x[0]=(signed int) temp;
temp = ( (int)h[0]*x[0]);
temp += ( (int)h[1]*x[1]);
temp += ( (int)h[1]*x[1]);
temp += ( (int)h[2]*x[2]);
temp -= ( (int)h[4]*y[1]);
temp -= ( (int)h[4]*y[1]);
temp -= ( (int)h[5]*y[2]);
temp>>=15;
if(temp>32767){
temp=32767;
}
else if (temp<-32767){
temp = -32767;
}
y[0]=temp;
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1]=x[0];
return (temp<<2);
}
TABULATION:
AIM:
To perform and design FIR lowpass ,highpass ,bandpass and bandstop filters using
TMS320C6713 DSP processor.
APPARATUS REQUIRED:
1. VMWare software
2. CC Studio
THEORY:
FIR have linear phase response. The transfer function is given by
It is a non feedback ,non recursive and a stable filter and can be realized with recursive and non
recursive structures.It is free of oscillations .
PROCEDURE:
7. Start a new project. Create a new source file.
8. Go to new DSP/BIOS DSK6713 system MEMS and set no dynamic
heaps for memory.
9. Save the configuration.
10. Add files to project C6000 DSK6713 include dsk.aie23 and dsk6713 and
in lib dsk6713.
11. Go to add files to project and add the source file to the ‘ new project’ created under
‘my projects’.
float b[]={-0.0089819,-0.017782,-0.02502,-0.029339,-0.029569,-0.024895,-0.01497,5.3894e-
018,0.019247,0.041491,0.065053,0.088016,0.10842,0.12447,0.13473,0.13825,0.13473,0.12447,
0.10842,0.088016,0.065053,0.041491,0.019247,5.3894e-018,-0.01497,-0.024895,-0.029569,-
0.029339,-0.02502,-0.017782,-0.0089819};
DSK6713_AIC23_Config config={\
void main(){
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input,r_input,l_output,r_output;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec,1);
while(1){
while(!DSK6713_AIC23_read(hCodec,&l_input));
while(!DSK6713_AIC23_read(hCodec,&r_input));
l_output = (Int16)FIR_FILTER(&b,l_input);
r_output = l_output;
while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signedint FIR_FILTER(float *h,signedint x)
{
inti=0;
signed long output =0;
in_buffer[0] = x;
for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];
for(i=0;i<32;i++)
output = output+ h[i]*in_buffer[i];
return(output);
}
TABULATION:
AIM:
To perform rounding off using code composer studio using simulation method.
APPARATUS REQUIRED:
1. VMWare software
2. CC Studio
ALGORITHM:
PROGRAM:
RESULT:
Thus, rounding off of a floating arithmetic was performed using code composer studio and
output was recorded.