Adsp Lab Manual-1
Adsp Lab Manual-1
Adsp Lab Manual-1
NARAYANA
ENGINEERING COLLEGE
GUDUR
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION
ENGINEERING
1
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Note:
A. Minimum of 10 Experiments have to be conducted
B. All Simulations are be carried out using MATLAB/DSP Processors/Labview
Software & DSP Kits
2
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
4. Finding voice & unvoiced detection for each frame of the speech signal
3
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Aim:
To Study the various addressing mode of TMS320C6745 DSP processor.
Addressing Modes:
The addressing modes on the DSP are linear, circular using BK0, and circular
using BK1. The addressing mode is specified by the addressing mode register (AMR).
All registers can perform linear addressing. Only eight registers can perform circular
addressing: A4-A7 are used by the .D1 unit, and B4-B7 are used by the .D2 unit. No
other units can perform circular addressing. LDB(U)/LDH(U)/LDW, STB/STH/STW,
LDNDW, LDNW, STNDW, STNW, LDDW, STDW,
ADDAB/ADDAH/ADDAW/ADDAD, and SUBAB/SUBAH/SUBAW instructions all
use AMR to determine what type of address calculations are performed for these
registers. There is no SUBAD instruction.
For load and store instructions, linear mode simply shifts the offsetR/cst operand to
the left by 3, 2, 1, or 0 for doubleword, word, halfword, or byte access, respectively;
and then performs an add or a subtract to baseR (depending on the operation
specified). The LDNDW and STNDW instructions also support nonscaled offsets. In
nonscaled mode, the offsetR/cst is not shifted before adding or subtracting from the
baseR.
For the preincrement, predecrement, positive offset, and negative offset address
generation options, the result of the calculation is the address to be accessed in
memory. For postincrement or postdecrement addressing, the value of baseR before
the addition or subtraction is the address to be accessed from memory.
4
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
For integer addition and subtraction instructions, linear mode simply shifts the src1/cst
operand to the left by 3, 2, 1, or 0 for doubleword, word, halfword, or byte data sizes,
respectively, and then performs the add or subtract specified.
The BK0 and BK1 fields in AMR specify the block sizes for circular addressing
LD and ST Instructions
The resulting address is bounded to 2(N + 1) range, regardless of the size of the
offsetR/cst.
The circular buffer size in AMR is not scaled; for example, a block-size of 8 is 8
bytes, not 8 times the data size (byte, halfword, word). So, to perform circular
addressing on an array of 8 words, a size of 32 should be specified, or N =
4. Example shows an LDW performed with register A4 in circular mode and BK0 = 4,
so the buffer size is 32 bytes, 16 halfwords, or 8 words. The value in AMR for this
example is 0004 0001h
The circular buffer size in AMR is not scaled; for example, a block size of 8 is 8 bytes,
not 8 times the data size (byte, halfword, word). So, to perform circular addressing on
an array of 8 words, a size of 32 should be specified, or N = 4.
5
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Result
Thus, the various addressing mode of DSP processor TMS320C6745 was studied.
6
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
EQUIPMENT REQUIRED:
THEORY:
Convolution is a formal mathematical operation, just as multiplication, addition, and
integration. Addition takes two numbers and produces a third number, while convolution
takes two signals and produces a third signal. Convolution is used in the mathematics of
many fields, such as probability and statistics. In linear systems, convolution is used to
describe the relationship between three signals of interest: the input signal, the impulse
response, and the output signal. In this equation, x1(k), x2(n-k) and y(n) represent the
input to and output from the system at time n.
Here we could see that one of the inputs is shifted in time by a value every time it is
multiplied with the other input signal. Linear Convolution is quite often used as a method
of implementing filters of various types.
Program:
clc;
clear all;
close all;
disp('linear convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
7
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;
CIRCULAR CONVOLUTION:
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
THEORY
Circular convolution is another way of finding the convolution sum of two input signals.
It resembles the linear convolution, except that the sample values of one of the input
signals is folded and right shifted before the convolution sum is found. Also note that
circular convolution could also be found by taking the DFT of the two input signals and
finding the product of the two frequency domain signals. The Inverse DFT of the product
would give the output of the signal in the time domain which is the circular convolution
output. The two input signals could have been of varying sample lengths. But we take the
DFT of higher point, which ever signals levels to. For example, If one of the signal is of
length 256 and the other spans 51 samples, then we could only take 256 point DFT. So
the output of IDFT would be containing 256 samples instead of 306 samples, which
follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two
inputs. Thus the output which should have been 306 samples long is fitted into 256
samples. The256 points end up being a distorted version of the correct signal. This
process is called circular convolution.
8
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
grid;
subplot(2,2,2),
stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');
grid;
disp('circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%circular convolution
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y((n)');grid;
EXP NO:3
Framing & windowing of speech signal. DATE:
9
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program:
[signal,fs]=wavread('Noor.wav');
%Shift percentage is 40%to cancel the background effect
%and Convert the signal to row vector
s=signal(.4*length(signal):end)';
Number_of_frames=240; %Number of frames
window_length=round(fs/Number_of_frames);%size of the frame
Frame_No=zeros(Number_of_frames);%The frame number
Frame_No(1)=1;
for i=1:Number_of_frames-1
Frame_No(i+1)=Frame_No(i)+window_length;%Construct an array for the start
number of each frame
end
j=input('Enter the frame number: ');
N=Frame_No(j);%specify which frame
plot((N:N+window_length-1),s(N:N+window_length-1));%plot the frame
title(['Frame Number ',num2str(j)]);xlabel('Time');ylabel('Amplitude');
figure,
plot(s);title('input signal');xlabel('Time');ylabel('Amplitude');
AIM:
10
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
The main aim of this experiment is to determine whether the speech waveform is voiced
or unvoiced, in other words speech or silence.
Theory:
The input speech waveform is segmented with the help of a window either a rectangular
of hamming window. Then the auto correlation function of the speech segment is
calculated by using formula
m= N−1−k
Rn (k) = ∑ ¿ ¿x(n+m)ώ(m)][x(n+m+k)ώ(k+m)]
m =0
The property of the short time auto correlation to reveal periodicity in a signal is used
here. The auto correlation of the voiced spech segment retains the periodicity. On the
other hand , the autocorrelation of the unvoiced speech signal looks more like noise. In
general, the auto correlation is considered as a robust indicator of periodicity. Thus we
will decide whether a speech wave form is voiced or unvoiced.
Algorithm of voiced – unvoiced speech detection:
Step-1: record the wave file that is to be analyzed. (wav record).
Step-2: take some samples from the entire array set into a variable.
Step-3: find the autocorrelation of the segmented section. (xcorr)
Step-4: take another segment from the same wave file at a different time instant.
Step-5: perform the autocorrelation for the second segment just as step-3.
Step-6: plot the autocorrelation of these two segments.
Step-7: the speech segment with higher magnitude is the voice speech.
Clc;
clear all;
close all;
% voiced and unvoiced speech as input
% Fs=8000;
%x= wavrecord(4*Fs,Fs,’double’);
[x Fs ]= wavread(‘SP06.wav’);
Ss1=x(2920:2980) ;
[ac4, lags4]=xcorr(ss1) ;
Ss4 =x (2920:2980) ;
[ac4, lags4]=xcorr(ss4) ;
Subplot(2,2,1) ;
Plot(ss1) ;
legend(‘voiced speech’)
Subplot(2,2,2) ;
Plot (lags1,ac1);
11
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Xlim([lags1(1) lags1(end)];
Legend(‘ autocorrelation of voiced speech’)
Grid on;
Subplot (2,2,3);
Plot(ss4);
Legend(‘unvoiced speech’)
Subplot(2,2,4);
Plot(lags4, ac4);
Xlim ([lags1(1) lags1(end)]) ;
Legend(‘ autocorrelation of unvoiced speech’)
Grid on ;
CONCLUSION:
Notice from the output waveforms that the autocorrelation of the voiced speech
segment retains the periodicity .on the other hand ,the autocorrelation of the unvoiced
speech segment looks like more noise.
12
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
AIM: To verify IIR Filter Implementation Using Probe Points using MATLAB
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program
clear all
load y2;
x = y2;
x = x/max(abs(x));
load SOS
N = length(x);
b1(1:3) = SOS(1,1:3); %B(z) coefficients
a1(1:3) = SOS(1,4:6); %A(z) coefficients
b2(1:3) = SOS(2,1:3); %B(z) coefficients
a2(1:3) = SOS(2,4:6); %A(z) coefficients
b3(1:3) = SOS(3,1:3); %B(z) coefficients
a3(1:3) = SOS(3,4:6); %A(z) coefficients
h_a1 = impz(1, a1, 100);
h_a2 = impz(1, a2, 100);
h_a3 = impz(1, a3, 100);
%compute scaling factors for each section. This computation is done
%offline prior to coding your filter on the DSP.
%compute scaling factors
G1 = sum(abs(h_a1));
G2 = sum(abs(h_a2));
G3 = sum(abs(h_a3));
%scale input
x_scaled = x/G1;
%scale b coefficients
b1 = b1*G1/G2;
b2 = b2*G2/G3;
b3 = b3*G3;
%initialize ripple buffers
%SOS1
x01 = 0;
x11 = 0;
x21 = 0;
%SOS2
13
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
x02 = 0;
x12 = 0;
x22 = 0;
%SOS3
x03 = 0;
x13 = 0;
x23 = 0;
for n = 1:N,
%SOS1 computations
x01 = x_scaled(n) - a1(2)*x11 - a1(3)*x21;
y1 = b1(1)*x01 + b1(2)*x11 + b1(3)*x21;
x21 = x11; %shift ripple buffer
x11 = x01;
x1(n) = x01;
%SOS2 computations
x02 = y1 - a2(2)*x12 - a2(3)*x22;
y2 = b2(1)*x02 + b2(2)*x12 + b2(3)*x22;
x22 = x12; %shift ripple buffer
x12 = x02;
x2(n) = x02;
%SOS3 computations
x03 = y2 - a3(2)*x13 - a3(3)*x23;
y(n) = b3(1)*x03 + b3(2)*x13 + b3(3)*x23;
x23 = x13; %shift ripple buffer
x13 = x03;
x3(n) = x03;
end
%this is just to compare with the Matlab 'sosfilt' function
y1 = sosfilt(SOS,x);
norm(y1' - y)
EQUIPMENT REQUIRED:
14
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program
15
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
figure; %Create a new figure window, so previous one isn't lost.
subplot(2,1,1);
xfftmag=(abs(fft(x,Ns))); %Compute spectrum of input signal.
xfftmagh=xfftmag(1:length(xfftmag)/2);
%Plot only the first half of FFT, since second half is mirror imag
%the first half represents the useful range of frequencies from
%0 to Fs/2, the Nyquist sampling limit.
f=[1:1:length(xfftmagh)]*Fs/Ns; %Make freq array that varies from
%0 Hz to Fs/2 Hz.
plot(f,xfftmagh); %Plot frequency spectrum of input signal
title('Input and Output Spectra');
xlabel('freq (Hz)');
ylabel('Input Spectrum');
subplot(2,1,2);
yfftmag=(abs(fft(y,Ns)));
yfftmagh=yfftmag(1:length(yfftmag)/2);
%Plot only the first half of FFT, since second half is mirror image
%the first half represents the useful range of frequencies from
%0 to Fs/2, the Nyquist sampling limit.
plot(f,yfftmagh); %Plot frequency spectrum of input signal
xlabel('freq (Hz)');
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
16
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program
function y = dec2q(x,a,b,format)
% function y = dec2q(x,a,b,format)
% Input is a vector of decimal numbers and the output is the equivalent numbers in Qa.b
format
% in either binary or hex format where "a' is number of bits to the left of the
% binary point not including the sign bit, and 'b' is the number of bits to the
% right of the binary point.
% Input numbers outside the range are clipped
% An example of a Q0.15 (also called Q15) number is 1.100 0000 0000 0000 = -1 + 0.5
= -0.5.
% x (vector) input in decimal
% a (scalar) number of bits to the left of the binary point not including the sign bit
% (optional, default a = 0)
% b (scalar) number of bits to the right of the binary point
% (optional, dafault b = 15)
% format (string) format of the output 'bin' or 'hex' (optional, default 'hex')
% y (string matrix) output in Qa.b format (each output number on a row of the matrix)
% default a = 0
if nargin < 2,
a = 0;
end
if isempty(a),
a = 0;
end
% default b = 15
if nargin < 3,
b = 15;
end
if isempty(a),
b = 15;
end
17
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
if a < 0,
error('dec2q: input a must be greater than or equal to 0')
end
if b < 0,
error('dec2q: input b must be greater than or equal to 0')
end
y(i,:) = d;
end
y=char(y);
18
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
AIM: To verify Image Enhancement Using Spatial And Frequency Domain using
MATLAB
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
19
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Power Adapter
Program
footBall=imread('football.jpg');
%Convert to grayscale
footBall=rgb2gray(footBall);
imshow(footBall)
20
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program
21
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
% This is a program for extracting objects from an image. Written for vehicle number
plate segmentation and extraction
% Authors : Jeny Rajan, Chandrashekar P S
% U can use attached test image for testing
% input - give the image file name as input. eg :- car3.jpg
clc;
clear all;
k=input('Enter the file name','s'); % input image; color image
im=imread(k);
im1=rgb2gray(im);
im1=medfilt2(im1,[3 3]); %Median filtering the image to remove noise%
BW = edge(im1,'sobel'); %finding edges
[imx,imy]=size(BW);
msk=[0 0 0 0 0;
0 1 1 1 0;
0 1 1 1 0;
0 1 1 1 0;
0 0 0 0 0;];
B=conv2(double(BW),double(msk)); %Smoothing image to reduce the number of
connected components
L = bwlabel(B,8);% Calculating connected components
mx=max(max(L))
% There will be mx connected components.Here U can give a value between 1 and mx
for L or in a loop you can extract all connected components
% If you are using the attached car image, by giving 17,18,19,22,27,28 to L you can
extract the number plate completely.
[r,c] = find(L==17);
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
figure,imshow(im);
figure,imshow(im1);
figure,imshow(B);
figure,imshow(n1,[]);
22
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter
Program
mov=aviread('fun.avi');
23
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Im=frame2im(mov(1,58));
figure,imshow(Im);
MATLAB CODE:
Vobj=mmreader('fun.avi');
Im=read(Vobj,58);
imshow(Im);
Lmov=aviread('smiley.avi');
MIm=frame2im(Lmov(1,1));
figure,imshow(MIm);
obj=avifile('VidPart.avi','FPS',5);
obj=addframe(obj,mov(27:33));
obj=close(obj);
24