You are on page 1of 53

LABORATORY MANUAL

DIGITAL SIGNAL PROCESSING LAB


III B.Tech. ECE - II Sem (2014-15)

Department of Electronics & Communication Engineering

BALAJI INSTITUTE OF ENGINEERING & SCIENCES


Laknepally, Narsampet, Warangal

Dept. of Electronics & Communication Engineering

LIST OF EXPERIMENTS
Academic Year: 2014 15 (II Sem)

Name of the Lab : DIGITAL SIGNAL PROCESSING LAB


Class

: III B.Tech., ECE

Regulation

: R 09

The programs shall be implemented in software (Using MATLAB / Lab


view / C programming/ Equivalent) and hardware (Using TI / Analog
devices / Motorola / Equivalent DSP processors).
Note: - Minimum of 12 experiments has to be conducted.
1. Determination of Power Spectrum of a given signal(s).
2. To find frequency response of a given system given in (Transfer
Function/ Differential equation form).
3. To find DFT / IDFT of given DT signal
4. Implementation of FFT of given sequence
5. Implementation of LP IIR filter for a given sequence
6. Implementation of HP IIR filter for a given sequence
7. Implementation of LP FIR filter for a given sequence
8. Implementation of HP FIR filter for a given sequence
9. Generation of Sinusoidal signal through filtering
10.
Implementation of Decimation Process
11.
Implementation of Interpolation Process
12.
Impulse response of first order and second order systems.
13.
Noise removal: Add noise above 3 KHz and then remove,
interference suppression using 400 Hz tone.
14.
Audio application such as to plot a time and frequency
display of microphone plus a cosine using DSP. Read a .wav file
and match with their respective spectrograms.
15.
Generation of DTMF signals
16.
Generation of Sinusoidal waveform / signal based on
recursive difference equations
17.
Implementation of I/D sampling rate converters
Experiment No. 1
Dept. of Electronics & Communication Engineering

PROGRAM FOR DETERMINATION OF POWER SPECTRUM


OF A GIVEN SIGNAL
Aim: To determine the power spectrum of a given signal.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program for Power spectrum of a signal


t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
figure,plot(1000*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various
frequencies, is:
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
figure,plot(f,Pyy(1:257))
title('Frequency content of y');
xlabel('frequency (Hz)');
Signal Corrupted with Zero-Mean Random Noise
Dept. of Electronics & Communication Engineering

Frequency content of y

Result: The power spectrum of a given signal is determined

Dept. of Electronics & Communication Engineering

Experiment No. 2

PROGRAM TO FIND THE FREQUENCY RESPONSE


OF A GIVEN SYSTEM
Aim: To find the frequency response of a given system
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program for frequency response of a given system


num=input('type the numerator vector');
den=input('type the denominator vector');
N=input('number of frequency points');
w=0:pi/N:pi;
H=freqz(num,den,w);
figure;
subplot(2,1,1);plot(w/pi,real(H));
xlabel('\omega /pi');ylabel('Amplitude')
title('Real part');
subplot(2,1,2);
plot(w/pi,imag(H));
xlabel('\omega /pi');ylabel('Amplitude')
title('Imaginary part');
Dept. of Electronics & Communication Engineering

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

Dept. of Electronics & Communication Engineering

Graph for Imaginary Part

Magnitude Spectrum

Phase Spectrum

Result: Frequency response of a given system is plotted.


Dept. of Electronics & Communication Engineering

Experiment No. 3

PROGRAM TO FIND THE DISCRETE FOURIER TRANSFORM OF


A GIVEN SEQUENCE
Aim: To find the DFT of a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program for DFT of a given sequence


close all;
clear all;
N=input('Howmany point DFT do you want');
x2=input('Enter the sequence=');
n2=length(x2);
c=zeros(N);
x2=[x2 zeros(1,N-n2)];
for k=1:N
for n=1:N
w=exp(-2*pi*i*(k-1)*(n-1)/N);
%prev. step=>evaluating w-matrix
x(n)=w;
end
c(k,:)=w;
end
r=[c]*[x2']
%plotting magnitude and angle
subplot(2,1,1);
stem(abs(r));
Dept. of Electronics & Communication Engineering

title('DFT absolute value:');


subplot(2,1,2);
stem(angle(r));
title('DFT angle:');

INPUT & OUTPUT:


Enter the Sequence

Output Sequence

:
Magnitude Plot

Phase Plot

RESULT: DFT of a given sequence is determined.


Dept. of Electronics & Communication Engineering

Experiment No. 4

PROGRAM TO IMPLEMENT FAST FOURIER TRANSFORM


OF A GIVEN SEQUENCE
Aim: To implement FFT of a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program for FFT of a given sequence


clc;
clear all;
close all;
tic;
x=input('Enter the sequence:');
n=input('Enter the length of FFT:');
%compute fft
disp('Fourier transformed signal');
X=fft(x,n)
subplot(1,2,1);stem(x);
title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
Dept. of Electronics & Communication Engineering

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

Input Sequence Graph

Output Sequence Graph

RESULT: FFT of a given sequence is determined.


Dept. of Electronics & Communication Engineering

Experiment No. 5

PROGRAM TO IMPLEMENT LOW PASS IIR FILTER


FOR A GIVEN SEQUENCE
Aim: To implement low pass IIR filter for a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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

xlabel('(a) Normalized freq. -->');


ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('Phase response of IIR filter is:');
xlabel('(b)Normalized frequency -->');
ylabel('Phase in radians-->');

INPUT & OUTPUT:


Enter the IIR filter design specifications:
Enter the passband ripple:
Enter the stopband ripple:
Enter the passband frequency:
Enter the stopband frequency:
Enter the sampling frequency:

Magnitude Response of Low Pass IIR Filter

Dept. of Electronics & Communication Engineering

Phase Response of Low Pass IIR Filter

RESULT: Frequency response of the Low pass IIR filter is plotted.

Dept. of Electronics & Communication Engineering

Experiment No. 6

PROGRAM TO IMPLEMENT HIGH PASS IIR FILTER


FOR A GIVEN SEQUENCE
Aim: To implement high pass IIR filter for a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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

xlabel('(a) Normalized freq. -->');


ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('Phase response of IIR filter is:');
xlabel('(b)Normalized frequency -->');
ylabel('Phase in radians-->');

INPUT & OUTPUT


Enter the IIR filter design specifications:
Enter the passband ripple:
Enter the stopband ripple:
Enter the passband frequency:
Enter the stopband frequency:
Enter the sampling frequency:
Magnitude Response of High Pass IIR Filter

Dept. of Electronics & Communication Engineering

Phase Response of High Pass IIR Filter

RESULT: Frequency response of the high pass IIR filter is plotted.

Dept. of Electronics & Communication Engineering

Experiment No. 7

PROGRAM TO IMPLEMENT LOW PASS FIR FILTER


FOR A GIVEN SEQUENCE
Aim: To implement low pass FIR filter for a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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);

Dept. of Electronics & Communication Engineering

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);

Dept. of Electronics & Communication Engineering

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

Dept. of Electronics & Communication Engineering

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:
Triangular window filter response

Dept. of Electronics & Communication Engineering

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:
Kaiser 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

PROGRAM TO IMPLEMENT HIGH PASS FIR FILTER


FOR A GIVEN SEQUENCE
Aim: To implement high pass FIR filter for a given sequence.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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);

Dept. of Electronics & Communication Engineering

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);

Dept. of Electronics & Communication Engineering

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

Dept. of Electronics & Communication Engineering

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:

Triangular Window Filter Response

Dept. of Electronics & Communication Engineering

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:
Kaiser Window Filter Response

RESULT:

The frequency responses of High pass FIR filter using Rectangular, Triangular &
Kaiser windows are plotted.

Dept. of Electronics & Communication Engineering

Experiment No. 9

PROGRAM TO GENERATE A SINUSOIDAL SIGNAL THROUGH


FILTERING
Aim: To generate a sinusoidal signal through filtering.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program to generate a sinusoidal signal through filtering.


clc;
clear all;
close all;
echo on;
t0=.2; % signal duration
ts=0.001; % sampling interval
fc=250; % carrier frequency
fs=1/ts; % sampling frequency
t=[-t0/2:ts:t0/2]; % time vector
kf=100; % deviation constant
m=cos(2*pi*10*t); % the message signal
int_m(1)=0;
for i=1:length(t)-1 % integral of m
int_m(i+1)=int_m(i)+m(i)*ts;
Dept. of Electronics & Communication Engineering

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');

Dept. of Electronics & Communication Engineering

OUTPUT:

RESULT:

The Sinusoidal signal is filtered from a modulated signal using butter worth
lowpass filter.

Dept. of Electronics & Communication Engineering

Experiment No. 10,11

PROGRAM TO IMPLEMENT DECIMATION & INTERPOLATION


PROCESSES
Aim: To implement decimation & interpolation on a given signal.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

MAT Lab program to implement decimation & interpolation on a given signal


clc;
close all;
clear all;
t=0:0.001:0.5;
F=100;
X=2*sin(2*pi*F*t);
Xp=X(1:100);
de=decimate(Xp,2);
tp=2*t(1:50);
interp=interp(de,2);
subplot(3,1,1);
stem(t(1:100),X(1:100));
grid;
xlabel('t');
ylabel('X(t)');
title('Plot of input sequence');
subplot(3,1,2);
stem(tp,de);
grid;
xlabel('t');
Dept. of Electronics & Communication Engineering

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

Dept. of Electronics & Communication Engineering

Plot of Decimated Sequence

Plot of Interpolated Sequence

RESULT: Given signal is decimated & interpolated.

Dept. of Electronics & Communication Engineering

Experiment No. 12

PROGRAM TO PLOT THE IMPULSE RESPONSE OF


SECOND ORDER SYSTEM
Aim: To plot the impulse response of second order system .
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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

Dept. of Electronics & Communication Engineering

RESULT: The impulse response of second order system is plotted.

Dept. of Electronics & Communication Engineering

Experiment No. 13

PROGRAM FOR NOISE REMOVAL


Aim: To add noise above 3kHz and then remove interference suppression using 400 Hz
tone.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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

\
\

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;

//Initialize the adaptive FIR coeffs=0


//init buffer for weights
//init buffer for delay samples

while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec,&l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));

Dept. of Electronics & Communication Engineering

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 */
}

signed int adaptive_filter(int l_input,int r_input)

//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;

for (i = 0; i < N; i++)

//noise as input to adapt FIR

//to calculate out of adapt FIR

yn += (w[i] * delay[i]);
E = (desired + noise) - yn;
for (i = N-1; i >= 0; i--)

//desired+noise

//output of adaptive filter


//"error" signal=(d+n)-yn

//to update weights and delays

{
w[i] = w[i] + beta*E*delay[i]; //update weights
Dept. of Electronics & Communication Engineering

delay[i] = delay[i-1];

//update delay samples

//output=((short)E); //error signal as overall output


output=((short)dplusn);//output (desired+noise)
//overall output result
return(output);
}

Result:

Dept. of Electronics & Communication Engineering

Experiment No. 14

PROGRAM FOR AUDIO APPLICATION


Aim: To plot a time & frequency display of micro phone plus a cosine using DSP read a
wav file and match with their respective spectrograms.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

Spectrogram_rtdx_mtl.c Time-Frequency analysis of signals Using RTDX-MATLAB


#include "dsk6713_aic23.h"
fs=DSK6713_AIC23_FREQ_8KHZ;
#include <rtdx.h>
#include <math.h>
#include "hamming.cof"
#define PTS 256
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);
float iobuffer[PTS],iobuffer1[PTS],a[PTS];
float x1[PTS];
short i;
int j, k,l, curr_block = 0;
short buffercount = 0;
short flag = 0;
COMPLEX w[PTS];
Dept. of Electronics & Communication Engineering

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

for (i = 0 ; i < PTS ; i++)


{
x1[i] = (samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/16;
}
RTDX_write(&ochan, x1, sizeof(x1)/2); //send 128 samples to PC
}
}
interrupt void c_int11()
{
output_sample((short)(iobuffer[buffercount]));
iobuffer[buffercount++]=(short)(input_sample());
if (buffercount >= PTS)
{
buffercount = 0;
flag = 1;
}
}

Dept. of Electronics & Communication Engineering

FFT.c C callable FFT function in C


#define PTS 256

//# of points for FFT

typedef struct {float real,imag;} COMPLEX;


extern COMPLEX w[PTS];

//twiddle constants stored in w

void FFT(COMPLEX *Y, int N)

//input sample array, # of points

{
COMPLEX temp1,temp2;
int i,j,k;

//temporary storage variables

//loop counter variables

int upper_leg, lower_leg;


int leg_diff;

//index of upper/lower butterfly leg

//difference between upper/lower leg

int num_stages = 0;
int index, step;

//number of FFT stages (iterations)


//index/step through twiddle constant

i = 1;

//log(base2) of N points= # of stages

do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;

//difference between upper&lower legs

step = 512/N;

//step between values in twiddle.h

for (i = 0;i < num_stages; i++) //for N-point FFT


{
index = 0;
for (j = 0; j < leg_diff; j++)
{
Dept. of Electronics & Communication Engineering

for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))


{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++)

//bit reversal for resequencing data

{
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);

%set up CCS object

reset(cc);

%reset board

visible(cc,1);

%for CCS window

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);

%set 50sec timeout for RTDX

open(cc,'spectrogram1.pjt');

%open CCS project

load(cc,'./debug/spectrogram1.out');

%load executable file

run(cc);

%run program

configure(cc.rtdx,2048,1);
open(cc.rtdx,'ochan','r');

%configure one RTDX channel


%open output channel

pause(3)

%wait for RTDX channel to open

enable(cc.rtdx,'ochan');

%enable channel from DSK

isenabled(cc.rtdx,'ochan');
M = 256;

%window size

N = round(M/2);
B = 128;

%No. of blocks (128)

fs = 8000;

%sampling rate

t=(1:B)*(M/fs);

%spectrogram axes generation

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');

%read FFT data from DSK

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

Dept. of Electronics & Communication Engineering

Experiment No. 15

PROGRAM FOR GENERATION OF DTMF SIGNALS


Aim: To generate dual tone multiple frequency signals.
Software Required:
Operating System

Windows Xp

Constructor

Simulator

Software

MAT Lab 7.5 & CCStudio3.1

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

thanks for playing!


RESULT: Dual tone multiple frequency signals are generated.

Dept. of Electronics & Communication Engineering

You might also like