Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Department of Electronics & Communication Engineering

ADVANCED DIGITAL SIGNAL PROCESSING LAB

NARAYANA
ENGINEERING COLLEGE
GUDUR

ADVANCED DIGITAL SIGNAL PROCESSING LAB


MANUAL

DEPARTMENT OF
ELECTRONICS AND COMMUNICATION
ENGINEERING

1
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR


M.Tech I year I Semester (DSCE) L T
P C
0 0 3
2
(17D38108) 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

1. Study of various addressing modes of DSP using simple programming examples


2. Generation of waveforms using recursive/filter methods
3. Sampling of input signal and display
4. Implementation of Linear and Circular Convolution for sinusoidal signals
5. Framing & windowing of speech signal.
6. Finding voice & unvoiced detection for each frame of the speech signal.
7. IIR Filter Implementation using probe points
8. Implementation of FIR filters on DSP processor
9. Loop back using DSK kit
10. Real-time signal enhancement using Adaptive Filter.
11. Representation of different Q-formats using GEL function
12. Verification of Finite word length effects (Overflow, Coefficient Quantization,
Scaling and Saturation mode in DSP processors)
13. Image enhancement using spatial & frequency domain
14. Implementation of Image segmentation techniques
15. Extraction of frames from Video signal

2
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

NARAYANA ENGINEERING COLLEGE::GUDUR


LIST OF EXPERIMENTS TO BE CONDUCTED

1. Study of various addressing modes of DSP using simple programming examples

2. Implementation of Linear and Circular Convolution for sinusoidal signals

3. Framing & windowing of speech signal

4. Finding voice & unvoiced detection for each frame of the speech signal

5. IIR Filter Implementation using probe points

6. Implementation of FIR filters on DSP processor

7. Representation of different Q-formats using GEL function

8. Image enhancement using spatial & frequency domain

9. Implementation of Image segmentation techniques

10. Extraction of frames from Video signal

3
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

EXP NO:1 STUDY OF VARIOUS ADDRESSING MODES OF DSP DATE:


USING SIMPLE PROGRAMMING EXAMPLES

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.

Addressing Mode Register (AMR):


For each of the eight registers (A4-A7, B4-B7) that can perform linear or
circular addressing, the addressing mode register (AMR) specifies the addressing
mode. A 2-bit field for each register selects the address modification mode: linear (the
default) or circular mode. With circular addressing, the field also specifies which BK
(block size) field to use for a circular buffer. The mode select & block size fields are
choose by writing values to AMR. The register details about AMR is available
at TMS320C674x DSP CPU and Instruction Set Reference Guide.
Linear Addressing Mode
LD and ST Instructions

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.

ADDA and SUBA Instructions

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.

Circular Addressing Mode

The BK0 and BK1 fields in AMR specify the block sizes for circular addressing

LD and ST Instructions

As with linear address arithmetic, offsetR/cst is shifted left by 3, 2, 1, or 0 according


to the data size, and is then added to or subtracted from baseR to produce the final
address. Circular addressing modifies this slightly by only allowing bits N through 0
of the result to be updated, leaving bits 31 through N + 1 unchanged after address
arithmetic.

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

ADDA and SUBA Instructions

As with linear address arithmetic, offsetR/cst is shifted left by 3, 2, 1, or 0 according


to the data size, and is then added to or subtracted from baseR to produce the final
address. Circular addressing modifies this slightly by only allowing bits N through 0
of the result to be updated, leaving bits 31 through N + 1 unchanged after address
arithmetic. 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 ADDAH 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.

5
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB
Result
Thus, the various addressing mode of DSP processor TMS320C6745 was studied.

IMPLEMENTATION Of LINEAR AND


EXP NO:2 CIRCULAR CONVOLUTION USING MATLAB DATE:

AIM: To verify Linear Convolution using MATLAB.

6
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

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.

Linear Convolution Using MATLAB:-

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:

AIM: To verify Circular Convolution using MATLAB.

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.

Circular Convolution using MATLAB:-


Program:
clc;
clear all;
close all;
disp('circular convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p sequence h(n)');
n=length(h);
subplot(2,2,1),
stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');

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

AIM: To verify Framing & windowing of speech signal using MATLAB.

EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter

Framing & windowing of speech signal using MATLAB:-

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

Finding voice & unvoiced detection for each


EXP NO:4 DATE:
frame of the speech signal

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.

MATLAB CODE DETECTION OF VOICED AND UNVOICED SPEECH


SIGNAL:

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.

EXP NO:5 IIR FILTER IMPLEMENTATION USING PROBE DATE:


POINTS

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

IIR Filter Implementation Using Probe Points using MATLAB:-

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)

IMPLEMENTATION OF FIR FILTERS ON DSP


EXP NO:6 PROCESSOR DATE:

AIM: To verify Implementation Of FIR Filters On DSP Processor using MATLAB

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

Implementation Of FIR Filters On DSP Processor using MATLAB:-

Program

Fs=8e3; %Specify Sampling Frequency


Ts=1/Fs; %Sampling period.
Ns=512; %Number of time samples to be plotted.
t=[0:Ts:Ts*(Ns-1)]; %Make time array that contains Ns elements
%t = [0, Ts, 2Ts, 3Ts,..., (Ns-1)Ts]
f1=500;
f2=1800;
f3=2000;
f4=3200;
x1=sin(2*pi*f1*t); %create sampled sinusoids at different frequencies
x2=sin(2*pi*f2*t);
x3=sin(2*pi*f3*t);
x4=sin(2*pi*f4*t);
x=x1+x2+x3+x4; %Calculate samples for a 4-tone input signal
grid on;
N=16; %FIR1 requires filter order (N) to be EVEN
%when gain = 1 at Fs/2.
W=[0.4 0.6]; %Specify Bandstop filter with stop band between
%0.4*(Fs/2) and 0.6*(Fs/2)
B=fir1(N,W,'DC-1');%Design FIR Filter using default (Hamming window.
B %Leaving off semi-colon causes contents of
%B (the FIR coefficients) to be displayed.
A=1; %FIR filters have no poles, only zeros.
freqz(B,A); %Plot frequency response - both amp and phase response.
pause; %User must hit any key on PC keyboard to go on.
figure; %Create a new figure window, so previous one isn't lost.
subplot(2,1,1); %Two subplots will go on this figure window.
Npts=200;
plot(t(1:Npts),x(1:Npts)) %Plot first Npts of this 4-tone input signal
title('Time Plots of Input and Output');
xlabel('time (s)');
ylabel('Input Sig');
%Now apply this filter to our 4-tone test sequence
y = filter(B,A,x);
subplot(2,1,2); %Now go to bottom subplot.
plot(t(1:Npts),y(1:Npts)); %Plot first Npts of filtered signal.
xlabel('time (s)');
Filtered Sig');
pause;

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

EXP NO:7 Representation of different Q-formats using DATE:


GEL function

AIM: To verify Representation of different Q-formats using GEL function using


MATLAB

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

Representation of different Q-formats using GEL function using


MATLAB:-

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)

% written by Joe Hoffbeck, 2/5/17

% 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

% default format = 'hex'


if nargin < 4,
format = 'hex';
end
format = lower(format); % convert to lower case (to accept 'HEX' or 'BIN')

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

if ~strcmp(format,'hex') & ~strcmp(format,'bin'),


error('dec2q: format must be either ''hex'' or ''bin''')
end

N = a + b + 1; % number of bits in output number


y = [];
for i = 1:length(x),
% clip input to range of Qa.b
if x(i) < -2^a,
x(k) = -2^a;
disp('dec2q: input clipped (too small)')
end
if x(i) > 2^a - 2^-b,
x(i) = 2^a - 2^-b;
disp('dec2q: input clipped (too big)')
end

% scale input to an integer and convert to two's complement format


if x(i) >= 0,
d = dec2bin(x(i)*2^b,N); % if positive, convert to binary
else
d = dec2bin(2^N - abs(x(i)*2^b),N); % if negative, take two's complement
and convert to binary
end

% convert to hex (if needed)


if strcmp(format,'hex'),
if round(N/4) ~= N/4,
error('dec2q: hex output not supported for these values of a and b because the
number of bits is not a multiple of 4')
end
d = dec2hex(bin2dec(d),N/4);
end

y(i,:) = d;
end
y=char(y);

18
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

EXP NO:8 IMAGE ENHANCEMENT USING SPATIAL AND DATE:


FREQUENCY DOMAIN

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

Image Enhancement Using Spatial And Frequency Domain using


MATLAB:-

Program

footBall=imread('football.jpg');
%Convert to grayscale
footBall=rgb2gray(footBall);
imshow(footBall)

%Determine good padding for Fourier transform


PQ = paddedsize(size(footBall));

%Create a Gaussian Lowpass filter 5% the width of the Fourier transform


D0 = 0.05*PQ(1);
H = lpfilter('gaussian', PQ(1), PQ(2), D0);

% Calculate the discrete Fourier transform of the image


F=fft2(double(footBall),size(H,1),size(H,2));

% Apply the highpass filter to the Fourier spectrum of the image


LPFS_football = H.*F;

% convert the result to the spacial domain.


LPF_football=real(ifft2(LPFS_football));

% Crop the image to undo padding


LPF_football=LPF_football(1:size(footBall,1), 1:size(footBall,2));

%Display the blurred image


figure, imshow(LPF_football, [])

% Display the Fourier Spectrum


% Move the origin of the transform to the center of the frequency rectangle.
Fc=fftshift(F);
Fcf=fftshift(LPFS_football);
% use abs to compute the magnitude and use log to brighten display
S1=log(1+abs(Fc));
S2=log(1+abs(Fcf));
figure, imshow(S1,[])
figure, imshow(S2,[])

20
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

EXP NO:9 Implementation of Image segmentation techniques DATE:

AIM: To verify Implementation of Image segmentation techniques using MATLAB

EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter

Implementation of Image segmentation techniques using MATLAB:-

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

EXP NO:10 Extraction of frames from video signal DATE:

AIM: To verify Extraction of frames from video signal using MATLAB

EQUIPMENT REQUIRED:
Hardware required Software Required
PC MATLAB
DSK6713 DSP Starter kit
USB Cable OS: Windows XP
Power Adapter

Extraction of frames from video signal using MATLAB:-

Program

%How to get frames from a video

mov=aviread('fun.avi');

23
Department of Electronics & Communication Engineering
ADVANCED DIGITAL SIGNAL PROCESSING LAB

Im=frame2im(mov(1,58));
figure,imshow(Im);

The above process can be done using 'mmreader' function also.

MATLAB CODE:

Vobj=mmreader('fun.avi');

Im=read(Vobj,58);
imshow(Im);

Lmov=aviread('smiley.avi');

MIm=frame2im(Lmov(1,1));
figure,imshow(MIm);

%Preallocating the structure array


frame=struct('cdata',1,'colormap',cell([1 91]));

I added the modified frames to the original video.


%Modify the video in the middle
frame(1,1:57)=mov(1,1:57);
frame(1,58:87)=Lmov(1,1:30);
frame(1,88:91)=mov(1,64:67);
implay(frame,5);

%Part of the video


scz=figure;
set(scz, 'position', [300 100  size(Im,1)+130 size(Im,2)-100]);
FRange=[1 27:33];
%Here 1 is for the number of times the video has to be repeated
%27:33 indicates the frames from 27 to 33.
movie(scz,mov,FRange,5);

%To save the desired part alone

obj=avifile('VidPart.avi','FPS',5);
obj=addframe(obj,mov(27:33));
obj=close(obj);

24

You might also like