0% found this document useful (1 vote)
187 views69 pages

EC106 Advance Digital Signal Processing Lab Manual On Digital Signal Processing

This document provides an introduction to MATLAB. It discusses getting started with MATLAB, basic matrix calculations, using commands repeatedly, generating vectors with colons, subscripting matrices, creating functions and scripts, and provides examples of simple MATLAB functions.

Uploaded by

SHARAD FADADU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
187 views69 pages

EC106 Advance Digital Signal Processing Lab Manual On Digital Signal Processing

This document provides an introduction to MATLAB. It discusses getting started with MATLAB, basic matrix calculations, using commands repeatedly, generating vectors with colons, subscripting matrices, creating functions and scripts, and provides examples of simple MATLAB functions.

Uploaded by

SHARAD FADADU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 69

ADSP Lab S.V.N.I.T.

EC106 Advance Digital Signal Processing


Lab Manual on Digital Signal Processing

Prof. S. Patanaik

Prof. Mehul C. Patel

Electronics Engineering Department

Sardar Vallabhbhai National Institute of


Technology,

Ichchhanath, Surat-395007

P10EC949 Page:-1
ADSP Lab S.V.N.I.T.

List of Experiments

1. Introduction to MATALB……………………………………………………………….3

2. Practices with MATLAB………………………………………………………………11

3. Dual Tone Multi Frequency (DTMF) Generator………………………………………20

4. Dual Tone Multi Frequency (DTMF) Receiver………………………………………..24

5. Chirp Signal Generator………………………………………………………………...34

6. Adaptive Echo Cancellation Using LMS (Least Means Square) Algorithm…………..38

7. Double Talk Suppression Using LMS (Least Means Square) Algorithm……………...47

8. Introduction To Music Synthesis………………………………………………………49

9. DSP Processor Introduction and Basic applications…………………………………...53

10. Real Time Filters Implementation Using DSK 6713…………………………………..64

P10EC949 Page:-2
ADSP Lab S.V.N.I.T.

LABORATORY-01
INTRODUTION TO MATLAB

1) Getting started:

Matlab was originally a package for matrix algebra. It has evolved to include strong
graphics abilities and an extensive programming language. It is available, in various
versions, for various types of hardware. On most of these systems Matlab will be started by
entering the command: “matlab”

At the command prompt, this can however differ, depending on the whims of your
system administrator. The command to exit Matlab is: “exit”

You can interrupt, or abort, execution of Matlab commands by entering a control C.


To do this hold down the control key and, before releasing it, press the C key.

2) Matlab as a simple matrix calculator

The basic object in Matlab is a rectangular matrix with real or complex entries. Thus
even a constant is viewed by Matlab as a 1 × 1 matrix.

In entering a matrix, separate the elements in a row by spaces or commas, separate


the rows by semi-colons, or by end of line characters. Thus the2 × 2 matrix

a= 1 2
[ ]
3 4

Could be entered with the command a = [ 1, 2; 3, 4 ] or a = [ 1 2

34]

Similarly the 2 × 1 vectora= [11]could be entered with the command : x = [ 1 ; 1 ] or the


command : x = [ 1 1 ]’ where the prime ( ‘ ) directs matlab to compute the transpose.

The three basic matrix arithmetic operations +, −, and × are represented naturally by
+, −, and ∗. The function “inv()” calculates the matrix inverse. For square matrices
backslash, or left matrix division, is related to left multiplication by an inverse, but is
computed using Gaussian elimination. Thus A\b is roughly equivalent to “inv(A)*b”.
Exponentiation is represented by^.

P10EC949 Page:-3
ADSP Lab S.V.N.I.T.

Matlab includes many other functions. For a listing of these simply enter the
command help. For help on a particular command specify its name after the word help. For
example help size will tell you how to determine the shape of matrix.

To compute operations on an element by element basis use the (.) operator. Thus for
example “C = X. *Y” computes the element by element product of X and Y putting the
result in the corresponding elements of C. Similarly “A.^3” stands for the element by
element power, rather than the matrix power and “A./B” for element by element division.

The format or number of significant figures which Matlab uses to display its answers
controlled by the format command. The options are

Format Example
format short 1.5000
format short e 1.5000E+000
format long 1.500000000000000
format long e 1.500000000000000E+100

3) Repeated commands

The up-arrow key can be used to recall previous Matlab commands. Thus a
surprisingly effective method for performing a short series of similar operations is the
following. Firstly recall the appropriate previous command using the up and down arrow
keys. Then edit it using the left and right arrow keys, and the delete, insert and backspace
keys. Finally issue the newly modified command with the enter key.

The colon operator (:)is a simple method of generating a vector of equally spaced
values. The syntax of the command is “variable = start[:increment]:end”

Where, the square brackets indicate that the increment term may be omitted. In that
case the increment defaults to 1. Thus x = 1:4generates the row vector x = [ 1, 2, 3, 4

The same vector could be generated, less efficiently, with a for loop

for k = 1:4
x(k) = k;
end

The semi-colon in the statement x(k) = k; above, has been included to suppress
printing of the result of the statement. A typical use of the for loop would be generation of
data for graphing as in the following code

h = .04

P10EC949 Page:-4
ADSP Lab S.V.N.I.T.
for k = 1:51
x(k) = (k-1)*h*pi;
y(k) = sin(x(k));
end
plot(x,y)

This generates a plot of sin(x). Matlab’s execution can be speeded up by factors of


up to twenty five by factorization. The following factorized code is faster than the previous
for loop.

x = 0:0.04*pi:2*pi ; y = sin(x); plot(x,y)

In the above, the single statement y = sin(x), takes the sine of all 51elements of x and
puts the result in the corresponding elements of the vector. In Matlab functions may be
applied in this element by element manner to arrays.

4) Subscripting, rows, columns and blocks

Matlab’s subscripts begin at 1. Thus if x is a row vector with 5 elements these are
numbered x(1), . . . , x(5), rather than starting with x(0). Arrays are subscripted in the usual
manner, with A(3,3) for example standing fora33.

Powerful vector subscripts are also allowed so that A(3:4,3:4) specifies the 2 × 2 sub
matrix of A with top left element a33. A colon (:) by itself represents all of a row or column.
Thus elementary row or column operations may be performed easily in Matlab. For example
the following command would subtract 3 times the second row of matrix A from the first
and store the result back in the first row of A.

A(1,:) = A(1,:) - 3*A(2,:)

5) Functions and scripts

A script is a file with file type “.m” containing a list of Matlab commands. Invoking
a script file is the same as issuing these commands, one by one, from the keyboard.

A function file differs from a script in that it has specific input and output
parameters. Variables changed within a function are local, and a function changes the
workspace only by the assignment of its output to a variable, or variables. As is usual for a
high level language, the actual parameters (with which the function is called) and the formal
parameters (named in called) and the formal parameters (named in the statement of the
function) may differ.

P10EC949 Page:-5
ADSP Lab S.V.N.I.T.

The first example is a simple function to evaluate the g(x) = x 2 − 2x.The following
lines would be edited into the file “g.m”.

function [y]=g(x) % g(x)= x*x-2*x


y = x*x-2*x;

The function could then be invoked by issuing the command “u = g(1.5)” from
within matlab. (Reminder: It is very important not to put extra spaces in Matlab expressions
such as x*x-2*x as Matlab interprets space as a separator between elements in a row.)

The second example is a system of three function files for performing one step of a
simple Newton iteration to find a zero of a function of two variables.

function [v]=f(x) % Evaluate the vector valued function f


and return
% the result.%
% Syntax [v]=f(x)
v = [ x(1)*x(1)+x(2)*x(2)-2
exp(x(1)-1)+x(2)^3 -2];

function [a]=jac(x) % Evaluates Jacobian of function f


% at a point %% Syntax [a]=jac(x)
a = [ 2*x(1) 2*x(2)
exp(x(1)-1) 3*x(2)*x(2) ];

function [v]=nr(x) % Makes a single step of Newton’s method


for finding
% a zero of a function of several
variables.

% Calls functions f and jac.

% Syntax[v]=nr(x)

v = x-jac(x)\f(x);

These files would be created with an editor and named “f.m”, “jac.m” and “nr.m”
respectively. Then issuing the commands “X = [2 2]” & “x=nr(X)” would perform one step
of Newton’s method starting from x = (2, 2).

The percentage sign (%) in the above examples starts a comment.

Typing help function name, as well as giving help on Matlab’s built in commands,
will print any initial block of comments in a user defined function.

P10EC949 Page:-6
ADSP Lab S.V.N.I.T.

6) Input and output

If the file filename contains a rectangular array of figures with blanks as a separator
within rows, then the command load file name will load the array into Matlab’s workspace
giving it a name formed by stripping the file type (the stuff from the “.” on) off the file
name. Conversely, the command “save variable name filename /ascii” will create a file
filename containing the variable name in ascii readable form.

Another way of importing data is via script files. For example, if the file “def x.m”
contained the lines x = [ 1 2 ; 3 4; 5 6] then the command def x would cause this script to
execute, thus defining x. A simple means for displaying data and text is the disp command.
Forexample the command

disp(’This program solves band systems’);

will display the message on a line. disp can also be used to display data. For example
if x is the 1×3 vector [1, 2, 3] and the current format option is short then disp(x); will result
in the output“1.0000 2.0000 3.000” Note that disp does not echo the name of the variable as
the command x would.

For greater control of the output format of numeric quantities use the C–like
command fprintf. The syntax of fprintf is “fprintf([filename,] format [,x,y,z])”where the
square brackets indicate that the filename, and the numeric arguments x, y, z, may be
omitted.

If the filename is omitted output is sent to the screen. If the filename option is used
and file filename does not exist then it is created. If it does exist, then the output is appended
to it. The format string specifies how the numbers are to be printed. Legal format specifies
are %e, %f and %g.

Optionally a string of the form n.m can be placed between the % and the conversion
character. The number to the right of the decimal specifies minimum field width and the
number to the left, the number of decimal places. Finally to insert a newline character in the
output string use the C format specifier \n. The following is an example of a script file
which creates a row vector with six elements and then prints these out using two fprintf
statements.

a = [1 2 3 4 5 6];
fprintf (’%e %e %e’,a(1),a(2),a(3));
fprintf (’%e %e %e \n’,a(4),a(5),a(6));

The next example prints out a table of values k2 against k.


P10EC949 Page:-7
ADSP Lab S.V.N.I.T.
for k=0:5
fprintf(’k = %3.0f k squared = %6.0f \n’,k,k*k);
end

An alternative to fprintf-ing to a file is to use the diary command. An initial


command “diary filename” erases the file filename and causes subsequent input and non-
graphics output to be echoed to this file. Echoing of input and output to the file can be
turned off and on mid-session with the commands “diary off”, “diary on”

At the end of the Matlab session the diary file may be edited or sent to the printer. A
function or script can prompt for input using the input command.

For example the line, n = input(’Enter the value of n : ’) will issue the prompt Enter the . . .
and wait for the user to type in a number. When the user presses Enter the number entered
will be assigned to the variable n. There is also a string version of the input command whose
syntax is “variable = input(prompt string,’s’)”

For example the following code shows how to execute a loop a user specified
number of times.

ans = ’y’;
while ˜strcmp(ans,’n’)
% while not string compare (ans,’n’)
% So anything but ’n’ continues! Even the
% empty string.
ans = input(’Continue y/n [y] ? : ’,’s’);
end % while

Another useful command is pause, which causes processing to stop until a key is
pressed, or until a specified number of seconds has elapsed. In the form pause it waits for
any key to be pressed. This is used to leave outputs displayed until they have been read – as
in:

disp(’The computed solution to the system is’);


disp(x);
fprintf(’\n \n Press any key to continue’)
pause(1); %It waits n seconds before continuing.

7) Conditional branching

Matlab has the following relational operators: <, <=, >, >=, == and˜=, which can be
used in comparing matrices of equal dimension. The == and˜= operators test for equality

P10EC949 Page:-8
ADSP Lab S.V.N.I.T.

and non-equality respectively. The output of a comparison is a matrix of zeros and ones, of
the same size (often 1 × 1) as the input matrices. The value one standing for TRUE and zero
for FALSE. The relational operators may be used in conjunction with the, if and while
statements to control the flow of a program.

For example consider evaluating the function

0if x =0
f ( x )=
{ 2
x ∗log|x|if x ≠ 0

This is a perfectly well defined, and smooth, function with f(0) = 0.However, trying
numerically to evaluate log(x), with x very small or zero, would cause an error. After all
log(0) is undefined! This problem can be avoided by using an if statement as in the
following function file.

function u=f(x) % Evaluate a thin plate spline in one


dimension
u = abs(x); % eps is a Matlab reserved variable
containing the machine epsilon.
if u < eps % u is very close to zero so avoid attempting
to
% evaluate log by using instead a Taylor
series approximation to f.
u = 0;
else
u = u*u*log(u);end

This if statement has an optional else i clause and so can operate like the case
statement of many computer languages.

8) Finishing touches

The Matlab function feval enables one to pass function names as parameters. The
syntax of the command is which evaluates function(x1, . . . ,xn)

feval(’function’,x1,. . .,xn)

For example the function my plot below will plot a user specified function on the
domain [ -4, 4]

function myplot()
fnm =input(’Enter a function name e.g. sin ’,’s’);
x = -4:.1:4;
y = feval(fnm,x);

P10EC949 Page:-9
ADSP Lab S.V.N.I.T.
plot(x,y);

As with some other computer languages it is not necessary to supply all the formal
input or output parameters when calling a function. The reserved variable margin records
the number of input variables a Matlab function was called with, while ragout records the
number of output variables. By testing nargin your Matlab functions can supply reasonable
defaults for omitted parameters, or print helpful messages. For example, the function plus
below prints a helpful message if it is called with insufficient parameters

function u = plus(x,y)
if nargin < 2
disp(’Insufficient parameters supplied !’);
disp(’The desired syntax is ’);
disp(’ u = plus(x,y) ’);
return
end % if
u = x+y;

P10EC949 Page:-10
ADSP Lab S.V.N.I.T.

LABORATORY-02
PRACTICES WITH MATALAB

EXERCISES:

1. Represent different Basic signal


(a) Generate Unit impulse signal
(b) Generate Unit step sequences [ u(n) – u(n-N)]
(c) Generate Ramp signal.
(d) Generate Exponential signal
(e) Generate Sine wave & Cosine signal
2. Determine Linear Convolution: Use sequence of inputs[ 11 1 21 ] ∧[1 1 21]. *
Underline is shown timing mark zero.
3. Circular Convolution: Use the above sequences.
4. Cross-correlation using FFT (Fast Fourier Transform).
Use sequence[ 11 1 01 1 ] ∧[1 11 1 11].
5. To compute the “DFT” of sequences and plot magnitude & phase response. Data is
[13 2 4 5 1 11 4 5 ]. (Hint: use function freqz).
6. Compute the overall impulse response of the system
7. A continuous time signalx ( t )consists of a linear combination of sinusoidal signals
of frequencies 300 Hz, 400 Hz, 1.3 KHz, 3.6 KHz and 4.3 KHz. The x ( t ) is
sampled at 4 KHz rate and the sampled sequences passed through an ideal low-
pass filter with cut-off frequency of 1 KHz, generating a continuous time signal
y ( t ) . What are frequencies components present in the reconstructed signal?

P10EC949 Page:-11
ADSP Lab S.V.N.I.T.

LABORATORY:-02

EXERCISES:-1
Represent different Basic signal
a. Generate Unit Impulse Signal
b. Generate Unit Step Sequence
c. Generate Unit Ramp Sequence
d. Generate Exponential Sequence
e. Generate Sine & Cosine Sequence

Program:-
clc; clear all;
N=41; k=1;
for n=0:1:N-1;
if(n==0)
del(k)=1;
else
del(k)=0;
end
m(k)=n; u(k)=1; r(k)=n; e(k)=(0.9^n);
sine(k)=sin(0.1*pi*n); cosine(k)=cos(0.1*pi*n);
k=k+1;
end
subplot(3,2,1); stem(m,del);
title('Unit Impulse Signal');
ylabel('del(n)');
subplot(3,2,2); stem(m,u);
title('Unit Step Sequence');
ylabel('u(n)');
subplot(3,2,3); stem(m,r);
title('Unit Ramp Sequence');
ylabel('r(n)');
subplot(3,2,4); stem(m,e);
title('Exponential Sequence');
ylabel('exp(n)')
subplot(3,2,5); stem(m,sine);
title('Sine Sequence');
xlabel('n'); ylabel('sin(n)')
subplot(3,2,6); stem(m,cosine);
title('Cosine Sequence');
xlabel('n'); ylabel('cos(n)')

P10EC949 Page:-12
ADSP Lab S.V.N.I.T.

Output Waveform:-

P10EC949 Page:-13
ADSP Lab S.V.N.I.T.

EXERCISES:-2&3
Use sequence of input [ 11 1 21 ] & [ 11 2 1 ]. *Underline is shown timing mark zero.
Derive: 1) Linear Convolution & 2) Circular Convolution.

Program:-
clc; clear all; close all;
x=[-2 -1 0 1 2;1 1 1 2 1]; h=[-2 -1 0 1;1 1 2 1];
x1=x(2,:); h1=h(2,:);
n1=length(x1); n2=length(h1); n=n1+n2;
for m=2:n,
yl(1,m-1)=x(1,1)+h(1,1)+m-2; yl(2,m-1)=0;
for k=1:n;
if(k<=n1 && k>=1 && m-k<=n2 && m-k>=1)
yl(2,m-1)=yl(2,m-1)+x1(k)*h1(m-k);
end
end
end
N=max(n1,n2);
if(N==n1)
yc(1,:)=x(1,:); h1=[h1 zeros(1,N-n2)];
else
x1=[x1 zeros(1,N-n1)];
end
for r=1:N,
for c=1:N,
q=mod(r-c,N); H(r,c)=h1(q+1);
end
end
yc(2,:)=H*x1';
subplot(2,2,1); stem(x(1,:),x(2,:));
title('Input Sequence x'); ylabel('x(n)');
set(gca,'xtick',(-2:2),'ytick',(1:2));
subplot(2,2,2); stem(h(1,:),h(2,:));
title('Input Sequence h'); ylabel('h(n)');
set(gca,'xtick',(-2:2),'ytick',(1:2));
subplot(2,2,3); stem(yl(1,:),yl(2,:));
title('Output Sequence (Linear Convolution)');
xlabel('n'); ylabel('y_l(n)');
set(gca,'ytick',(1:6),'xtick',(-4:3),'xlim',[-4 3]);
subplot(2,2,4); stem(yc(1,:),yc(2,:));
title('Output Sequence (Circular Convolution)');
xlabel('n'); ylabel('y_c(n)');
set(gca,'xtick',(-2:2),'ytick',(1:7),'ylim',[1 7]);

P10EC949 Page:-14
ADSP Lab S.V.N.I.T.

Output:-

P10EC949 Page:-15
ADSP Lab S.V.N.I.T.

EXERCISES:-4
Find Cross-Correlation (Using FFT) of sequences [ 11 1 01 1 ] & [ 11 11 1 1 ].

Program:-

clc; clear all;


x1=[1 1 1 0 1 1];
x2=[1 1 1 1 1 1];
n1=length(x1); n2=length(x2);
n=n1+n2-1;
FFT1=fft(x1,n);
FFT2=fft(x2,n);
RX1X2=conj(FFT1).*FFT2;
rx1x2=ifft(RX1X2);
stem(rx1x2);
title('Cross-Corelation of Sequences x_1 & x_2');
xlabel('k'); ylabel('r x_1x_2');
set(gca,'ytick',(1:5))

Output:-

P10EC949 Page:-16
ADSP Lab S.V.N.I.T.

EXERCISES:-5
Compute the DFT of the sequence[ 12 3 4 5 1 11 4 5 ], and plot Magnitude & Phase
response. (Hint: Use function freqz).

Program:-
clc; clear all;
x=[1 2 3 4 5 1 1 1 4 5];
[h w]=freqz(x);
subplot(1,2,1)
plot(w/(2*pi),abs(h));
title('Magnitude Responce of x(n)');
xlabel('Normalized Frequency'); Ylabel('|X(f)|')
set(gca,'xlim',[0 0.5],'xtick',(0:0.1:0.5));
subplot(1,2,2)
plot(w/(2*pi),angle(h)*180/pi);
title('Phase Responce of x(n)');
xlabel('Normalized Frequency'); Ylabel('Arg (X(f))')
set(gca,'xlim',[0 0.5],'xtick',(0:0.1:0.5));
set(gca,'ylim',[-180 180],'ytick',(-180:90:180));

Output:-

P10EC949 Page:-17
ADSP Lab S.V.N.I.T.

EXERCISES:-7
A continuous time signal x (t ) is consists of a linear combination of sinusoidal
signals of frequencies 300 Hz , 400 Hz ,1.3 KHz , 3.6 KHz ∧4.3 KHz, is sampled at 4 KHz rate
and the sampled sequences passed through an ideal low-pass filter with cut-off frequency of
1 KHz, generating a continuous time signal y (t).What are frequencies components present
in the reconstructed signal?

Program:-
clc; clear all;
f=[300 400 1300 3600 4300];
Fs=4000; N=512;
t=(0:N-1)/Fs;
x=sum(sin(2*pi*f(:)*t));
subplot(2,2,1)
plot(t*1e3,x); set(gca,'xlim',[0 50])
title('Signal x(t) When fs=4000 Hz');
xlabel('Time (ms)'); ylabel('x(t)');
[h1 w1]=freqz(x);
subplot(2,2,2);
plot(w1*Fs/(2000*pi),abs(h1))
title('Amplitude Spectrum (1-Sided) of x(t), N=512')
xlabel('Frequency (KHz)'); ylabel('|X(f)|')
set(gca,'xtick',f/1000,'Fontsize',8)
for n=1:length(h1)
if(w1(n)*Fs/(2*pi)<=1000)
H(n)=1;
else
H(n)=0;
end
Y(n)=H(n)*h1(n);
end
subplot(2,2,3);
plot(w1*Fs/(2000*pi),abs(H));
set(gca,'xtick',1);
title('Amplitude Spectrum (1-Sided) of Low Pass Filter');
xlabel('Frequency (KHz)'); ylabel('|h(f)|');
subplot(2,2,4)
plot(w1*Fs/(2000*pi),abs(Y));
title('Amplitude Spectrum (1-Sided) of y(t)');
xlabel('Frequency (KHz)'); ylabel('|Y(f)|');
set(gca,'xtick',f/1000,'Fontsize',8);

P10EC949 Page:-18
ADSP Lab S.V.N.I.T.

Output:-

Reconstructed signal has frequency component of 300 Hz only.

P10EC949 Page:-19
ADSP Lab S.V.N.I.T.

LABORATORY-03
DUAL TONE MULTI-FREQUENCY (DTMF) GENERATOR

INTRODUCTION

A common application of sine wave generator is the all-digital touch-tone phone that
uses dual tone multi-frequency (DTMF) transmitter and receiver. DTMF also finds
widespread use in electronics mail systems and automated telephone servicing system in
which the user can select options from menu by sending DTMF signal from a telephone.

Each key-press on the telephone keypad generate sum of two tones expressed as

x ( n )=cos (2 π f L nT )+ cos(2 π f H nT )

Where, T is the sampling period and the two frequencies f L and f H uniquely define
the key that was pressed. Figure shows the matrix of sine wave frequencies used to encode
16 DTMF symbols. The values of the eight frequencies have been chosen carefully so that
they do not interfere with speech.

The low frequency group (697, 770, 852 & 941 Hz) select the four rows
frequencies of the 4 x 4 keypad, and high frequency group (1209, 1336, 1477, & 1633 Hz)
select columns frequencies. A pair of sinusoidal signals with f L from, the low-frequency
group and f H from the high frequency group will represent a particular key. The digit ‘3’ is
represented by two sine waves at the frequencies 697 Hz & 1477 Hz. The row frequencies
are in the high frequency between 1 KHz & 2 KHz. The digits are displayed as they appear
on telephone’s 4 x 4 matrix keypad, where the fourth column is omitted on standard
telephone sets.

P10EC949 Page:-20
ADSP Lab S.V.N.I.T.

On DSP kit the generated of dual tones can be implemented by using two sine wave
generators connected in parallel. Each sine wave generator can be realized using the
polynomials approximation technique, the recursive oscillator introduced, or the lookup-
table method. Usually, DTMF signal are interfaces to the analog world via a CODEC
(coder/decoder) chip with an 8 KHz sampling rate.

The DTMF signal must meet timing requirements for duration and spacing of digit
tones. Digits are required to be transmitted at rate less than 10/second. A minimum spacing
of 50ms. A tone-detection scheme used to implement a DTMF receiver must have sufficient
time resolution to verify correct digit timing.

MATLAB ALGORITHMS:

First touch tones had to be understood and synthesized, and then using filtering each
had to be decoded to produce the original key sequence that generated it. The end result was
a dialing and decoding system like that of a phone.

Generating Touch Tones

A touch tone is made up of two frequencies corresponding to the keys position on


the grid of the phone. For instance, 5 is produce by playing a pure 1336 Hz sine wave and a
pure 770 Hz sine wave simultaneously. The result is the warble sound you hear.

FREQS 1209 Hz 1336 Hz 1477 Hz 1633 Hz


697 Hz 1 2 3 A
770 Hz 4 5 6 B
852 Hz 7 8 9 C
941 Hz * 0 # D

It was simple to code a function that would cycle through a list of characters (like a
phone number) and produce the corresponding waveform to simulate touch tones.

Sampling frequency Fs = 8000;

Number of Sample N = 800;


Matlab inbuilt function: audioplayer () see help

P10EC949 Page:-21
ADSP Lab S.V.N.I.T.

LABORATORY:-03

Aim:- Dual Tone Multi Frequency (DTMF) Generator.

Program:-
clc; clear all;
l=input('Enter the symbol:- ','s');
symbol=['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D']; %DTMF Keypad
f_row=[697 770 852 941];
f_col=[1209 1336 1477 1633];
for r=1:4,
for c=1:4,
if (symbol(r,c)==l) %Compare input symbol with Keypad
f=[f_row(r);f_col(c)];
%If Same than store the row & col freqs
end
end
end
Fs=8000; N=800; %Sampling Freq=8 KHz
t=(0:N-1)/Fs;
y=sum(sin(f(:)*2*pi*t)); %Generation of DTMF for input Symbol
plot(t*1e3,y); %Plot and all GUI title and label
title(['Tone For Symbol "',l,'"
[',num2str(f(1)),'Hz+',num2str(f(2)),'Hz]']);
xlabel('Time (ms)');
ylabel('Amplitude');
p=audioplayer(y,Fs); play(p);

Output:- *For N=320 & Fs=4000

Enter the symbol:- B

P10EC949 Page:-22
ADSP Lab S.V.N.I.T.

*For N=540 & Fs=6000

Enter the symbol:- 5

*For N=800 & Fs=8000

Enter the symbol:- *

Conclusion:-
From above we concluded that total time of DTMF tone is depend up on the Number
of samples N and Sampling frequency Fs, In real applications to detect DTMF tone

P10EC949 Page:-23
ADSP Lab S.V.N.I.T.

correctly tone time must ≥ 25 msec and most system has Fs=8 KHz. So, tone generator
requiresN ≥320.

LABORATORY-04
DUAL TONE MULTI-FREQUENCY (DTMF) RECEIVER

INTRODUCTION

There are different methods used for DTMF tones used in the communication
networks. The correct detection of a digit requires both valid tone pair and the correct
timing intervals. DTMF signaling is used both to set up a call and to control features such as
call forwarding and teleconferencing calling. In some applications, it is necessary to detect
DTMF signaling in the presences of speech, so it is important that the speech waveform is
not interpreted as valid signaling tones.

SPECIFICATIONS

The DTMF receiver involves the detection of the signaling tones, validation of
correct tone pair, and the timing to determine that digit is present for the correct amount of
time and with the correct spacing between tones. In addition, it is necessary to perform
additional tests to improve the performances of the decoder in the presences of speech. A
DSP implementation is useful in applications in which the digitized signal is available and
several channels need to be processed such as in a private branch exchange.

DTMF receivers are required to detect frequencies with tolerances of +1.5% as valid
tones. Tones that are offset by + 3.5% or greater must not be detected. This requirement is
necessary to prevent the detector from falsely detecting speech and other signals as valid
DTMF digits. The receiver is required to work with a worst-case signal-to-noise ratio of 15
dB and with a dynamic range of 26 dB.

P10EC949 Page:-24
ADSP Lab S.V.N.I.T.

Another requirement of the receiver is ability to detect DTMF signal when two tones
are received at different levels. The high-frequency tone received at a lower level than the
low-frequency tone due to the magnitude response of the communication channel. This level
differences is called twist occurs when the low-frequency tone is received at a lower level
than the high frequency tone. The receiver must operate with a maximum of 8 dB normal
twist and 4 dB reverse twist. A final requirement for the receiver is that it operates in the
presences of speech without incorrectly identifying the speech signal as valid DTMF tones.
This referred to as talk-off performances.

GOERTZAL ALGORITHM

The principal of DTMF detection is examine the energy of the signal at the DTMF
frequencies to determine whether a valid DTMF tone pair has been received. The detection
algorithm can be a DFT implementation using an FFT algorithm or a filter-bank
implementation. An FFT can be used to calculate the energies of N evenly spaced
frequencies. To achieve the frequency resolution required to detect the eight DTMF
frequencies within +1.5% frequency deviations, a 256-point FFT is needed for an 8 KHz
sample rate. For the relatively small number of tones to be detected, the filter-bank
implementation is more efficient.

Since only eight frequencies are of interest, it is efficient to use the DFT to compute
N −1
X ( k )= ∑ x ( n )∗W kn
N
n=0

For eight different k values that correspond to the DTMF frequencies defined in
previous exp. The DFT coefficient can be more efficiently calculated by using Gortzel
algorithm, which can be interpreted as a matched filter for each frequency k as illustrated in
figure. In this figure, x (n) is the input signal of the system, H k ( z ) is the transfer function of
the filter atk th frequency and X ( k ) is the corresponding filter output.

j(2 π / N )kN
Now we have, W −kn
N =e =e j 2 πk =1

Multiplying the right-hand side of equation byW −kn


N , we have

P10EC949 Page:-25
ADSP Lab S.V.N.I.T.
N−1 N −1
−kn kN
= ∑ x ( n )∗W −k(N −n)
X ( k )=W N ∑ x ( n )∗W N N
n=0 n=0

Define the sequences,


N−1
y k ( n )= ∑ x ( m )∗W −k(n−m)
N
m=0

This equation can be interpreted as a convolution of the finite-duration sequences


x ( m ) , 0 ≤n ≤ N−1, with the sequences W −kn
N ∗u (n).

Consequently y k ( n ) can be viewed as the output of a filter with impulse response


n
N ∗u( n). That is, the filter with impulse response, h k ( n ) =W N ∗u( n)
W −k −kn

Due to finite-length inputx (n). Thus Equation can be expressed as

y k ( n )=x ( n )∗W −kn


N u( n)

From above equation, the fact x ( n )=0for n< 0and n ≥ N ,we show that,

X ( k )= y k ¿n=N −1,

ThusX ( k ) is the output of filter H k ( z ) at timen=N−1.

Taking z-transform of output equation, we obtain

1
Y k ( z )=X ( z )
1−W −k −1
N z

The transfer function of the k th Gortzel filter is defined as

Y k(z) 1
H k ( z )= = k =0 , 1 ,2 … N−1
X (z ) 1−W −k
N z−1

This filter has a pole on the unit circle at the frequency ω k =2 πk /N . Thus the entire
DFT can be computed by filtering the block of input data using a parallel bank of N filters
defined by above equation, where each filter has a pole at the frequency of the DFT. Since
the Gortzel algorithm computes NDFT coefficients, the parameter N must be chosen to
make sure that X ( k ) is close to DTMF frequencies f k . This can be accomplished by choosing
N such that,

fk k
=
fs N

Where, f s=8 KHz for most of telecom systems.

P10EC949 Page:-26
ADSP Lab S.V.N.I.T.

A signal-flow diagram of transfer function H k ( z ) is depicted below figure. Since the

N are complex valued, the computation of each new value of y k ( n ) using figure
coefficientW −k
require four multiplications and additions. All the intermediary values
y k ( 0 ) , y k ( 1 ) , ... y k ( N−1 ) . must be computed in order to obtain the final output.
y k ( N−1 )= X (k ). Therefore the computational algorithm show below requires 4N complex
multiplications and additions to compute X ( k ) for each frequency index k.

The complex multiplications and additions can be avoided by combining the pair of
filters that have complex-conjugated poles. By multiplying both the numerator and the
denominator of H k ( z ) in equation by factor(1−W kN z−1 ), we have

1−W kN z −1 1−e j 2 πk / N z −1
H k ( z )= k −1
=
( 1−W −k −1
N z ) (1−W N z )
1−2 cos ( 2 πk /N ) z−1 + z−2

The signal-flow of the transfer function defined by above equation is shown in figure
using the direct-form II realization. The recursive part of the filter is on the left-hand side of
the delay elements, and the non-recursive part is on the right-hand side. Since the output
y k ( n ) is required only at timeN−1, we just need to compute the non-recursive part of the
filter at the N−1 th iteration.

[Flow Graph of recursive computation of X(k)]

[Detailed signal-flow diagram of Goertzel algorithm]

The recursive part of algorithm can be expressed as

w k ( n )=x ( n ) +2 cos ¿ ¿.

P10EC949 Page:-27
ADSP Lab S.V.N.I.T.

The non-recursive calculation of y k ( N−1 ) is expressed as

X ( k )= y k ( N −1 )=wk ( N−1 )−e− j 2 π f /fs


k
w k ( N−2).

A further simplification is made by realization that only the magnitude squared ofX ( k )is
2
needed for tone detection. Therefore| X (k )| can be computed as

2
| X (k )| =w2k ( N −1 )−2 cos ¿ ¿ ¿
Thus the complex arithmetic given is eliminated and energy equation requires only
2
one coefficient, 2 cos ¿ ¿for each | X (k )| to be evaluated. Since eight possible tones to be
detected, we need eight filter required.

IMPLEMENTATION CONSIDERATION

P10EC949 Page:-28
ADSP Lab S.V.N.I.T.

DTMF TONE DETECTION

Initialization

Get 8 KHz Frequency


Input signal No
Offset pass ?

Compute the Yes


Recursive Part of
No
The Goertzel filter
For 8-frequencies Total Energy
No
Test pass ?

Yes
n=N-1?

Yes 2nd Harmonic


Yes
too strong ?
Compute the Yes
Non-Recursive Part of No
The Goertzel filter
For 8-frequencies
D(m)=D(m-2) ? Yes

Magnitude > No
No
Threshold ?

D(m)=D(m-1) ? No
Yes

Yes
No Twist normal ?

Output Symbol

The flow chart of DTMF tone detection algorithm is shown below. At the beginning
of each frame of lengthN, the state variables x ( n ) , wk ( n ) , wk ( n−1 ) , w k ( n−2 ) and y k ( n ) for
each eight Gortzel filters and the energy are set to 0. For each sample, the recursive part of
2
each filter is executed. At the end of each frame, i.e.n=N−1, the squared magnitude| X (k )|
for each DTMF frequency is computed. The following tests are performed if valid DTMF
digit has been detected.

P10EC949 Page:-29
ADSP Lab S.V.N.I.T.

LABORATORY:-04

Aim:- a) Dual Tone Multi Frequency (DTMF) receiver (Using function Goertzel).

Program:-
clc; clear all;
l=input('Enter the symbol:- ','s');
symbol=['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D']; %DTMF Keypad
f_row=[697 770 852 941];
f_col=[1209 1336 1477 1633];
for r=1:4,
for c=1:4,
if (symbol(r,c)==l) %Compare input symbol with Keypad
f=[f_row(r);f_col(c)];
%If Same than store the row & col freqs
end
end
end
Fs=8000; N=800; %Sampling Freq=8 KHz
t=(0:N-1)/Fs;
y=sum(sin(f(:)*2*pi*t));
%Generation of DTMF for input Symbol
plot(t*1e3,y);
%Plot and add GUI title and label
title(['Tone For Symbol "',l,'"
[',num2str(f(1)),'Hz+',num2str(f(2)),'Hz]']);
xlabel('Time (ms)'); ylabel('Amplitude');
k=round([f_row f_col]/Fs*N);
%Find Goertzel’s index k for all possible freqs
ydft=goertzel(y,k+1);
%Find DFT using Goertzel’s Algorithm
estim_f = round(k*Fs/N);
%Calculate estimated freqs
[c1,i1]=max(abs(ydft(1:4))); %Identify Row freq
[c2,i2]=max(abs(ydft(5:8))); %Identify Col freq
my_f=[estim_f(i1) estim_f(i2+4)]; %Print in Command Window
fprintf('\n-> Approximate frequencies of Tone:- %dHz %dHz',my_f);
fprintf('\n\n-> Hence your input symbol is %c\n',symbol(i1,i2));
subplot(2,1,2); stem(estim_f,abs(ydft)); %Add GUI.
title ('Single-Sided Amplitude Spectrum of Above Tone');
set(gca,'XTick',estim_f,'xlim',[650 1650]);
xlabel('Frequency (Hz)'); ylabel('DFT Magnitude');

Output:-

P10EC949 Page:-30
ADSP Lab S.V.N.I.T.

*For N=320

Enter the symbol:- 8

-> Approximate frequencies of Tone:- 850Hz 1325Hz

-> Your input symbol is 8

*For N=800
P10EC949 Page:-31
ADSP Lab S.V.N.I.T.
Enter the symbol:- 8

-> Approximate frequencies of Tone:- 850Hz 1340Hz

-> Your input symbol is 8

Conclusion:-
From above we concluded that we can get better approximations of frequencies
(especially for higher frequency) by increasing number of samples N.

Aim:- b) Dual Tone Multi Frequency (DTMF) receiver (Using your Goertzel function).

Program:-
P10EC949 Page:-32
ADSP Lab S.V.N.I.T.
clc; clear all;
l=input('Enter the symbol:- ','s');
symbol=['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D']; %DTMF Keypad
f_row=[697 770 852 941];
f_col=[1209 1336 1477 1633];
for r=1:4,
for c=1:4,
if (symbol(r,c)==l) %Compare input symbol with Keypad
f=[f_row(r);f_col(c)];
%If Same than store the row & col freqs
end
end
end
Fs=8000; N=800; %Sampling Freq=8 KHz
t=(0:N-1)/Fs;
y=sum(sin(f(:)*2*pi*t));
%Generation of DTMF for input Symbol
plot(t*1e3,y);
%Plot and add GUI title and label
title(['Tone For Symbol "',l,'"
[',num2str(f(1)),'Hz+',num2str(f(2)),'Hz]']);
xlabel('Time (ms)'); ylabel('Amplitude');
k=round([f_row f_col]/Fs*N);
%Find Goertzel’s index k for all possible freqs
for i=1:length(k),
ydft(i) = my_goert(y,k(i),N);
%Find DFT using my_goert function
end;
estim_f = round(k*Fs/N);
%Calculate estimated freqs
[c1,i1]=max(abs(ydft(1:4)));
%Identify Row freq max amplitude out of first four freqs
[c2,i2]=max(abs(ydft(5:8))); %Same way Identify Col freq
my_f=[estim_f(i1) estim_f(i2+4)];
%Print freqs in Command Window
fprintf('\n-> Approximate frequencies of Tone:- %dHz %dHz',my_f);
fprintf('\n\n-> Hence your input symbol is %c\n',symbol(i1,i2));
subplot(2,1,2); stem(estim_f,abs(ydft)); %Add GUI.
title ('Single-Sided Amplitude Spectrum of Above Tone');
set(gca,'XTick',estim_f,'xlim',[650 1650]);
*Function File (my_goert.m)
function X=my_goert(x,k,N)
vk(1)=0; vk(2)=0;
for n=3:N-1;
vk(n)=(x(n))+(2*cos(2*k*pi/N)*vk(n-1))-(vk(n-2));
%Implementation of Goertzel’s Eqs
end

P10EC949 Page:-33
ADSP Lab S.V.N.I.T.
vk(N)=2*cos(2*k*pi/N)+vk(N-1)-vk(N-2);
X=vk(N)-(exp(-i*2*pi*k/N))*vk(N-1);
%DFT value for particular Index
end

Output:-

*For N=800

Enter the symbol:- 8

-> Approximate frequencies of Tone:- 850Hz 1340Hz

-> Your input symbol is 8

Conclusion:-
From above we concluded that we can make our own function of Goerzel’s filter in
Matlab using for loop and we can get better approximations of frequencies (especially for
higher frequency) by increasing number of samples N.

LABORATORY-05

P10EC949 Page:-34
ADSP Lab S.V.N.I.T.

CHIRP SIGNAL GENERATOR

INTRODUCTION

The Chirp Signal is sine or cosine wave whose frequency increases at a linear or non
linear rate with time. We can use this signal to generate sirens (warning sound) and also for
spectral analysis of nonlinear systems.

The parameters, Initial frequency( f 0), Target time(t ¿¿ 1) ¿, and Frequency at target
time( f t ), determine the characteristic of output signal. We can generate it by mainly three
methods 1) Linear method, 2) Quadratic method and 3) Logarithmic method.

1) Linear Method:-
It specifies an Instantaneous frequency sweep f i (t) given by equation

f i ( t )=f 0 + ( f t−f 0 ) t /t 1

2) Quadratic Method:-
It specifies an Instantaneous frequency sweep f i (t), given by equation

f i ( t )=f 0 + ( f t−f 0 ) t 2 /t 21

3) Logarithmic Method:-
It specifies an Instantaneous frequency sweep f i (t) given by equation

f i ( t )=f 0 ×(f ¿ ¿ t ¿ ¿ f 0 )t /t ¿ ¿
1

Matlab Program :- (For linear)

clc; clear all;


f0=800; f1=1700;
t0=0; t1=4.92;
Fs=4000;
bt=(f1-f0)/t1;
t=t0:1/Fs:t1;
y=sin(2*pi*((f0+(bt/2.*t)).*t));
spectrogram(y,1024,1000,1024,Fs,'xaxis');

P10EC949 Page:-35
ADSP Lab S.V.N.I.T.

LABORATORY:-05

Aim:- a) To Generate Chirp Signal. Where, Initial frequency ( f 0=800 Hz),Target frequency
¿ ¿) and Target time (t g=4.92 sec ). Using Linear Method.

Program:-
clc; clear all;
f0=800; ft=1700; t0=0; t1=4.92;
Fs=4000; t=t0:1/Fs:t1;
y=chirp(t,f0,t1,ft,'li',-90); %’li’ for Quadratic
%Generate Chirp Signal for Given Specification
subplot(2,1,1); spectrogram(y/10,1024,1000,1024,Fs,'xaxis');
title('Chirp Signal (Linear Method)'); ylabel('Time (Sec)');
set(gca,'xtick',[800 1700],'ytick',(1.2:1.2:4.8));
p=audioplayer(y,Fs); play(p);
[Y W]=freqz(y); subplot(2,1,2); %freq response of signal y
plot(W/(2*pi)*Fs,abs(Y));
%Magnitude in Y & Digialfreqs in W
title('DFT of Above Signal For Fs=4000Hz, N=512');
ylabel('|X(f)|'); xlabel('Frequency (Hz)');
set(gca,'xtick',[800 1700]);

Output Waveforms:-

P10EC949 Page:-36
ADSP Lab S.V.N.I.T.

Aim:- b) To Generate Chirp Signal. Where, Initial frequency ( f 0=800 Hz),Target


frequency¿ ¿) and Target time (t g=4.92 sec ). Using Quadratic Method.

Program:-
clc; clear all;
f0=800; ft=1700; t0=0; t1=4.92;
Fs=4000; t=t0:1/Fs:t1;
y=chirp(t,f0,t1,ft,'q',-90); %’q’ for Quadratic
%Generate Chirp Signal for Given Specification
subplot(2,1,1); spectrogram(y/10,1024,1000,1024,Fs,'xaxis');
title('Chirp Signal (Quadratic Method)'); ylabel('Time (Sec)');
set(gca,'xtick',[800 1700],'ytick',(1.2:1.2:4.8));
p=audioplayer(y,Fs); play(p);
[Y W]=freqz(y); subplot(2,1,2); %freq response of signal y
plot(W/(2*pi)*Fs,abs(Y));
%Magnitude in Y & Digialfreqs in W
title('DFT of Above Signal For Fs=4000Hz, N=512');
ylabel('|X(f)|'); xlabel('Frequency (Hz)');
set(gca,'xtick',[800 1700]);

Output Waveforms:-

P10EC949 Page:-37
ADSP Lab S.V.N.I.T.

Aim:- c) Using Logarithmic Method.

Program:-
clc; clear all;
f0=800; ft=1700; t0=0; t1=4.92;
Fs=4000; t=t0:1/Fs:t1;
y=chirp(t,f0,t1,ft,'lo',-90);
subplot(2,1,1); spectrogram(y/10,1024,1000,1024,Fs,'xaxis');
title('Chirp Signal (Logarithmic Method)'); ylabel('Time (Sec)');
set(gca,'xtick',[800 1700],'ytick',(1.2:1.2:4.8));
p=audioplayer(y,Fs); play(p);
[Y W]=freqz(y); subplot(2,1,2); %freq response of signal y
plot(W/(2*pi)*Fs,abs(Y)); %Magnitude in Y & Freqs in W
title('DFT of Above Signal For Fs=4000Hz, N=512');
ylabel('|X(f)|'); xlabel('Frequency (Hz)');
set(gca,'xtick',[800 1700]);

Output Waveforms:-

Conclusion:-
From above we conclude that chirp signals are used to generate siren (warning
sound) and its tone depend upon f 0 , f t and methods of chirp signal generation.

P10EC949 Page:-38
ADSP Lab S.V.N.I.T.

LABORATORY-06
ADAPTIVE ECHO CANCELLATION

INTRODUCTION

Adaptive echo cancellation is an application of adaptive filtering to the attenuation of


undesired echo in the communication networks. This is accomplished by modeling the echo
path using an adaptive filter and subtracting the estimated echo from the echo-path output.
The development of echo cancelling chips and advances in DSP processor have made the
implementation of echo cancellers at commercially acceptable coasts.

Beginning from cancelling the voice echo in long-distances links and now being applied
to control acoustics echo in hands-free telephones, adaptive echo cancellers have also found
wide use in full-duplex data transmission over two-wire circuits such as high speed
modems. In addition, echo cancelling techniques are used in providing the digital data
stream between the customer premises and serving central offices. Since the requirement for
voice and data echo cancellers are quite different.

LINE ECHOES:

One of the main problems associated with telephone communications in generation of


echoes due to impedance mismatches at various points in telecommunication networks.
Such echoes are called line echoes. If the time delay between the speech and the echo is
short, the echo is not noticeable. Distinct echoes are noticeable only if the delay exceeds
tens of milliseconds, which are annoying and can disrupt a conversation under certain
conditions. The deleterious effect of echoes depends upon their loudness, spectral distortion,
and delay. In general, the longer the echo is delayed, the more echo attenuation is required.
Echo is probably the most devastating degradation for long –distances telecommunications,
especially if the two parties are separated by a great distances with long transmission delay.

A simplified communication network is shown in figure 1, where the local telephone set
is connected to a central office by a two-wire line, in which both direction of transmission
are carried on a single wire pair. The connection between two central offices is a four wire
facility, in which the two directions of transmission are segregated on physically different
facilities. This is because long distances transmission requires amplification that is a one –
way function and one-way function and long distances cells are multiplexed, which requires
that signals in the two directions be sent over different slots. This four-wire transmission
P10EC949 Page:-39
ADSP Lab S.V.N.I.T.

path may include various equipment, including switches, cross-connects, and multiplexers.
The conversion between the two-wire and four wire parts of the overall transmission link is
done in the device called hybrid (H) located in the central office.

Four-wire
facility
Two-wire H Two-wire
Telephone H Telephone
facility facility
Echo
Figure 1: long-distance telephone communication Network

An ideal hybrid is a bridge circuits with balancing impedances that is exactly equal to
the impedances of the two-wire circuit at all frequencies. Therefore a hybrid circuit couples
all energy on the incoming branch of the four wire circuit into the two-wire circuit. Thus
none of the incoming four-wire signal should be transferred to the outgoing branch of the
four-wire circuit. In practice, the hybrid may be connected to any of the two-wire loops
served by central offices. Thus the balancing network can only provide a compromise
(fixed) impedances match. As a result, some of incoming signals from the four wire circuit
that is supposed to go into the two wire facility leak into the outgoing four-wire circuit,
which is then returned to the source and is heard as an echo. This echo requires special
treatment if the round-trip delay exceeds 40 mSec.

ADAPTIVE ECHO CANCELER:

In a telecommunication network using echo cancellation, an echo canceller is positioned


in the four wire section on the network near the origin of the echo sources. The principle of
adaptive echo cancellation for one direction of transmission is illustrated in figure 2. We
show only one echo canceller located at the left end of network. To overcome the echoes in
full-duplex communication network, it is desirable to cancel the echoes in the both
directions of the trunk. Thus another echo canceller is symmetrically located at the other
end. The reason for showing a telephone and two-wire line is to indicate that this side is
called the near end, while the other side is referred to as the far-end. The far-end talker is the
talker who generates the echoes that will be cancelled by the echo canceller.

To explain the principal of echo cancellation, the function of the hybrid in figure 3 can
be illustrated in figure 4, where the far-end signal x(n) passing through the echo path P(z)
results in the echo r(n). The primary signal d(n) is a combination of echo r(n), near end

P10EC949 Page:-40
ADSP Lab S.V.N.I.T.

signal u(n), and noise v(n) which consists of the quantization noise from the A/D converter
and other noises from the circuit. The adaptive filter W(z) adaptively learns the response of
the echo path P(z) by using the far-end speech x(n) as an excitation signal. The echo replica
y(n) is generated by W(z), and is subtracted from the primary signal d(n) to yield the error
signal e(n). Ideally, y(n)  r(n) and the residual error e(n) is substantially echo free.

A typically impulse response of echo path shown in figure 4. The time span over the
impulse response of the echo path significant (non-zero) and typically about 4 mSec. This
portion is called the dispersive delay since it associated with the frequency dependent delay
and loss through the echo path. Because of the existence of the four-wire circuits between
the location of the echo canceller and the hybrid, the impulse response of echo path is
delayed. Therefore the initial samples of p(n) are all zeros, representing a flat delay between
the canceller and the hybrid. The flat delay depends on the transmission delay and the delay
through the sharp filter associated with frequency division multiplex equipment.

XXXXX figure(2).

XXXX Figure(3).

The sum of the flat delay and the dispersive is called the tail delay.

Assume that the echo path P(z) is linear, time invariant, and with infinite impulse
response p(n), n=0, 1, . . . , . As shown in figure 4, the primary signal d(n) can be
expressed as.

d (n )=r(n )+u(n )+v(n )=∑ p(l )∗x(n−l )+u(n )+v(n )
l=0 . Eq1

Where the additive noise v(n) is assumed to be uncorrelated with the near-end speech
u(n) and the echo r(n). The most widely used FIR filter generates the echo mimic
L−1
y (n )= ∑ wi (n)∗x (n−l )
l=0 . Eq2.

To cancel the echo signal r(n). The estimation error is expressed as


L−1 ∞
e (n)=d (n )− y (n )= ∑ [ p(l)−wi( n)]∗x (n−l)+ ∑ p (l)∗x (n−l)+u(n )+v (n )
l=0 i= L . Eq3

As shown in figure, the adaptive filter W(z) has to adjust its weights to mimic the
response of echo path in order to cancel out the echo signal. The simple normalized LMS
algorithm is used for most voice echo cancellation applications. Assuming that disturbances

P10EC949 Page:-41
ADSP Lab S.V.N.I.T.

u(n) and v(n) are uncorrelated with x(n), we can show that will converge to P(z).
Unfortunately this requires L to be quite large in many applications Echo cancellation is
achieved if as W(z)  P(z) shown below. Thus the residual error after the echo canceller has
converged can be expressed as

e(n)≈ ∑ p(l)∗x(n−l)+u( n)+v(n)
l= L . Eq. 4

By making the length L of W(z) sufficiently long, this residual echo can be minimized.
However, the excess MSE produced by the adaptive algorithm is also proportional to L.
Therefore there is an optimum order L that will minimize the MSE if an FIR filter is used.

The number of co-efficient for the transversal filter is directly related to the tail delay
(total delay) of the channel between the echo canceller and the hybrid. As mentioned earlier,
the length of the impulse response of the hybrid (dispersive delay) is relatively short.
However, the transmission delay (flat delay) from the echo canceller to the hybrid depends
on the physical location of the echo canceller. As shown in figure, the split echo canceller
configuration is especially important for channels with particularly long delays, such as
satellite channels. In the split configuration, the number of transversal filter coefficient need
only compensate for the delay between the hybrid and the canceller and not the much longer
delay through the satellite. Hence, the number of coefficient is minimized.

The design of an adaptive echo canceller involves much consideration, such as the speed
of adaption, the effect of near-end and far-end signals, the impact of signal levels and
spectra, and the impact nonlinearity. The echo canceller must accurately model the echo
path and rapidly adapt to its variation. This involves the selection of an adaptive filter
structures and an adaption algorithm. Because the potential application of echo cancellation
is numerous, there have been considerable activities in the design of echo cancelation
devices. The best selection depends on performances requirement for particular
applications.

The effectiveness of an echo canceller is measured by the echo return loss enhancement
(ERLE) defined as.

E[ d 2 (n )]
ERLE=10 log
{ E [ e2 (n) } .

For a given applications, the ERLE depends on the step size , the filter length L, the
signal-to-noise ratio (SNR), and the nature of signal in terms of power and spectral content.

P10EC949 Page:-42
ADSP Lab S.V.N.I.T.

A larger value of step size provides a faster initial convergence, but the final ERLE is
smaller due to excess MSE. Provided the length is large enough to correct for the length of
echo tail, increasing L further is detrimental since doubling L will reduce the ERLE by 3
dB.

Most echo canceller aim at cancelling echo component up to 30 dB. Further reduction of
the residual echo can be achieved by using a residual echo suppressor that will be discussed.
Detailed requirement of an echo canceller are described in ITU recommendations G.165 and
G168, including the maximum residual echo level, the echo suppression effect on the
hybrid, the convergences time must be less than 500 msec, the initial set-up time, the
degradation in a double talk situation.

The first special-purpose chip for echo cancellation implements a single 128-tap
adaptive echo canceller. Most echo cancellers were implemented using customized device
in order to handle the large amount of computation associated with it in real time
applications. Disadvantages of VLSI implementation include the high development cost and
a lack of flexibility to meet application-specific requirement and improvements. There has
been considerable activity in the design of device using commercially available DSP chips.

IMPLEMENTATION CONSIDERATION

There are some practical issues to be consider in designing adaptive echo canceller:

(1) Adaption should be stopped if the far-end signal x(n) is absent.

(2) We must also worry about the quality of adaption over large dynamic range of far-
end signal power.

(3) The adaption process benefits when the far-end signal contains a well–distributed
frequency component to persistently excite the adaptive system and interfacing signal u(n)
and v(n) are small. When the reference x(n) is narrowband signal, the adaptive filter
response cannot be controlled at frequencies other than that frequency band. If the reference
signals later changes to a broadband signal, then the canceller may actually become an echo
generator. Therefore a tone detector may be used to inhibit adaption in case.

The initial part of the impulse response of the echo path is all zeros, representing a flat
transmission delay between the canceller and the hybrid. To take advantages a flat delay, the
structures are given below. Where  is a measured of flat delay and the order of shorter
echo canceller W(z) is L-. Estimation of the number of zero coefficients and using buffer
indexing, one does not need to perform the actual adaptive filtering operation on the zero

P10EC949 Page:-43
ADSP Lab S.V.N.I.T.

coefficients but simply index into the buffer appropriately. This technique can effectively
reduce the real-time computational requirement. However, there are two difficulties: the
multiple echoes and there has not been a good way to estimate the flat delay.

Figure-1:

Figure-2:

Figure-3:

Figure-4:

P10EC949 Page:-44
ADSP Lab S.V.N.I.T.

Figure-5:

Figure-6:

P10EC949 Page:-45
ADSP Lab S.V.N.I.T.

LABORATORY:-06

Aim:- a) To Study about Adaptive Echo Cancellation Using LMS (Least Means Square)
Algorithm.

Program:-
clc; clear all; close all;
Fs=100000; N=1000; %Sampling Freq=100 KHz
fn=1000;
t=(0:N-1)/Fs;
yn=sin(2*pi*fn*t);
%Speech Signal of f=1 KHz
subplot(4,1,1);
plot(t*1000,yn);
title('Original Speech Signal');
ylabel('Amplitude');
ye=[zeros(1,200),0.4*yn(1:N-200)]+0.05*randn(1,N);
%Signal Delayed by 2ms and Random Noise
%Generation of Echo of Original Signal
subplot(4,1,2);
plot(t*1000,ye);
title('Echo of Original Speech Signal');
ylabel('Amplitude');
yf=yn+ye; %Sum of Original and Line Echo Signal
subplot(4,1,3);
plot(t*1000,yf);
title('Distorted Speech Signal');
ylabel('Amplitude');
Hf=adaptfilt.lms(32,0.0004);%Adaptive Filter Coefficient of LMS
%Algo. Length=32 & Step Size=0.0004

[y,e]=filter(Hf,yn,yf); % Hf is Filter Coefficient


% yn is Desired(Original) Signal
% yf is Input to the Filter
% y is Filer Output & e is Error Signal
subplot(4,1,4)
plot(t*1000,y); hold on;
plot(t*1000,yn,'r-.');
% -. Line of Red Colour is for Actual Signal
title('Filter Output and Original Speech Signal');
ylabel('Amplitude'); xlabel('Time (ms)');

P10EC949 Page:-46
ADSP Lab S.V.N.I.T.

Output:-

Conclusion:-
From above we conclude that the output accuracy and response time of adaptive
LMS filter depends upon the length and step size of coefficient respectively.

P10EC949 Page:-47
ADSP Lab S.V.N.I.T.

LABORATORY:-07

Aim:- a) To Study about Double Talk Suppresser Using LMS (Least Means Square)
Algorithm.

Program:-
clc; clear all; close all;
Fs=100000; N=1000; %Sampling Freq=100 KHz
fn=1000; t=(0:N-1)/Fs;
yn=sin(2*pi*fn*t);
%Actual Speech Signal of f=1 KHz
subplot(4,1,1);
plot(t*1000,yn);
title('Actual Speech Signal');
ylabel('Amplitude');
ff=1500; t=(0:N-1)/Fs;
yf=0.3*sin(2*pi*ff*t)+0.1*randn(1,N);
%Far End Speech Signal of f=1.5 KHz with Noise
subplot(4,1,2);
plot(t*1000,yf);
title('Far End Speech Signal');
ylabel('Amplitude');
ym=yn+yf;
%Sum of Two Signal (Double Talk Effected Signal)
subplot(4,1,3);
plot(t*1000,ym);
title('Distorted Speech Signal');
ylabel('Amplitude');
Hf=adaptfilt.lms(64,0.0009); );
%Adaptive Filter Coefficient of LMS
%Algo. Length=64 & Step Size=0.0009

[y,e]=filter(Hf,yn,ym); % Hf is Filter Coefficient


% yn is Desired(Actual) Signal
% ym is Input to the Filter
% y is Filer Output & e is Error Signal

subplot(4,1,4)
plot(t*1000,y); hold on;
plot(t*1000,yn,'r-.');
% -. Line of Red Colour is for Actual Signal
title('Filter Output and Actual Speech Signal');
ylabel('Amplitude'); xlabel('Time (ms)');

P10EC949 Page:-48
ADSP Lab S.V.N.I.T.

Output:-

Conclusion:-
From above we conclude that we can suppress double talk effect using adaptive filter
LMS algorithm.

P10EC949 Page:-49
ADSP Lab S.V.N.I.T.

LABORATORY-08
INTRODUCTION TO MUSIC SYNTHESIS

INTRODUCTION
The ability to synthesize waveforms through digital methods is a popular technique.
This method can be found in many applications such as data communications devices
(modems), software radios, and DTMF (Touch Tone) generators. One of its most familiar
consumer-oriented applications is in music synthesis. In this application, the musician often
has control over many instruments and sound effects all from a single synthesizer.
Waveform synthesis can be taught early in a typical undergraduate Digital Signal
Processing (DSP) course to illustrate some of the applications of sampling and
reconstruction theory. In addition hands-on practice with waveform synthesis can be made
very interesting in the context of computer music. In this paper we outline a waveform
synthesis project in which students code two simple tools in MATLAB. These tools are a
tone (sinusoid) generator and an envelope generator used to shape the amplitude of the tone,
i.e. amplitude modulation. These two tools form the basis of the project where students can
experiment with computer-based music and musical synthesis using MATLAB’s built-in
sound capabilities and the PC’s sound card. A student design example is provided which
will synthesize a Bach Musset (25 seconds in duration) using only the tone and envelope
generation tools in MATLAB.

MUSIC SYNTHESIS
In this section we provide background for the non-musician and a basic method of
shaping a sinusoid so as to match tonal output from real instruments.

Background for the Nonmusical:-


The fundamental element in music is the note or tone which is simply an oscillation;
combinations of notes are called chords. On a piano each key defines a note and the
frequencies of these notes are determined by their position relative to the 4th octave
(middle) A which is set to 440Hz. Each octave up, down produces a note with twice, half
the frequency respectively. With 12 notes per octave and the doubling relation, we can
easily see that the frequency ratio of any two consecutive notes is 2. Frequency, duration,

P10EC949 Page:-50
ADSP Lab S.V.N.I.T.

and loudness data for producing music is efficiently coded in Fig-1.

Figure 1: (a) Octave codes, (b) Note codes, (c) Frequency data.

P10EC949 Page:-51
ADSP Lab S.V.N.I.T.

LABORATORY:-08

Aim:- a) To Study about Music Synthesis for Octave Codes.

Program:-
clc; clear all;
close all;
f=[261.626,293.665,329.628,349.228,391.995,440.000,493.883];
%frequencies of Octave Codes for index-4
Fs=8000; N=8000;
%Sampling freq=8 KHz each tone for 1sec
yf=[];
%Nil array
for i=1:length(f);
t=(0:N-1)/Fs;
y=sin(2*pi*f(i).*t);
yf=[yf,y];
%Synthesis tone with previous tones
subplot(4,2,i);
plot(t*1000,y);
%plot different tones
set(gca,'xlim',[0,100]);
ylabel('Amplitude')
if(i<=5)
title(['Tone For "','B'+i,'" f=',num2str(f(i)),' Hz']);
else
title(['Tone For "','A'+i-6,'" f=',num2str(f(i)),' Hz']);
xlabel('Time (ms)');
end;
end;
audio=audioplayer(yf,Fs);
%Initialize audio player
play(audio);
%play all tones for Fs=8 KHz

P10EC949 Page:-52
ADSP Lab S.V.N.I.T.

Output:-

Conclusion:-
From above we conclude that sound of octave codes is dependent upon frequency
index. It is the best for middle index-4.

P10EC949 Page:-53
ADSP Lab S.V.N.I.T.

LABORATORY-09
DSP PROCESSOR INTRODUCTION AND BASIC APPLICATION

PART-A

P10EC949 Page:-54
ADSP Lab S.V.N.I.T.

P10EC949 Page:-55
ADSP Lab S.V.N.I.T.

P10EC949 Page:-56
ADSP Lab S.V.N.I.T.

P10EC949 Page:-57
ADSP Lab S.V.N.I.T.

P10EC949 Page:-58
ADSP Lab S.V.N.I.T.

P10EC949 Page:-59
ADSP Lab S.V.N.I.T.

PART-B

P10EC949 Page:-60
ADSP Lab S.V.N.I.T.

P10EC949 Page:-61
ADSP Lab S.V.N.I.T.

P10EC949 Page:-62
ADSP Lab S.V.N.I.T.

P10EC949 Page:-63
ADSP Lab S.V.N.I.T.

P10EC949 Page:-64
ADSP Lab S.V.N.I.T.

LABORATORY-10
REAL TIME FILTERS IMPLEMENTATION USING DSK 6713

P10EC949 Page:-65
ADSP Lab S.V.N.I.T.

P10EC949 Page:-66
ADSP Lab S.V.N.I.T.

P10EC949 Page:-67
ADSP Lab S.V.N.I.T.

//Fir.c FIR filter. Include coefficient file with length N

#include "bs2700.cof" //coefficient file


#include "dsk6713_aic23.h" //codec-dsk support
file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
int yn = 0; //initialize
filter's output
short dly[N];
//delay samples

interrupt void c_int11() //ISR


{
short i;

dly[0]=input_sample(); //input newest sample


yn =
0;
//initialize filter's output
for (i = 0; i< N; i++)
yn += (h[i] * dly[i]); //y(n) +=
h(i)* x(n-i)
for (i = N-1; i > 0; i--)
//starting @ end of buffer
dly[i] = dly[i-1]; //update
delays with data move
output_sample(yn >> 15); //scale output
filter sample
return;
}

void main()
{
comm_intr(); //init DSK,
codec, McBSP
while(1);
//infinite loop
}

P10EC949 Page:-68
ADSP Lab S.V.N.I.T.

//IIR.c IIR filter using cascaded Direct Form II


//Coeffs a's and b's correspond to b's and a's from MATLAB

#include "DSK6713_AIC23.h" //codec-DSK


support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
#include "bs1750.cof"
//BS @ 1750 Hz coefficient file
short dly[stages][2] = {0};
//delay samples per stage

interrupt void c_int11() //ISR


{
short i, input;
int un, yn;

input = input_sample(); //input to 1st stage


for (i = 0; i < stages; i++) //repeat for
each stage
{
un=input-((b[i][0]*dly[i][0])>>15) - ((b[i][1]*dly[i]
[1])>>15);

yn=((a[i][0]*un)>>15)+((a[i][1]*dly[i][0])>>15)+((a[i]
[2]*dly[i][1])>>15);

dly[i][1] = dly[i][0];
//update delays
dly[i][0] = un; //update
delays
input = yn; //intermediate
output->input to next stage
}
output_sample((short)yn); //output final
result for time n
return; //return from ISR
}

void main()
{
comm_intr(); //init
DSK, codec, McBSP
while(1); } //infinite loop

P10EC949 Page:-69

You might also like