DSP Lab Maual
DSP Lab Maual
DSP Lab Maual
LIST OF EXPERIMENTS
Academic Year: 2014 15 (II Sem)
Regulation
: R 09
Windows Xp
Constructor
Simulator
Software
Frequency content of y
Experiment No. 2
Windows Xp
Constructor
Simulator
Software
figure;
subplot(2,1,1);
plot(w/pi,abs(H));
xlabel('\omega /pi');ylabel('Magnitude');
title('Magnitude spectrum');
subplot(2,1,2);
plot(w/pi,angle(H));
xlabel('\omega /pi');ylabel('Phase(radians)');
title('Phase Spectrum');
INPUT & OUTPUT
type the numerator vector
type the denominator vector
number of frequency points
Graph for Real Part
Magnitude Spectrum
Phase Spectrum
Experiment No. 3
Windows Xp
Constructor
Simulator
Software
Output Sequence
:
Magnitude Plot
Phase Plot
Experiment No. 4
Windows Xp
Constructor
Simulator
Software
subplot(1,2,2);stem(real(X));
title('fft of i/p x(n) is:');
xlabel('Real axis --->');
ylabel('Imaginary axis -->');grid;
INPUT & OUTPUT
Enter the sequence:
Enter the length of FFT:
Fourier transformed signal
Experiment No. 5
Windows Xp
Constructor
Simulator
Software
MAT Lab program to implement low pass IIR filter for a given sequence
clc;
clear all;
close all;
disp('Enter the IIR filter design specifications:');
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[b,a]=butter(n,wn,'low','s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('Magnitude response of IIR filter is:');
Dept. of Electronics & Communication Engineering
Experiment No. 6
Windows Xp
Constructor
Simulator
Software
MAT Lab program to implement high pass IIR filter for a given sequence
clc;
clear all;
close all;
disp('Enter the IIR filter design specifications:');
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[b,a]=butter(n,wn,'high','s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('Magnitude response of IIR filter is:');
Dept. of Electronics & Communication Engineering
Experiment No. 7
Windows Xp
Constructor
Simulator
Software
MAT Lab program to implement low pass FIR filter for a given sequence
clc;
clear all;
close all;
rp=input('Enter passband ripple:');
rs=input('Enter the stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');
f=input('Enter sampling frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('Enter your choice of window function 1. Rectangular 2. Triangular
3.Kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('Kaiser window filter response');
end
%Low Pass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a)Normalized frequency-->');
INPUT & OUTPUTS
Enter passband ripple:
Enter the stopband ripple:
Enter passband frequency:
Enter stopband frequency:
Enter sampling frequency:
Enter your choice of window function 1. Rectangular 2. Triangular 3.Kaiser:
Rectangular window filter response
RESULT:
The frequency responses of Low pass FIR filter using Rectangular, Triangular &
Kaiser windows are plotted.
Dept. of Electronics & Communication Engineering
Experiment No. 8
Windows Xp
Constructor
Simulator
Software
MAT Lab program to implement high pass FIR filter for a given sequence
clc;
clear all;
close all;
rp=input('Enter passband ripple:');
rs=input('Enter the stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');
f=input('Enter sampling frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('Enter your choice of window function 1. Rectangular 2.
Triangular 3.Kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('Kaiser window filter response');
end
%High pass filer
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b)Normalized frequency-->');
INPUT & OUTPUTS
Enter passband ripple:
Enter the stopband ripple:
Enter passband frequency:
Enter stopband frequency:
Enter sampling frequency:
Enter your choice of window function 1. Rectangular 2. Triangular 3.Kaiser:
Rectangular Window Filter Response
RESULT:
The frequency responses of High pass FIR filter using Rectangular, Triangular &
Kaiser windows are plotted.
Experiment No. 9
Windows Xp
Constructor
Simulator
Software
echo off ;
end
echo on ;
u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal
%now lets filter the signal
[z,p] = butter(1,2*50/fs,'low');
filter_out = filter(50,[1 50],u); %this damn filter doesn't work!
subplot(2,1,1);
plot(t,u);
hold on;
plot(t,m,'r');
subplot(2,1,2);
plot(t,filter_out);
hold on;
plot(t,m,'r');
OUTPUT:
RESULT:
The Sinusoidal signal is filtered from a modulated signal using butter worth
lowpass filter.
Windows Xp
Constructor
Simulator
Software
ylabel('Xd(t)');
title('decimated output sequence');
subplot(3,1,3);
stem(t(1:100),interp);
grid;
xlabel('t');
ylabel('xi(t)');
title('Interpolated output sequence');
OUTPUT:
Plot of Input Sequence
Experiment No. 12
Windows Xp
Constructor
Simulator
Software
MAT Lab program to plot the impulse response of second order system.
clc;
clear all;
close all;
a = [-0.5572 -0.7814;0.7814 0];
b = [1 -1;0 2];
c = [1.9691 6.4493];
sys = ss(a,b,c,0);
impulse(sys);
INPUT & OUTPUTS
Experiment No. 13
Windows Xp
Constructor
Simulator
Software
C Program
#include "NCcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#define beta 1E-13
#define N 30
//rate of convergence
//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 */
Dept. of Electronics & Communication Engineering
\
\
};
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);
DSK6713_AIC23_setFreq(hCodec, 1);
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
*/
while (!DSK6713_AIC23_write(hCodec, r_output)); /* Send o/p to the right
channel*/
}
DSK6713_AIC23_closeCodec(hCodec); /* Close the codec */
}
//ISR
{
short i,output;
float yn=0, E=0, dplusn=0,desired,noise;
desired = l_input;
noise = r_input;
dplusn = (short)(desired + noise);
delay[0] = noise;
yn += (w[i] * delay[i]);
E = (desired + noise) - yn;
for (i = N-1; i >= 0; i--)
//desired+noise
{
w[i] = w[i] + beta*E*delay[i]; //update weights
Dept. of Electronics & Communication Engineering
delay[i] = delay[i-1];
Result:
Experiment No. 14
Windows Xp
Constructor
Simulator
Software
COMPLEX samples[PTS];
RTDX_CreateOutputChannel(ochan);
main()
{
for (i = 0 ; i<PTS ; i++)
{
w[i].real = cos(2*PI*i/512.0);
w[i].imag =-sin(2*PI*i/512.0);
}
comm_intr();
while(!RTDX_isOutputEnabled(&ochan))
puts("\n\n Waiting . . . ");
for(l=0;l<256;l++)
a[l]=cos(2*3.14*1500*l/8000);
for(k=0;k<5000;k++)
{
while (flag == 0) ;
flag = 0;
for (i = 0 ; i < PTS ; i++)
{ iobuffer1[i]=iobuffer[i]+a[i];
samples[i].real=h[i]*iobuffer1[i];
iobuffer1[i] = x1[i];
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0;
FFT(samples,PTS);
Dept. of Electronics & Communication Engineering
{
COMPLEX temp1,temp2;
int i,j,k;
int num_stages = 0;
int index, step;
i = 1;
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
step = 512/N;
{
k = N/2;
while (k <= j)
{
j = j - k;
Dept. of Electronics & Communication Engineering
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
Spectrogram_RTDX.m For spectrogram plot using RTDX with MATLAB
clc;
ccsboardinfo
%board info
cc=ccsdsp('boardnum',0);
reset(cc);
%reset board
visible(cc,1);
enable(cc.rtdx);
%enable RTDX
if ~isenabled(cc.rtdx);
error('RTDX is not enabled')
end
Dept. of Electronics & Communication Engineering
cc.rtdx.set('timeout',50);
open(cc,'spectrogram1.pjt');
load(cc,'./debug/spectrogram1.out');
run(cc);
%run program
configure(cc.rtdx,2048,1);
open(cc.rtdx,'ochan','r');
pause(3)
enable(cc.rtdx,'ochan');
isenabled(cc.rtdx,'ochan');
M = 256;
%window size
N = round(M/2);
B = 128;
fs = 8000;
%sampling rate
t=(1:B)*(M/fs);
f=((0:(M-1)/2)/(M-1))*fs;
set(gcf,'DoubleBuffer','on');
y = ones(N,B);
column = 1;
set(gca,'NextPlot','add');
axes_handle = get(gcf,'CurrentAxes');
set(get(axes_handle,'XLabel'),'String','Time (s)');
set(get(axes_handle,'YLabel'),'String','Frequency (Hz)');
set(get(axes_handle,'Title'),'String','\fontname{times}\bf Real-Time Spectrogram');
set(gca,'XLim', [0 4.096]);
set(gca,'YLim', [0 4000]);
set(gca,'XLimMode','manual');
Dept. of Electronics & Communication Engineering
set(gca,'YLimMode','manual');
for i = 1:32768
w=readmsg(cc.rtdx,'ochan','single');
w=double(w(1:N));
y(:, column) = w';
imagesc(t,f,dB(y));
%plot spectrogram
column = mod(column, B) + 1;
end
halt(cc);
%halt processor
close(cc.rtdx,'ochan');
%close channel
clear cc
%clear object
Experiment No. 15
Windows Xp
Constructor
Simulator
Software
MAT Lab program for generation of dual tone multiple frequency signals
fs = 4000;
dt = 1/fs;
frow = [697 770 852 941];
fcol = [1209 1336 1477];
ftone = [350 440];
fbusy = [480 620];
fring = [440 480];
Tkey = 0.25;
Ttone = 2;
Tring = [2 4];
Tbusy = [0.5 0.5];
task = 'go';
while strcmp(task,'end') == 0
task = input('task: ', 's');
Dept. of Electronics & Communication Engineering
switch task
case '1'
row = 1; col = 1;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '2'
row = 1; col = 2;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '3'
row = 1; col = 3;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '4'
row = 2; col = 1;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '5'
Dept. of Electronics & Communication Engineering
row = 2; col = 2;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '6'
row = 2; col = 3;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '7'
row = 3; col = 1;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '8'
row = 3; col = 2;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '9'
row = 3; col = 3;
t = 0:dt:Tkey;
Dept. of Electronics & Communication Engineering
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '*'
row = 4; col = 1;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '0'
row = 4; col = 2;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case '#'
row = 4; col = 3;
t = 0:dt:Tkey;
x = cos(2*pi*frow(row)*t) + cos(2*pi*fcol(col)*t);
soundsc(x, fs);
case 'tone'
t = 0:dt:Ttone;
x = cos(2*pi*ftone(1)*t) + cos(2*pi*ftone(2)*t);
soundsc(x, fs);
case 'ring'
Dept. of Electronics & Communication Engineering
ton = 0:dt:Tring(1);
toff = 0:dt:Tring(2);
xon = cos(2*pi*fring(1)*ton) + cos(2*pi*fring(2)*ton);
xoff = zeros(size(toff));
x = [xon xoff];
for k=1:2
sound(x, fs);
pause(Tring(1)+Tring(2));
end
case 'busy'
ton = 0:dt:Tbusy(1);
toff = 0:dt:Tbusy(2);
xon = cos(2*pi*fbusy(1)*ton) + cos(2*pi*fbusy(2)*ton);
xoff = zeros(size(toff));
x = [xon xoff];
for k=1:4
sound(x, fs);
pause(Tbusy(1)+Tbusy(2));
end
case 'end'
fprintf('\nthanks for playing! \n');
otherwise
Dept. of Electronics & Communication Engineering
fprintf('invalid task\n');
end
end
INPUT & OUTPUT
task: 1
task: 2
task: 3
task: 4
task: 5
task: 6
task: 7
task: 8
task: 9
task: 0
task: *
task: #
task: end