Professional Documents
Culture Documents
com
Department of Electronics and Communication
VCET,Hyderabad.
Prepared by:
K. Ashok Kumar Reddy
Page 1
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
L T/P/D C
0
-/3/-
Page 2
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
CONTENTS
List of experiments using Mat lab
Introduction to MATLAB
Page No.
4
10
18
20
22
24
26
30
34
37
40
43
46
49
52
55
Introduction to CC STUDIO
63
68
2) Linear Convolution
72
75
Page 3
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
INRODUCTION
MATLAB: MATLAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for
technical computation, graphics and animation. The MATLAB name stands for MATrix
Laboratory
Page 4
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
and/or get data back out (i.e. the list of commands is like a function in most programming
languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you
as if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that MATLAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It simply
reads through each line of the function, executes it, and then goes on to the next line. (In
practice, a form of compilation occurs when you first run a function, so that it can run faster the
next time you run it.)
MATLAB Windows :
MATLAB works with through three basic windows
Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called M
files.
Input-output:
MATLAB supports interactive computation taking the input from the screen and flushing, the
output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, charcter strings, structures and cells.There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required
for vectors or arrays .we can find the dimensions of an existing matrix or a vector with the size
and length commands.
Page 5
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
0000
0000
6. ones (5,2)
Digital Signal Processing Lab Manual
Page 6
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The above instruction creates a vector of five rows and two columns
Output =
11
11
11
11
11
7. a = [ 1 2 3]
b = [4 5 6]
a.*b = [4 10 18]
8
if C= [2 2 2]
b.*C results in [8 10 12]
9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
Page 7
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent number
of the figure
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent number
of the figure
12. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.
13.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed.Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable.Note that disp does not display
empty arrays.
14.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
15. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
Digital Signal Processing Lab Manual
Page 8
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
16.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
17.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
18.FFT Discrete Fourier transform.
FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation is
applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton
dimension.
FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated
if it has more.
Page 9
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
1. Generation of signals
Aim:- To ge nera te the following signals using MAT L A B 6. 5
1. Unit im pulse signal
2. Unit ste p signa l
3. Unit ra m p signa l
4. E xpone ntia l growing signal
5. E xpone ntia l deca ying signa l
6. Sine signal
7. Cosine s ignal
Apparatus Required:- Syste m with MAT L A B 6. 5.
Algorithm:1. Get the num ber of sa m ples.
2. Ge nera te the unit im pulse, unit s te p using ones, zeros m atrix c om ma nd.
3. Ge nera te ra m p, s ine, cosine a nd e xpone ntia l signals using c orres ponding ge nera l form ula.
4. Plot the graph.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
Page 10
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
P rogram:
1. Unit impulse signal
clc;
clear all;
close all;
dis p('UNIT I MPUL SE SIGNAL ');
N=input(' E nter Num ber of Sa m ples: ');
n=-N:1:N
x=[zeros(1, N) 1 ze ros(1, N)]
ste m(n, x);
xla be l('T ime');
yla be l('Am plitude');
title('Im pulse Res ponse');
Output:UNIT I MP UL SE SIGNAL
Enter Number of Samples: 6
Page 11
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
clc;
clear all;
close all;
dis p('UNIT STE P SIGN AL');
N=input(' E nter Num ber of Sa m ples : ');
n=-N:1:N
x=[zeros(1, N) 1 ones (1, N)]
ste m(n, x);
xla be l('T ime');
yla be l('Am plitude');
title('Unit Ste p Res ponse');
Output:UNIT ST E P SIGNAL
E nter Num ber of Sa m ples : 6
Page 12
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:UNIT RA MP SIGNAL
E nter Num ber of Sa m ples : 6
E nter Am plitude : 20
Page 13
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 14
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 15
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
6. Cosine signal
clc;
clear all;
close all;
Output:COSINE SIGN AL
E nter Num ber of Sa m ples : 16
Page 16
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
7. Sine signal
clc;
clear all;
close all;
Result:- Thus the MATLAB program for generation of all basic signals was performed and the
output was verified.
Digital Signal Processing Lab Manual
Page 17
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 18
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:-
Result:- Thus the MATLAB program for sum of sinusoidal signals was performed and the output was
verified.
Page 19
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 20
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
ylabel('Imaginary part');
title('Poles and Zeros of H[z] in Z-plane');
Output:Difference Equation of a digital system
Desired Impulse response length = 100
Coefficients of x[n] terms = 1
Coefficients of y[n] terms = [1 -1 0.9]
Result:-Thus the MATLAB program for Impulse Response of Difference Equation was
performed and the output was verified
Digital Signal Processing Lab Manual
Page 21
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
4.
VCET,Hyderabad.
Page 22
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:-
Result:- Thus the MATLAB program for Frequency Response of Difference Equation was
performed and the output was verified.
Note:- If the transfer function is given instead of difference equation the n perform the inverse ZTransform and obtain the difference equation and then find the frequency response for the
difference equation using Matlab.
Page 23
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 24
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:-
Result:- Thus the MATLAB program for Power Spectral Density was performed and the
output was verified.
Page 25
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
Page 26
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 27
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
Output:enter passband ripple
0.02
enter the stopband ripple
0.01
enter passband freq
1000
enter stopband freq
1500
enter sampling freq
10000
enter beta value
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
1
Rectangular window filter response
Page 28
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 29
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 30
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 31
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
Page 32
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 33
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
where, w = 0:.01:pi
This function returns complex frequency response vector h and frequency vector om in
radians/samples of the filter.
8) Calculate the magnitude of the frequency response in decibels (dB
m=20*log10(abs(h))
9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]
10) Calculate the phase response using an = angle(h)
11) Plot the phase response [phase in radians Vs normalized frequency (om/pi)]
12)Give relevant names to x and y axes and give an appropriate title for the plot.
13)Plot all the responses in a single figure window.[Make use of subplot]
Digital Signal Processing Lab Manual
Page 34
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Low Pass filter is:');
xlabel('(a) Normalized freq. -->');
Digital Signal Processing Lab Manual
Page 35
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Low Pass filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
Page 36
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 37
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR High Pass filter is:');
Digital Signal Processing Lab Manual
Page 38
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 39
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Algorithm:
1) Get the input sequence
2) Number of DFT point(m) is 8
3) Find out the FFT function using MATLAB function.
4) Display the input & outputs sequence using stem function
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
Digital Signal Processing Lab Manual
Page 40
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 41
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 42
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The inverse DFT allows us to recover the sequence x[n] from the frequency samples.
X(k) is a complex number (remember ejw=cosw + jsinw). It has both magnitude and phase
which are plotted versus k. These plots are magnitude and phase spectrum of x[n]. The k gives
us the frequency information.
Here k=N in the frequency domain corresponds to sampling frequency (fs). Increasing N,
increases the frequency resolution, i.e., it improves the spectral characteristics of the sequence.
For example if fs=8kHz and N=8 point DFT, then in the resulting spectrum, k=1 corresponds to
1kHz frequency. For the same fs and x[n], if N=80 point DFT is computed, then in the resulting
spectrum, k=1 corresponds to 100Hz frequency. Hence, the resolution in frequency is increased.
Since N L , increasing N to 8 from 80 for the same x[n] implies x[n] is still the same
sequence (<8), the rest of x[n] is padded with zeros. This implies that there is no further
information in time domain, but the resulting spectrum has higher frequency resolution. This
spectrum is known as high density spectrum (resulting from zero padding x[n]). Instead of
zero padding, for higher N, if more number of points of x[n] are taken (more data in time
domain), then the resulting spectrum is called a high resolution spectrum.
Procedure:1)Open MATLAB
2)Open new M- file
Digital Signal Processing Lab Manual
Page 43
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
1.0000 - 1.0000i
Column 4
1.0000 + 1.0000i
Page 44
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 45
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
12.
VCET,Hyderabad.
Page 46
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
Page 47
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
stem(m,y(1:N/M));
title('Output Sequence');
xlabel('Time index n');ylabel('Amplitude');
Output:enter Down-sampling factor : 3
enter number of samples :100
Page 48
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
To increase the sampling rate by an integer factor L, it is necessary to extract the samples
from x(n). The samples of xi(n) for values of n that are integer multiples of L are easily extracted
from x(n) as follows:
The system performing the operation is called up-sampler and is shown below:
After up-sampling, it is necessary to remove the frequency scaled images in xi(n), except those
that are at integer multiples of 2. This is accomplished by filtering xi(n) with a low-pass filter
that has a cutoff frequency of /L and a gain of L. In the time domain, the low-pass filter inter polates between the samples at integer multiples of L as shown below and is called interpolator.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
Digital Signal Processing Lab Manual
Page 49
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:-
Page 50
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 51
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
SRC by L/M requires performing an interpolation to a sampling rate which is divisible by both L
and M. The final output is then achieved by decimating by a factor of M. The need for a noninteger sampling rate conversion appears when the two systems operating at different sampling
rates have to be connected, or when there is a need to convert the sampling rate of the recorded
data into another sampling rate for further processing or reproduction. Such applications are very
common in telecommunications, digital audio, multimedia and others. An example is transferring
data from compact disc (CD) system at a rate of 44.1 kHz to a digital audio tape at 48 kHz. This
can be achieved by increasing the data rate of the CD by a factor of 48/44.1, a non-integer.
If M>L, the resulting operation is a decimation process by a non- integer, and when M<L it is
interpolation. If M=1, the generalized system reduces to the simple integer interpolation and if
L=1 it reduces to integer decimation.
Page 52
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Procedure:1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window\ Figure window
Program:clc;
close all;
clear all;
L = input('Enter Up-sampling factor :');
M = input('Enter Down-sampling factor :');
N = input('Enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
y = resample(x,L,M);
subplot(2,1,1);
stem(n,x(1:N));
axis([0 29 -2.2 2.2]);
title('Input Sequence');
xlabel('Time index n'); ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N*L/M)-1;
stem(m,y(1:N*L/M));
axis([0 (N*L/M)-1 -2.2 2.2]);
title('Output Sequence');
xlabel('Time index n'); ylabel('Amplitude');
Output:Enter Up-sampling factor :7
Enter Down-sampling factor :2
Enter number of samples :30
Digital Signal Processing Lab Manual
Page 53
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Result:- Thus sampling rate conversion by a rational form is performed using MATLAB
Page 54
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Digital Signal Processing can be divided into two categories, fixed po int and
floating point which refer to the format used to store and manipulate numbers within the devices.
Fixed point DSPs usually represent each number with a minimum of 16 bits, although a different
length can be used. There are four common ways that these 216 i,e., 65,536 possible bit patterns
can represent a number. In unsigned integer, the stored number can take on any integer value
from 0 to 65,535, signed integer uses two's complement to include negative numbers from 32,768 to 32,767. With unsigned fraction notation, the 65,536 levels are spread uniformly
between 0 and 1 and the signed fraction format allows negative numbers, equally spaced
between -1 and 1.
The floating point DSPs typically use a minimum of 32 bits to store each value. This results in
many more bit patterns than for fixed point, 232 i,e., 4,294,967,296 to be exact. All floating point
DSPs can also handle fixed point numbers, a necessity to implement counters, loops, and signals
coming from the ADC and going to the DAC. However, this doesn't mean that fixed point math
will be carried out as quickly as the floating point operations; it depends on the internal
architecture.
C versus Assembly:
Page 55
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
DSPs are programmed in the same languages as other scientific and engineering applications,
usually assembly or C. Programs written in assembly can execute faster, while programs written
in C are easier to develop and maintain. In traditional applications, such as programs run on PCs
and mainframes, C is almost always the first choice. If assembly is used at all, it is restricted to
short subroutines that must run with the utmost speed.
How fast are DSPs?
The primary reason for using a DSP instead of a traditional microprocessor is speed: the ability
to move samples into the device and carry out the needed mathematical operations, and output
the processed data. The usual way of specifying the fastness of a DSP is: fixed point systems are
often quoted in MIPS (million integer operations per second). Likewise, floating point devices
can be specified in MFLOPS (million floating point operations per second).
TMS320 Family:
The Texas Instruments TMS320 family of DSP devices covers a wide range, from a 16-bit fixedpoint device to a single-chip parallel-processor device. In the past, DSPs were used only in
specialized applications. Now they are in many mass- market consumer products that are
continuously entering new market segments. The Texas Instruments TMS320 family of DSP
devices and their typical applications are mentioned below.
C1x, C2x, C2xx, C5x, and C54x: The width of the data bus on these devices is 16 bits. All have
modified Harvard architectures. They have been used in toys, hard disk drives, modems, cellular
phones, and active car suspensions.
C3x: The width of the data bus in the C3x series is 32 bits. Because of the reasonable cost and
floating-point performance, these are suitable for many applica tions. These include almost any
filters, analyzers, hi- fi systems, voice- mail, imaging, bar-code readers, motor control, 3D
graphics, or scientific processing.
C4x: This range is designed for parallel processing. The C4x devices have a 32-bit data bus and
are floating-point. They have an optimized on-chip communication channel, which enables a
number of them to be put together to form a parallel-processing cluster. The C4x range devices
have been used in virtual reality, image recognition, telecom routing, and parallel-processing
systems.
C6x: The C6x devices feature VelociTI , an advanced very long instruction word (VLIW)
architecture developed by Texas Instruments. Eight functional units, including two multipliers
Digital Signal Processing Lab Manual
Page 56
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
and six arithmetic logic units (ALUs), provide 1600 MIPS of cost-effective performance. The
C6x DSPs are optimized for multi-channel, multifunction applications, including wireless base
stations, pooled modems, remote-access servers, digital subscriber loop systems, cable modems,
and multi-channel telephone systems.
Page 57
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 58
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The DSK is USB port interfaced platform that allows to efficiently develop and test
applications for the C6713. With extensive host PC and target DSP software support, the DSK
provides ease-of- use and capabilities that are attractive to DSP engineers.
The 6713 DSP Starter K it (DSK) is a low-cost platform which lets customers evaluate and
develop applications for the Texas Instruments C67X DSP family.
The primary features of the DSK are:
225 MHz TMS320C6713 Floating Point DSP
AIC23 Stereo Codec
Four Position User DIP Switch and Four User LEDs
On-board Flash and SDRAM
TIs Code Composer Studio development tools are bundled with the 6713DSK providing the
user with an industrial-strength integrated development environment for C and assembly
programming.
Code Composer Studio communicates with the DSP using an on-board JTAG emulator through a
USB interface.
The TMS320C6713 DSP is the heart of the system. It is a core member of Texas Instruments
C64X line of fixed point DSPs whose distinguishing features are an extremely high performance
225MHz VLIW DSP core and 256Kbytes of internal memory. On-chip peripherals include a 32bit external memory interface (EMIF) with integrated SDRAM controller, 2 multi-channel
buffered serial ports (McBSPs), two on-board timers and an enhanced DMA controller (EDMA).
The 6713 represents the high end of TIs C6700 floating point DSP line both in terms of
computational performance and on-chip resources.
The 6713 has a significant amount of internal memory so many applications will have all code
Digital Signal Processing Lab Manual
Page 59
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
and data on-chip. External accesses are done through the EMIF which can connect to both
synchronous and asynchronous memories. The EMIF signals are also brought out to standard TI
expansion bus connectors so additional functionality can be added on daughter card modules.
DSPs are frequently used in audio processing applications so the DSK includes an on-board
codec called the AIC23. Codec stands for coder/decoder,the job of the AIC23 is to code analog
input samples into a digital format for the DSP to process, then decode data coming out of the
DSP to generate the processed analog output. Digitial data is sent to and from the codec on
McBSP1.
TMS320C6713 DSK Overview Block Diagram
Page 60
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The DSK has 4 light emitting diodes (LEDs) and 4 DIP switches that allow users to interact with
programs through simple LED displays and user input on the switches. Many of the included
examples make use of these user interfaces Options.
The DSK implements the logic necessary to tie board components together in a
programmable logic device called a CPLD. In addition to random glue logic, the CPLD
implements a set of 4 software programmable registers that can be used to access the on-board
LEDs and DIP switches as well as control the daughter card interface.
Page 61
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 62
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
If the board still fails to detect Go to CM OS setup Enable the USB Port Option
(The required Device drivers will load along with CCS Installation)
SOFTWARE INSTALLATION
You must install the hardware before you install the software on your system.
The requirements for the operating platform are;
Insert the installation CD into the CD-ROM drive
An install screen appears; if not, goes to the windows Explorer
and run setup.exe
Choose the option to install Code Composer Studio
If you already have C6000 CC Studio IDE installed on your PC,do not install DSK
software. CC Studio IDE full tools supports the DSK platform
Respond to the dialog boxes as the installation program runs
The Installation program automatically configures CC Studio IDE for operation with your DSK
and creates a CCStudio IDE DSK icon on your desktop. To install, follow these instructions:
Page 63
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Code Composer is the DSP industry's first fully integrated development environment (IDE) with
DSP-specific functionality. With a familiar environment liked MS-based C++TM, Code
Composer lets you edit, build, debug, profile and manage projects from a single unified
environment. Other unique features include graphical signal analysis, injection/extraction of data
signals via file I/O, multi-processor debugging, automated testing and customization via a Cinterpretive scripting language and much more.
3. file.asm: assembly source program created by the user, by the C compiler,or by the linear
optimizer.
4. file.sa: linear assembly source program. The linear optimizer uses file.sa as input to produce
an assembly program file.asm.
5. file.h: header support file.
Digital Signal Processing Lab Manual
Page 64
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
6. file.lib: library file, such as the run-time support library file rts6701.lib.
7. file.cmd: linker command file that maps sections to memory.
8. file.obj: object file created by the assembler.
9. file.out: executable file created by the linker to be loaded and run on the processor.
Procedure to work on code composer studio
1.Click on CCStudio 3.1 on the desktop
Page 65
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Enter the source code and save the file with .C extension.
5. To add the c program to the project
Project Add files to project <source file>
Page 66
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
8. To compile
Project Compile file ( or use icon or ctrl+F7 )
9. To build or link
Project build (or use F7 ) (which will create a .out file in project folder)
Digital Signal Processing Lab Manual
Page 67
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 68
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 69
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Program
Sine Wave
#include <stdio.h>
#include <math.h>
float a[500];
void main()
{
int i=0;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
}
Square wave
#include <stdio.h>
#include <math.h>
int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{
for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1) ;
}
}
Page 70
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:Sine wave
Page 71
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Square wave:-
Result:- The sine wave and square wave has been obtained.
Page 72
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
2. Linear Convolution
Aim: -To verify Linear Convolution.
Equipments: Operating System - Windows XP
Software - CC STUDIO 3
Page 73
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Program:
// Linear convolution program in c language using CC Studio
#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for i/p h(n) \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}
Page 74
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Precautions:
1) Switch ON the computer only after connecting USB cable and make sure the DSP kit is ON.
2) Perform the diagnostic check before opening code composer studio.
3) All the connections must be tight.
Result:- Thus linear convolution of 2 sequences is verified using CC Studio.
Page 75
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 76
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
void main()
{
int j, k;
float a[Order+1] = {0.1311, 0.2622};
float b[Order+1] = {1, -0.7478};
for(j=0; j<Len; j++)
{
sum = 0.0;
for(k=1; k<=Order; k++)
{
if((j-k)>=0)
sum = sum+(b[k]*h[j-k]);
}
if(j<=Order)
h[j] = a[j]-sum;
else
h[j] = -sum;
printf("%f", j, h[j]);
}
}
Output:
0.131100 0.360237 0.269385 0.201446 0.150641.
Page 77
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 78
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
2. Connect CRO/Desktop Speakers to the Socket Provided for LINE OUT or connect a
headphone to the Headphone out Socket.
3. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.
4. Use the Debug Connect menu option to open a debug connection to the DSK Board
Page 79
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
8. Automatically three files are added in the Gene rated file folder in project pane
xyzcfg.cmd Command and linking file
xyzcfg.s62 optimized assembly code for configuration
xyzcfg_c.c Chip support initialization
9. Open the File Menu ne w Source file
10. Type the code in editor window. Save the file in project folder. (Eg: Codec.c).
Important note: Save your source code with preferred language extension. For ASM codes save
the file as code(.asm) For C and C++ codes code (*.c,*.cpp) respectively.
Digital Signal Processing Lab Manual
Page 80
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
11. Add the saved Codec.c file to the current project which has the main function and
calls all the other necessary routines. Project Add files to Project Codec.c
12. Add the library file dsk6713bsl.lib to the current project
Path : C:\CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib
Files of type : Object and library files (*.o*, *.l*)
13. Copy header files dsk6713.h and dsk6713_aic23.h from and paste it in current project
folder.
C:\CCStudio_v3.1\C6000\dsk6713\include.
14. Add the header file generated within xyzcfg_c.c to codec.c
Note:- Double click on xyzcfg_c.c. Copy the first line header (eg.#include xyzcfg.h) and
paste that in source file (eg.codec.c).
15. Compile the program using the Project-compile pull down menu or by Clicking the
shortcut icon on the left side of program window.
16. Build the program using the Project-Build pull down menu or by clicking the shortcut icon
on the left side of program window.
17. Load the program (Codec. Out) in program memory of DSP chip using the File-load
program pull down menu.
18. Debug Run
19. You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec
configuration.
20. You can also pass an audio input and hear the output signal through the speakers.
21. You can also vary the sampling frequency using the DSK6713_AIC23_setFreq Function in
the codec.c file and repeat the above steps.
Conclusion:
The codec TLV320AIC23 successfully configured using the board support library and verified.
Page 81
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Sinewave.c
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include <stdio.h>
Digital Signal Processing Lab Manual
Page 82
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
#include <math.h>
float a[500],b;
DSK6713_AIC23_Config config= DSK6713_AIC23_DEFAULTCONFIG;
void main()
{
int i=0;
DSK6713_AIC23_CodecHandle hCodec;
Int l_output,r_output;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq=DSK6713_AIC23_FREQ_48KHZ;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
while(1)
{
for(i=0;i<500;i++)
{
b=400*a[i];
while(!DSK6713_AIC23_write(hCodec,b));
}
}
DSK6713_AIC23_closeCodec(hCodec);
}
Result:- The sine wave tone have been successfully generated and obtained through speaker
Page 83
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 84
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Matlab Program to gene rate FIR Filter-Low Pass Coefficients using FIR1
% FIR Low pass filters using rectangular, triangular and kaiser windows
fid=fopen('FIR_lowpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
Digital Signal Processing Lab Manual
Page 85
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:
Page 86
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
T.2: Matlab generated Coefficients for FIR Low Pass Rectangular filter
T.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter
Page 87
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
fid=fopen('FIR_highpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
Digital Signal Processing Lab Manual
Page 88
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
T.1: MATLAB generated Coefficients for FIR High Pass Kaiser filter:
Page 89
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
T.2 :MATLAB generated Coefficients for FIR High Pass Rectangular filter
T.3 : MATLAB generated Coefficients for FIR High Pass Triangular filter
Page 90
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,
0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.000000,
0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,
-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,
0.000000,-0.002423,-0.001591,0.000000 };
static short in_buffer[100];
DSK6713_AIC23_Config config = {\
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume */\
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume*/\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */\
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */\
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */\
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */\
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */\
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */\
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */\
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
Digital Signal Processing Lab Manual
Page 91
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 92
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
PROCEDURE :
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/* main() - Main code routine, initializes BSL and generates tone */
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
/*set codec sampling frequency*/
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
/* Read a sample to the left channel */
Digital Signal Processing Lab Manual
Page 93
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Output:-
Page 94
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Result:- Thus FIR (LP/HP) filter is designed using windowing technique and verified using the
DSP Processor.
Page 95
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 96
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 97
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
figure(2);
[h,w]=freqz(num_bw2,den_bw2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb2,den_cb2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1 (Ripple: 3dB)');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response in the passband');
axis([0 12000 -20 20]);
Digital Signal Processing Lab Manual
Page 98
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 99
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 100
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 101
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
y[2] =
y[1] =
x[2] =
x[1] =
y[1];
y[0];
x[1];
x[0];
VCET,Hyderabad.
/* y(n-2) = y(n-1) */
/* y(n-1) = y(n) */
/* x(n-2) = x(n-1) */
/* x(n-1) = x(n) */
/* temp is used as input next time through */
return (temp<<2);
}
Procedure:
1) Switch on the DSP board.
2) Open the Code Composer Studio.
3) Create a new project
Project New (File Name. pjt , Eg: IIR.pjt)
4) Initialize on board codec.
Kindly refer the Topic Configuration of 6713 Codec using BSL
5) Add the given above C source file to the current project (re move codec.c
source file from the project if you have already added).
6) Connect the speaker jack to the input of the CRO.
7) Build the program.
8) Load the generated object file(*.out) on to Target board.
9) Run the program using F5.
10) Observe the waveform that appears on the CRO screen.
Page 102
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Result:- Thus IIR (LP/HP) filter is designed using Low pass Butterworth and Chebyshev filters
technique and verified using the DSP processor
Page 103
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
7.
VCET,Hyderabad.
Audio applications
Aim: - To Perform Audio applications 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.
Equipments:1) Operating System - Windows XP
2) Software - CC STUDIO 3
3) Software Matlab 6.5
4) DSK 6713 DSP Trainer kit.
5) USB Cable
6) Power supply
Theory:
Spectrogram with RTDX using MATLAB
This version of project makes use of RTDX with MATLAB for transferring data from
the DSK to the PC host. This section introduces configuration file(.CDB) file and RTDX with
MATLAB.
This project uses source program spectrogram_rtdx_mtl.c that runs on the DSK which
computes 256 point FFT and enables an RTDX output channel to write/send the resulting FFT
data to the PC running MATLAB for finding the spectrogram. A total o f N/2 (128 points )are
sent. The (.CDB) configuration file is used to set interrupt INT11. From this configuration file
select Input/Output RTDX. Right click on properties and change the RTDX buffer size to
8200. Within CCS, select tools RTDX Configure to set the host buffer size to 2048(from
1024).
An input signal is read in blocks of 256 samples. Each block of data is then
multiplied with a hamming window of length 256 points. The FFT of the windowed data is
calculated and squared. Half of the resulting FFT of each block of 256 points is then transferred
to the PC running MATLAB to find the specrtrogram.
Page 104
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;
#include <rtdx.h>
#include <math.h>
#include "hamming.cof"
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);
//FFT prototype
float iobuffer[PTS],iobuffer1[PTS],a[PTS];
float x1[PTS];
//intermediate buffer
short i;
int j, k,l, curr_block = 0;
short buffercount = 0;
short flag = 0;
COMPLEX w[PTS];
COMPLEX samples[PTS];
RTDX_CreateOutputChannel(ochan);
main()
{
for (i = 0 ; i<PTS ; i++)
{
Digital Signal Processing Lab Manual
Page 105
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
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 . . . ");
//while waiting
for(l=0;l<256;l++)
a[l]=cos(2*3.14*1500*l/8000);
for(k=0;k<5000;k++)
//infinite loop
{
while (flag == 0) ;
flag = 0;
//reset flag
//swap buffers
{ iobuffer1[i]=iobuffer[i]+a[i];
samples[i].real=h[i]*iobuffer1[i]; //multiply by Hamming window coeffs
iobuffer1[i] = x1[i];
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0;
FFT(samples,PTS);
//imag components = 0
//call C-coded FFT function
{
x1[i] = (samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/16; //FFT data scaling
Digital Signal Processing Lab Manual
Page 106
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
}
RTDX_write(&ochan, x1, sizeof(x1)/2);
//end of main
//ISR
{
output_sample((short)(iobuffer[buffercount])); //out from iobuffer
iobuffer[buffercount++]=(short)(input_sample()); //input to iobuffer
if (buffercount >= PTS)
{
buffercount = 0;
/reinit buffercount
flag = 1;
//reset flag
}
}
{
COMPLEX temp1,temp2;
int i,j,k;
Page 107
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
step = 512/N;
Page 108
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
-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++)
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
Digital Signal Processing Lab Manual
Page 109
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
(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);
visible(cc,1);
enable(cc.rtdx);
%reset board
%for CCS window
%enable RTDX
if ~isenabled(cc.rtdx);
error('RTDX is not enabled')
end
cc.rtdx.set('timeout',50);
open(cc,'spectrogram1.pjt');
load(cc,'./debug/spectrogram1.out');
run(cc);
configure(cc.rtdx,2048,1);
open(cc.rtdx,'ochan','r');
%run program
%configure one RTDX channel
%open output channel
Page 110
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
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');
set(gca,'YLimMode','manual');
for i = 1:32768
w=readmsg(cc.rtdx,'ochan','single');
w=double(w(1:N));
y(:, column) = w';
Digital Signal Processing Lab Manual
Page 111
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
imagesc(t,f,dB(y));
VCET,Hyderabad.
%plot spectrogram
column = mod(column, B) + 1;
end
halt(cc);
%halt processor
close(cc.rtdx,'ochan');
%close channel
clear cc
%clear object
Procedure:
1. Create a new project with name spectrogram.pjt.
2. Open spectrogram.cdb from given CD and save it in your new
project folder.
3. Copy the following files from the CD to your new project folder
1) c6713dskinit . c
2) FFT.c
3) spectrogram_rtdx_mtl.c
4) c6713dskinit . h
5) hamming.cof
6) spectrogram_RTDX.m
4. Add spectrogram.cdb, c6713dskinit.c and spectrogram_rtdx_mtl.c to the current
project.
5. Add the library file dsk6713bsl.lib to the current project
Path C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib
5. Set the following compiler options.
Select Project Build options.
Select the following for compiler option with Basic ( for category):
(1) c671x{mv6710} (for target version)
(2) Full symbolic debug (for Generate Debug info)
(3) Speed most critical(for Opt Speed vs. Size)
(4) None (for Opt Level and Program Level Opt)
Digital Signal Processing Lab Manual
Page 112
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Select The Preprocessor Category and Type for Define Symbols{d}: CHIP_6713, and
from Feedback category, select for Interlisting: OPT / C and ASM{-s}
6 Build project.
7. Close CCS
8. Open MATLAB and Run spectrogram_RTDX.m . within MATLAB ,CCS will
enable RTDX and will load and run the COFF(.out) executable file. Then
MATLAB will plot the spectrogram of an input signal .
Result:- Thus Audio application is performed and spectrogram of an input signal is plotted using
Matlab.
Page 113
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
8. Noise removal
Aim:- To
1) Add noise above 3kHz and then remove (using adaptive filters)
2) Interference suppression using 400 Hz tone
Equipments:1) Operating System - Windows XP
2) Software - CC STUDIO 3
3) DSK 6713 DSP Trainer kit.
4) USB Cable
5) Power supply
6) CRO
7) Function Generator
Theory:- Adaptive filters are best used in cases where signal conditions or system parameters
are slowly changing and the filter is to be adjusted to compensate for this change. The least mean
squares (LMS) criterion is a search algorithm that can be used to provide the strategy for
adjusting the filter coefficients.
Page 114
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Figure 1 shows a basic adaptive filter structure in which the adaptive filters output y is
compared with a desired signal d to yield an error signal e, which is fed back to the adaptive
filter. The coefficients of the adaptive filter are adjusted, or optimized, using a least mean
squares (LMS) algorithm based on the error signal. We discuss here only the LMS searching
algorithm with a linear combiner (FIR filter), although there are several strategies for performing
adaptive filtering. The output of the adaptive filter in Figure 1 is
---------------------------------(1)
where wk(n) represent N weights or coefficients for a specific time n. The convolution equation
1 is in conjunction with FIR filtering. It is common practice to use the terminology of weights w
for the coefficients associated with topics in adaptive filtering and neural networks.A
performance measure is needed to determine how good the filter is. This
measure is based on the error signal,
----------------------------------(2)
which is the difference between the desired signal d(n) and the adaptive filters output y(n).The
weights or coefficients wk(n) are adjusted such that a mean squared error function is minimized.
This mean squared error function is E[e2(n)], where E represents the expected value. Since there
are k weights or coefficients, a gradient of the mean squared error function is required. An
estimate can be found instead using the gradient of e2(n), yielding
--------------------------------(3)
which represents the LMS algorithm [13]. Equation 3 provides a simple but powerful and
efficient means of updating the weights, or coefficients, without the need for averaging or
differentiating, and will be used for implementing adaptive filters. The input to the adaptive filter
is x(n), and the rate of convergence and accuracy of the adaptation process (adaptive step size) is
b.
For each specific time n, each coefficient, or weight, wk(n) is updated or replaced by a
new coefficient, based on 3, unless the error signal e(n) is zero. After the filters output y(n), the
error signal e(n) and each of the coefficients wk(n) are updated for a specific time n, a new
Page 115
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
sample is acquired (from an ADC) and the adaptation process is repeated for a different time.
Note that from equation 3, the weights are not updated when e(n) becomes zero.
The linear adaptive combiner is one of the most useful adaptive filter structures and is
an adjustable FIR filter.Whereas the coefficients of the frequency-selective FIR filter are fixed,
the coefficients, or weights, of the adaptive FIR filter can be adjusted based on a changing
environment such as an input signal. Adaptive IIR filters (not discussed here) can also be used. A
major problem with an adaptive IIR filter is that its poles may be updated during the adaptatio n
process to values outside the unit circle, making the filter unstable.
ADAPTIVE STRUCTURES
A number of adaptive structures have been used for different applications in adaptive
ltering.
1. For noise cancellation. Figure 2 shows the adaptive structure in Figure 1 modied for a noise
cancellation application. The desired signal d is corrupted by uncorrelated additive noise n. The
input to the adaptive lter is a noise n that is correlated with the noise n. The noise n could
come from the same source as n but modied by the environment. The adaptive lters output y
is adapted to the noise n. When this happens, the error signal approaches the desired signal d.
The overall output is this error signal and not the adaptive lters output y. This structure will be
further illustrated with programming examples using C code.
2. For system identication. Figure 3 shows an adaptive lter structure that can be used for
system identication or modeling. The same input is to an unknown system in parallel with an
adaptive lter. The error signal e is the difference between the response of the unknown system d
and the response of the adaptive lter y. This error signal is fed back to the adaptive lter and is
used to update the adaptive lters coefcients until the overall output yd. When this happens,
the adaptation process is nished, and e approaches zero. In this scheme, the adaptive lter
models the unknown system. This structure is illustrated later with three programming examples.
3. Adaptive predictor. Figure 4 shows an adaptive predictor structure which can provide an
estimate of an input. This structure is illustrated later with a programming example.
4. Additional structures have been implemented, such as:
(a) Notch with two weights, which can be used to notch or cancel/reduce a sinusoidal noise
signal. This structure has only two weights or coefcients.This structure is shown in Figure 5 .
Digital Signal Processing Lab Manual
Page 116
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
(b) Adaptive channel equalization, used in a modem to reduce channel distortion resulting from
the high speed of data transmission over telephone channels.
Page 117
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The LMS is well suited for a number of applications, including adaptive echo and noise
cancellation, equalization, and prediction. Other variants of the LMS algorithm have been
employed, such as the sign-error LMS, the sign-data LMS, and the sign-sign LMS.
1. For the sign-error LMS algorithm, eqn 3 becomes
which reduces to
Page 118
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
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,
0x0017,
0x00d8,
0x00d8,
0x0011,
0x0000,
/* 5 DSK6713_AIC23_DIGPATH
0x0000,
0x0043,
/* 7 DSK6713_AIC23_DIGIF
0x0081,
0x0001
/* 9 DSK6713_AIC23_DIGACT
\
\
\
};
/* main() - Main code routine, initializes BSL and generates tone*/
void main()
{
Digital Signal Processing Lab Manual
Page 119
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
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));
}
DSK6713_AIC23_closeCodec(hCodec);
Page 120
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
//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
delay[i] = delay[i-1];
//output=((short)E);
output=((short)dplusn);
//output (desired+noise)
Page 121
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 122
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
A
MINI PROJECT
ON
DTMF (Touch Tone) SIGNALLING
Tone Generation and Detection Using MATLAB
Page 123
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
CONTENTS
Abstract
Chapter 1: Dual Tone Multi Frequency (DTMF)
1.1. Introduction
1.2. History
1.3. #, *, A, B, C, and D
1.4. Keypad
1.5. DTMF event frequencies
1.6. Sample Code for DTMF Tone generation
Page 124
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Abstract
Most engineers are familiar with the Fast Fourier Transform (FFT) and would have little
trouble using a "canned" FFT routine to detect one or more tones in an audio signal.What many
don't know, however, is that if you only need to detect a few frequencies, a much faster method
is available. It's called the Goertzel algorithm. The Goertzel algorithm can perform tone
detection using much less CPU horsepower than the Fast Fourier Transform.
The objective of this project is to gain an understanding of the DTMF tone generation
software and the DTMF decoding algorithm (The GOERTZEL algorithm) using MATLAB.
In this project DTMF tone for a digit (seven - 7) was generated and it was detected using
Goertzel algorithm.
Chapter 1
Dual Tone Multi-Frequency (DTMF)
Digital Signal Processing Lab Manual
Page 125
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
1.1. Introduction
DTMF is the generic name for push button telephone signaling that is equivalent to the
Touch Tone system in use within the BELL SYSTEM. DTMF also finds widespread use in
electronic mail systems and telephone banking systems in which the user can select options from
a menu by sending DTMF signals from a telephone.
Dual-tone multi-frequency (DTMF) signaling is used for telephone signaling over the
line in the voice-frequency band to the call switching center. The version of DTMF used for
telephone tone dialing is known by the trademarked term Touch-Tone(canceled March 13,
1984), and is standardized by ITU-T Recomme ndation Q.23.Other multi- frequency systems are
used for signaling internal to the telephone network.
In a DTMF signalling system, a combination of a high- frequency and a lowfrequency
tone represent a specific digit or the characters *, #, A, B, C and D. [1]
As a method of in-band signaling, DTMF tones were also used by cable television
broadcasters to indicate the start and stop times of local commercial insertion points during
station breaks for the benefit of cable companies. Until better out-of-band signaling equipment
was developed in the 1990s, fast, unacknowledged, and loud DTMF tone sequences could be
heard during the commercial breaks of cable channels in the United States and elsewhere.
1.2. History
In the time preceding the development of DTMF, telephone systems employed a
system commonly referred to as pulse (Dial Pulse or DP in the U.S.) or loop disconnect (LD)
signaling to dial numbers, which functions by rapidly disconnecting and connecting the calling
party's telephone line, similar to flicking a light switch on and off. The repeated connection and
disconnection, as the dial spins, sounds like a series of clicks. The exchange equipment counts
those clicks or dial pulses to determine the called number. Loop disconnect range was restricted
by telegraphic distortion and other technical problems, and placing calls over longer distances
required either operator assistance (operators used an earlier kind of multi- frequency dial) or the
provision of subscriber trunk dialing equipment.
Dual Tone Multi-Frequency, or DTMF, is a method for instructing a telephone
switching system of the telephone number to be dialed, or to issue commands to switching
systems or related telephony equipment.
Digital Signal Processing Lab Manual
Page 126
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The DTMF dialing system traces its roots to a technique developed by Bell Labs in
the 1950s called MF (Multi-Frequency) which was deployed within the AT&T telephone
network to direct calls between switching facilities using in-band signaling. In the early 1960s, a
derivative technique was offered by AT&T through its Bell System telephone companies as a
"modern" way for network customers to place calls. In AT&Ts Compatibility Bulletin No. 105,
AT&T described the product as "a method for pushbutton signaling from customer stations using
the voice transmission path."
The consumer product was marketed by AT&T under the re gistered trade name
Touch-Tone. Other vendors of compatible telephone equipment called this same system "Tone"
dialing or "DTMF," or used their own registered trade names such as the "Digitone" of Northern
Electric (now known as Nortel Networks).The DTMF system uses eight different frequency
signals transmitted in pairs to represent sixteen different numbers, symbols and letters - as
detailed below.
1.3. #, *, A, B, C, and D
The engineers had envisioned phones being used to access computers, and surveyed a
number of companies to see what they would need for this role. This led to the addition of the
octothorpe number sign (#) and star (*) keys as well as a group of keys for menu selection: A, B,
C and D. In the end, the lettered keys were dropped from most phones, and it was many years
before these keys became widely used for vertical service codes such as *67 in the United States
and Canada to suppress caller ID.
Public payphones that accept credit cards use these additional codes to send the information
from the magnetic strip.
The U.S. military also used the letters, relabeled, in their now defunct Autovon phone
system. Here they were used before dialing the phone in order to give some calls priority, cutting
in over existing calls if need be. The idea was to allow important traffic to get through every
time. The levels of priority available were Flash Override (A), Flash (B), Immediate (C), and
Priority (D), with Flash Override being the highest priority.Pressing one of these keys gave your
call priority, overriding other conversations on the network. Pressing C, Immediate, before
dialing would make the switch first look for any free lines, and if all lines were in use, it would
disconnect any non-priority calls, and then any priority calls. Flash Override will kick every
Digital Signal Processing Lab Manual
Page 127
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
other call off the trunks between the origin and destination. Consequently, it is limited to the
White House Communications Agency. Precedence dialing is still done on the military phone
networks, but using number combinations (Example: Entering 93 before a number is a priority
call) rather than the separate tones and the Government Emergency Telecommunications Service
has superseded Autovon for any civilian priority telco access.
Present-day uses of the A, B, C and D keys on telephone networks are few, and
exclusive to network control. For example, the A key is used on some networks to cycle through
different carriers at will (thereby listening in on calls). Their use is probably prohibited by most
carriers. The A, B, C and D tones are used in amateur radio phone patch and repeater operations
to allow, among other uses, control of the repeater while connected to an active phone
line.DTMF tones are also used by some cable television networks and radio networks to signal
the local cable company/network station to insert a local advertisement or station identification.
These tones were often heard during a station ID preceding a local ad insert. Previously,
terrestrial television stations also used DTMF tones to shut off and turn on remote transmitters.
DTMF tones are also sometimes used in caller ID systems to transfer the caller ID information,
however in the USA only Bell 202 modulated FSK signaling is used to transfer the data.
1.4. Keypad
The DTMF keypad is laid out in a 44 matrix, with each row representing a low
frequency, and each column representing a high frequency. Pressing a single key (such as '1' )
will send a sinusoidal tone of the two frequencies (697 and 1209 hertz (Hz)). The original
keypads had levers inside, so each button activated two contacts. The multiple tones are the
reason for calling the system multi frequency. These tones are then decoded by the switching
center to determine which key was pressed.
Page 128
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
The tone frequencies, as defined by the Precise Tone Plan, are selected such that
harmonics and inter modulation products will not cause an unreliable signal. No frequency is a
multiple of another, the difference between any two frequencies does not equal any of the
Digital Signal Processing Lab Manual
Page 129
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
frequencies, and the sum of any two frequencies does not equal any of the frequencies. The
frequencies were initially designed with a ratio of 21/19, which is slightly less than a whole tone.
The frequencies may not vary more than 1.8% from their nominal frequency, or the switching
center will ignore the signal. The high frequencies may be the same volume or louder as the low
frequencies when sent across the line. The loudness difference between the high and low
requencies can be as large as 3 decibels (dB) and is referred to as "twist." The minimum duration
of the tone should be at least 70 msec, although in some countries and applications DTMF
receivers must be able to reliably detect DTMF tones as short as 45ms.
Page 130
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Chapter 2
Goertzel algorithm
2.1. Introduction
The Goe rtzel algorithm is a digital signal processing (DSP) technique for identifying
frequency components of a signal, published by Dr. Gerald Goertzel in 1958.While the general
Fast Fourier transform (FFT) algorithm computes evenly across the bandwidth of the incoming
signal, the Goertzel algorithm looks at specific, predetermined frequency.
The basic Goertzel gives you real and imaginary frequency components as a regular
Discrete Fourier Transform (DFT) or FFT would. If you need them, magnitude and phase can
then be computed from the real/imaginary pair.
The optimized Goertzel is even faster (and simpler) than the basic Goertzel, but doesn't
give you the real and imaginary frequency components. Instead, it gives you the relative
magnitude squared. You can take the square root of this result to get the relative magnitude (if
needed), but there's no way to obtain the phase.
Before you can do the actual Goertzel, you must do some preliminary calculations:
1. Decide on the sampling rate.
2. Choose the block size, N.
3. Precompute one cosine and one sine term.
4. Precompute one coefficient.
These can all be precomputed once and then hardcoded in your program, saving RAM and ROM
space; or you can compute them on-the-fly.
(i) Sampling rate
Your sampling rate may already be determined by the application. For example, in
telecom applications, it's common to use a sampling rate of 8kHz (8,000 samples per second).
Alternatively, your analog-to-digital converter (or CODEC) may be running from an external
clock or crystal over which you have no control.
If you can choose the sampling rate, the usual Nyquist rules apply: the sampling rate
will have to be at least twice your highest frequency of interest. I say "at least" because if you are
Digital Signal Processing Lab Manual
Page 131
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
detecting multiple frequencies, it's possible that an even higher sampling frequency will give
better results. What you really want is for every frequency of interest to be an integer factor of
the sampling rate.
(ii) Block size
Goertzel block size N is like the number of points in an equivalent FFT. It controls the
frequency resolution (also called bin width). For example, if your sampling rate is 8kHz and N is
100 samples, then your bin width is 80Hz.
This would steer you towards making N as high as possible, to get the highest frequency
resolution. The catch is that the higher N gets, the longer it takes to detect each tone, simply
because you have to wait longer for all the samples to come in. For example, at 8kHz sampling,
it will take 100ms for 800 samples to be accumulated. If you're trying to detect tones of short
duration, you will have to use compatible values of N.
The third factor influencing your choice of N is the relationship between the sampling rate
and the target frequencies. Ideally you want the frequencies to be centered in their respective
bins. In other words, you want the target frequencies to be integer multiples of sample rate/N.
The good news is that, unlike the FFT, N doesn't have to be a power of two.
(iii) Pre computed constants
Once you've selected your sampling rate and block size, it's a simple five-step process to
compute the constants you'll need during processing:
w = (2*/N)*k
cosine = cos w
sine = sin w
coeff = 2 * cosine
For the per-sample processing you're going to need three variables. Let's call them Q0,Q1, and
Q2.
Q1 is just the value of Q0 last time. Q2 is just the value of Q0 two times ago (or Q1 last time).
Q1 and Q2 must be initialized to zero at the beginning of each block of samples. For every
sample, you need to run the following three equations:
Q0 = coeff * Q1 - Q2 + sample
Q2 = Q1
Digital Signal Processing Lab Manual
Page 132
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Q1 = Q0
After running the per-sample equations N times, it's time to see if the tone is present or not.
real = (Q1 - Q2 * cosine)
imag = (Q2 * sine)
magnitude2 = real2 + imag2
A simple threshold test of the magnitude will tell you if the tone was present or not. Reset
Q2 and Q1 to zero and start the next block.
2i ,
+ 2i
addition and one subtraction per input sample. For real inputs, these operations are real.
Page 133
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Note that applying the additional transform Y(z)/S(z) only requires the last two samples of the s
sequence. Consequently, upon processing N samples x(0)...x(N 1), the last two samples from
the s sequence can be used to compute the value of a DFT bin which corresponds to the chosen
frequency as
X() = y(N 1)e 2i(N 1) = (s(N 1) e 2is(N 2))e 2i(N 1)
For the special case often found when computing DFT bins, where N = k for some integer, k,
this simplifies to
X() = (s(N 1) e 2is(N 2))e + 2i = e + 2is(N 1) s(N 2)
Digital Signal Processing Lab Manual
Page 134
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
In either case, the corresponding power can be computed using the same cosine term required to
compute s as
X()X'() = s(N 2)2 + s(N 1)2 2cos(2)s(N 2)s(N 1)
When implemented in a general-purpose processor, values for s(n 1) and s(n 2) can be
retained in variables and new values of s can be shifted through as they are computed, assuming
that only the final two values of the s sequence are required. The code may then be as follows:
Page 135
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
or if, for some reason, N is not an integral power of 2 while you stick to a simple FFT algorithm
like the 2-radix Cooley-Tukey FFT algorithm, and zero-padding the samples out to an integral
power of 2 would violate
Moreover, the Goertzel algorithm can be computed as samples come in, and the
FFTalgorithm may require a large table of N pre-computed sines and cosines in order to be
efficient.
If multiplications are not considered as difficult as additions, or vice versa, the 5/6 ratio can
shift between anything from 3/4 (additions dominate) to 1/1 (multiplications dominate).
Page 136
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
One additional problem is that the algorithm will sometimes produce spurious outputs
because of a window period that is not completely filled with samples. Imagine a DTMF tone
burst and then imagine the window superimposed over this tone burst.Obviously, the detector is
running at a fixed rate and the tone burst is not guaranteed to arrive aligned with the timing of
the detector. So some window intervals on the leading and trailing edges of the tone burst will
not be entirely filled with valid tone samples.Worse, RC-based tone generators will often have
voltage sag/surge related anomalies at the leading and trailing edges of the tone burst. These also
can contribute to spurious outputs.
It is highly likely that this detector will report false or incorrect results at the leading and
trailing edges of the tone burst due to a lack of sufficient valid samples within the window. In
addition, the tone detector must be able to tolerate tone dropouts within the tone burst and these
can produce additional false reports due to the same windowing effects.
The post-processing system can be implemented as a statistical aggregator which will
examine a series of outputs of the algorithm below. There should be a counter for each possible
output. These all start out at zero. The detector starts producing outputs and depending on the
output, the appropriate counter is incremented. Finally, the detector stops generating outputs for
long enough that the tone burst can be considered to be over.
The counter with the highest value wins and should be considered to be the DTMF digit
signaled by the tone burst.While it is true that there are eight possible frequencies in a DTMF
tone, the algorithm as originally entered on this page was computing a few more frequencies so
as to help reject false tones (talk off). Notice the peak tone counter loop. This checks to see that
only two tones are active. If more than this are found then the tone is rejected.
Page 137
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Chapter 3
MATLAB Simulation Codes
3.1. Matlab Code for DTMF Tone Generator :
close all;
clear all
figure(1)
% DTMF tone generator
fs=8000;
t=[0:1:204]/fs;
x=zeros(1,length(t));
x(1)=1;
y852=filter([0 sin(2*pi*852/fs) ],[1 -2*cos(2*pi*852/fs) 1],x);
y1209=filter([0 sin(2*pi*1209/fs) ],[1 -2*cos(2*pi*1209/fs) 1],x);
y7=y852+y1209;
subplot(2,1,1);plot(t,y7);grid
ylabel('y(n) DTMF: number 7');
xlabel('time (second)')
Ak=2*abs(fft(y7))/length(y7);Ak(1)=Ak(1)/2;
f=[0:1:(length(y7)-1)/2]*fs/length(y7);
subplot(2,1,2);
plot(f,Ak(1:(length(y7)+1)/2));grid
ylabel('Spectrum for y7(n)');
xlabel('frequency (Hz)');
Page 138
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 139
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 140
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 141
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Chapter 4
Comparison of Goertzel Algorithm and FFT
While the general Fast Fourier transform (FFT) algorithm computes evenly across the bandwidth
of the incoming signal, the Goertzel algorithm looks at specific,predetermined frequency
4.1. Matlab Code:
%++++++++++++++++++++++++++++++++++++++++++++++++++++++
% Filename: Goertz.m
%
% Compares the Goertzel algorithm with
% a standard FFT. (That is, the final output of
% the Goertzel filter should be equal to a
% single FFT-bin result.)
%
% NSSV Prasad - May, 2008
%++++++++++++++++++++++++++++++++++++++++++++++++++++++
Fsub_i = 30; % Tone freq to be detected, in Hz.
Fsub_s = 128; % Sample rate in samples/second.
N =64;
% Define the Goertzel filter coefficients
B = [1,-exp(-j*2*pi*Fsub_i/Fsub_s)]; % Feed forward
A = [1,-2*cos(2*pi*Fsub_i/Fsub_s),1]; % Feedback
[H,W] = freqz(B,A,N,Fsub_s); % Freq resp. vs omega
MAG = abs(H);
PHASE = angle(H).*(180/pi); % Phase in degrees
% Plot the Goertzel filters freq response
figure(1)
subplot(2,1,1), plot(W,MAG,W,MAG,o,markersize,4), grid
title(Filter Magnitude Resp.)
xlabel(Hz)
subplot(2,1,2), plot(W,PHASE,W,PHASE,o,markersize,4), grid
title(Filter Phase Resp. in Deg.)
xlabel(Hz)
Digital Signal Processing Lab Manual
Page 142
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 143
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
FFT computes all DFT values at all indices, while GOERTZEL computes DFT
values at a specified subset of indices (i.e., a portion of the signals frequency range). If
less than log2 (N) points are required, GOERTZEL is more efficient than the Fast
Digital Signal Processing Lab Manual
Page 144
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Page 145
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Chapter 5
Conclusion
This project gives an understanding of the DTMF tone generation and the DTMF
decoding algorithm (The GOERTZEL algorithm) using MATLAB.
A tone of the digit 7 was generated and detected using Goertzel algorithm. And the
Goertzel algorithm was compared with the single FFT. the Goertzel algorithm looks at specific,
predetermined frequency, while the general Fast Fourier transform (FFT) algorithm computes
evenly across the bandwidth of the incoming signal. The Goertzel algorithm can perform tone
detection using much less CPU horsepower than the Fast Fourier Transform.
This project can be extended for the generation of tones of a series of digits using the code
proposed in this report, as a MATLAB function.
Page 146
www.jntuworld.com
www.jntuworld.com
Department of Electronics and Communication
VCET,Hyderabad.
Chapter 6
References
1. Digital Signal Processing Using MATLAB, (Bookware Companion Series): Vinay K. Ingle,
John G. Proakis, PWS Publishing Company. Pp. 405-409.
2. Understanding Telephone Electronics, 4th edition, By Stephen J. Bigelow, Joseph J. Carr,
Steve Winder,Published by Newnes, 2001,
3. Digital Signal Processing and Applications with the C6713 and C6416 DSK , By Rulph
Chassaing, A John Wiley & Sons Inc., Publication, 2005, pp 347-348.
4. Mitra, Sanjit K. Digital Signal Processing: A Computer-Based Approach. New York, NY:
McGraw-Hill, 1998, pp. 520-523.
5. www.crazyengineers.com/forum/electrical/dtmf_geort.html
6. www.en.wikipedia.org/dtmf.html
7. www.dsprelated.com/dtmf.html
Page 147
www.jntuworld.com