You are on page 1of 70

DIGITAL SIGNAL PROCESSING LAB Dept.

of ECE

TABLE OF CONTENTS
NAME OF THE EXPERIMENT PAGE
S.NO.
PART-1( SIGNALS ) NO
1 Generation of discrete time signals for discrete signals
To verify Linear Convolution
2 a) Using MATLAB
b) Using Code Composer Studio(CCS)
To verify Circular Convolution for discrete signals
3 a) Using MATLAB
b) Using Code Composer Studio(CCS)
4 To find the addition of sinusoidal signals
To verify Discrete Fourier Transform(DFT) and Inverse Discrete Fourier
Transform(IDFT)
5
a) Using MATLAB
b) Using Code Composer Studio(CCS)
Transfer Function Stability Analysis: using pole-zero plot, bode plot,
6
Nyquist plot, z-plane plot.
PART-2 ( FILTERS )
7 Frequency Response of IIR low pass Butterworth Filter
8 Frequency Response of IIR high pass Butterworth Filter
9 Frequency Response of IIR low pass Chebyshev Filter
10 Frequency Response of IIR high pass Chebyshev Filter
11 Frequency Response of FIR low pass Filter using Rectangle Window
12 Frequency Response of FIR low pass Filter using Triangle Window
PART – 3( IMAGE PROCESSING )
13 An image processing in a false contouring system
14 To generate the histogram equalization to the image
To verify the Normalized Cross Correlation to the addition of noise and
15
removal of noise using filters to an image
16 Compute the edge of an image using spatial filters.
Perform the image motion blur and calculate PSNR to the noise image and
17
also noise free image.
To verify the PSNR to the Second order Decomposition of Discrete
18 Wavelet transforms and to the reconstructed image using inverse Discrete
Wavelet transform

1
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO STUDY THE ARCHITECTURE OF DSP CHIPS–


TMS 320 CSA / INSTRUCTIONS
AIM: To study the architecture of DSP processor TMS 320C6713 / Instructions.

TOOLS REQUIRED:
TMS 320 C6713 Kit,
Code Composer Studio Software,
Personal Computer
BLOCK DIAGRAM

TMS320C6713 DSK Overview Block Diagram

2
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

DESCRIPTION:

The C6713 Digital Signal Processor (DSP) Starter Kit (DSK) builds on Texas Instruments
(TI's) industry-leading line of low cost, easy-to-use DSK development boards. The high-
performance board features the TMS320C6713 floating-point DSP. Capable of performing
1350 Million Floating-point Operations per Second (MFLOPS), the C6713 DSP makes the
C6713 DSK the most powerful DSK development board. The DSK is USB port interfaced
platform that allows efficiently developing and testing applications for the C6713. The DSK
consists of a C6713-based printed circuit board that will serve as a hardware reference design
for TI’s customers’ products. With extensive host PC and target DSP software support,
including bundled TI tools, the DSK provides ease-of-use and capabilities that are attractive
to DSP engineers.
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C6713 DSK provides:
 A USB Interface
 SDRAM and ROM
 An analog interface circuit for Data conversion (AIC)
 An I/O port
 Embedded JTAG emulation support

The C6711 DSK includes a stereo codec. This analog interface circuit (AIC) has the
following characteristics:
1. High-Performance Stereo Codec
 90-dB SNR Multibit Sigma-Delta ADC (A-weighted at 48 kHz)
 100-dB SNR Multibit Sigma-Delta DAC (A-weighted at 48 kHz)
 1.42 V – 3.6 V Core Digital Supply: Compatible With TI C54x DSP Core
Voltages
 2.7 V – 3.6 V Buffer and Analog Supply: Compatible Both TI C54x DSP
Buffer Voltages
 8-kHz – 96-kHz Sampling-Frequency Support

3
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Fig1.1: TMS320C67XX CPU DataPath

4
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

2. Software Control Via TI McBSP-Compatible Multiprotocol Serial Port


 I 2 C-Compatible and SPI-Compatible Serial-Port Protocols
 Glueless Interface to TI McBSPs

3. Audio-Data Input/Output Via TI McBSP-Compatible Programmable Audio Interface


 I 2 S-Compatible Interface Requiring Only One McBSP for both ADC and
DAC
 Standard I 2 S, MSB, or LSB Justified-Data Transfers
 16/20/24/32-Bit Word Lengths

The C6713DSK has the following features:


The 6713 DSK is a low-cost standalone development platform that enables customers to
evaluate and develop applications for the TI C67XX DSP family. The DSK also serves as a
hardware reference design for the TMS320C6713 DSP. Schematics, logic equations and
application notes are available to ease hardware development and reduce time to market.
The DSK uses the 32-bit EMIF for the SDRAM (CE0) and daughter card expansion interface
(CE2 and CE3). The Flash is attached to CE1 of the EMIF in 8-bit mode.
An on-board AIC23 codec allows the DSP to transmit and receive analog signals. McBSP0
is used for the codec control interface and McBSP1 is used for data. Analog audio I/O is
done through four 3.5mm audio jacks that correspond to microphone input, line input, line
output and headphone output. The codec can select the microphone or the line input as the
active input. The analog output is driven to both the line out (fixed gain) and headphone
(adjustable gain) connectors. McBSP1 can be re-routed to the expansion connectors in
software.
The DSK includes 4 LEDs and 4 DIP switches as a simple way to provide the user with
interactive feedback. Both are accessed by reading and writing to the CPLD registers.
An included 5V external power supply is used to power the board. On-board voltage
regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A
voltage supervisor monitors the internally generated voltage, and will hold the board in reset,
until the supplies are within operating specifications and the reset button is released. If
desired, JP1 and JP2 can be used as power test points for the core and I/O power supplies.

Code Composer communicates with the DSK through an embedded JTAG emulator with a
USB host interface. The DSK can also be used with an external emulator through the
external JTAG connector.

5
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

TMS320C6713 DSP Features


 Highest-Performance Floating-Point Digital Signal Processor (DSP):
 Eight 32-Bit Instructions/Cycle
 32/64-Bit Data Word
 300-, 225-, 200-MHz (GDP), and 225-, 200-, 167-MHz Clock Rates
 3.3-, 4.4-, 5-, 6-Instruction Cycle Times
 2400/1800, 1800/1350, 1600/1200, and 1336/1000 MIPS /MFLOPS
 Rich Peripheral Set, Optimized for Audio
 Highly Optimized C/C++ Compiler
 Extended Temperature Devices Available

Fig 1.2: TMS320C6713 DSP Block Diagram

 Advanced Very Long Instruction Word (VLIW) TMS320C67x DSP Core


 Eight Independent Functional Units:
 Two ALUs (Fixed-Point)
 Four ALUs (Floating- and Fixed-Point)
 Two Multipliers (Floating- and Fixed-Point)
 Load-Store Architecture with 32 32-Bit General-Purpose Registers
6
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

 Instruction Packing Reduces Code Size


 All Instructions Conditional
 Instruction Set Features
 Native Instructions for IEEE 754
 Single- and Double-Precision
 Byte-Addressable (8-, 16-, 32-Bit Data)
 8-Bit Overflow Protection
 Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization
 L1/L2 Memory Architecture
 4K-Byte L1P Program Cache (Direct-Mapped)
 4K-Byte L1D Data Cache (2-Way)
 256K-Byte L2 Memory Total: 64K-Byte L2 Unified Cache/Mapped RAM, and 192K-
Byte Additional L2 Mapped RAM
 Device Configuration
 Boot Mode: HPI, 8-, 16-, 32-Bit ROM Boot
 Endianness: Little Endian, Big Endian
 32-Bit External Memory Interface (EMIF)
 Glueless Interface to SRAM, EPROM, Flash, SBSRAM, and SDRAM
 512M-Byte Total Addressable External Memory Space
 Enhanced Direct-Memory-Access (EDMA) Controller (16 Independent Channels)
 16-Bit Host-Port Interface (HPI)
 Two Multichannel Audio Serial Ports (McASPs)
 Two Independent Clock Zones Each (1 TX and 1 RX)
 Eight Serial Data Pins Per Port:
   Individually Assignable to any of the Clock Zones
 Each Clock Zone Includes:
 Programmable Clock Generator
 Programmable Frame Sync Generator
 TDM Streams From 2-32 Time Slots
 Support for Slot Size:
   8, 12, 16, 20, 24, 28, 32 Bits
 Data Formatter for Bit Manipulation
 Wide Variety of I2S and Similar Bit Stream Formats
 Integrated Digital Audio Interface Transmitter (DIT) Supports:
 S/PDIF, IEC60958-1, AES-3, CP-430 Formats
 Up to 16 transmit pins

7
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

 Enhanced Channel Status/User Data


 Extensive Error Checking and Recovery
 Two Inter-Integrated Circuit Bus (I2C Bus™) Multi-Master and Slave Interfaces
 Two Multichannel Buffered Serial Ports:
 Serial-Peripheral-Interface (SPI)

PROCEDURE USED FOR RUNNING CODE COMPOSER STUDIO:

1. Click on the Code Composer Studio. And create the project of your own i.e. as shown
below:

2. To create the new source file, Click on File-> NEW-> Source file

8
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

3. Write the program in edit window and save the file in your project as *.C (for C
Program) or *.asm (Assembly Language Program)

TMS320C6713 CPU contains :


1. Program Fetch unit
2. Instruction dispatch unit
3. Instruction decode unit
4. Two data paths, each with four functional units
5. 32 32-bit registers
6. Control registers
7. Control logic
8. Test, emulation, and interrupt logic

4. Click on Project ->Add files to Project-> click your Source file.

9
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

10
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

5. Click on Project ->Add files to Project ->C:\CCStudio\cgtools\lib\rts6700.lib


(File type is Object and Library Files *.o, *.l)

6. Click Project ->Add files to Project -:\CCStudio\Tutorial\dsk6713\hello1\hello.cmd


(File type is Linker Command File *.cmd)

Mapping Between Instructions and Functional Units : The following Table shows which
instructions can be executed in which of the functional units for fixed point instructions.

11
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

12
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

7. Click on Project -> Compile your file.

8. Click on Project-> Build your File.

9. Click on File-> Load project.

13
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Mapping Between Instructions and Functional Units : The following Table shows which
instructions can be executed in which of the functional units for floating point instructions.

14
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

10. Disassembly file is available in the below Window.

11. Click on Debug -> Run (see the result in the Output window.)

15
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Program:
.global _main
_main:
MVKL .S1 -5, A4
ABS .L1 A4, A4
ZERO .L1 A3
ADD .L1 A4, A4, A3
SUB .L1 A3, A4, A5
MPY .M1 A3, A4, A0
NOP 1
SUB .L2X A0, B0, B0
B B3
NOP 5

RESULT:

16
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

GENERATION OF DISCRETE TIME SIGNALS FOR


DISCRETE SIGNALS
AIM: Generation of discrete time signals for discrete signals.

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.

MATLAB PROGRAM FOR UNIT SAMPLE SEQUENCE:


clc;
clear all;
close all;
n = -5:15;
g = [zeros(1,5) ones(1,1) zeros(1,15)];
h = [zeros(1,10) ones(1,1) zeros(1,10)];
subplot(2,1,1);
stem(n,g);
xlabel('time index');
ylabel('amplitude');
title('UNIT SAMPLE SEQUENCE');
axis([-5 15 0 1.2]);
subplot(2,1,2);
stem(n,h);
xlabel('time index');
ylabel('amplitude');
title(' DELAYED UNIT SAMPLE SEQUENCE');
axis([-5 15 0 1.2]);

MATLAB PROGRAM FOR UNIT STEP SEQUENCE:


clc;
clear all;
close all;
n = -5:15;
i = [zeros(1,5) ones(1,6) zeros(1,10)];
j = [zeros(1,10) ones(1,6) zeros(1,5)];
17
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

subplot(2,1,1);
stem(n,i);
xlabel('time index');
ylabel('amplitude');
title(' UNIT STEP SEQUENCE');
axis([-5 15 0 1.2]);
subplot(2,1,2);
stem(n,j);
xlabel('time index');
ylabel('amplitude');
title(' DELAYED UNIT STEP SEQUENCE');
axis([-5 15 0 1.2]);

MATLAB PROGRAM FOR SINE WAVE:


clc;
clear all;
close all;
t=0:0.2:10;
y=sin(2*pi*t/5);
subplot(2,1,1);
plot(t,y);
xlabel('time index');
ylabel('amplitude');
title('SINE WAVE');
subplot(2,1,2);
stem(t,y);
xlabel('time index');
ylabel('amplitude');
title('SINE WAVE');

MATLAB PROGRAM FOR RAMP SIGNAL:


clc;
clear all;
close all;
m=1;
t=0:.1:1;

18
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

y=m*t;
subplot(2,1,1);
plot(t,y);
xlabel('time index');
ylabel('amplitude');
title('UNIT RAMP');
subplot(2,1,2);
stem(t,y);
xlabel('time index');
ylabel('amplitude');
title('UNIT RAMP');

MATLAB PROGRAM FOR TRIANGULAR WAVE:


clc;
clear all;
close all;
m=-1;
t=0:1:10;
y=m.^t;
subplot(2,1,1);
plot(t,y);
xlabel('time index');
ylabel('amplitude');
title('TRIANGULAR WAVE');
subplot(2,1,2);
stem(t,y);
xlabel('time index');
ylabel('amplitude');
title('TRIANGULAR WAVE');

19
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MODEL WAVEFORMS:

UNIT SAMPLE:
UNIT SAMPLE SEQUENCE

1
amplitude

0.5

0
-5 0 5 10 15
time index
DELAYED UNIT SAMPLE SEQUENCE

1
amplitude

0.5

0
-5 0 5 10 15
time index

UNIT STEP:

UNIT STEP SEQUENCE

1
amplitude

0.5

0
-5 0 5 10 15
time index
DELAYED UNIT STEP SEQUENCE

1
amplitude

0.5

0
-5 0 5 10 15
time index

20
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

SINE WAVE:

SINE WAVE
1

0.5
amplitude

-0.5

-1
0 1 2 3 4 5 6 7 8 9 10
time index
SINE WAVE
1

0.5
amplitude

-0.5

-1
0 1 2 3 4 5 6 7 8 9 10
time index

RAMP SIGNAL:

UNIT RAMP
1
amplitude

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index
UNIT RAMP
1
amplitude

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index

21
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

TRIANGULAR SIGNAL:
TRIANGULAR WAVE
1

0.5
amplitude

-0.5

-1
0 1 2 3 4 5 6 7 8 9 10
time index
TRIANGULAR WAVE
1

0.5
amplitude

-0.5

-1
0 1 2 3 4 5 6 7 8 9 10
time index

RESULT:

22
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
TO VERIFY LINEAR CONVOLUTION
AIM: To write a program to compute the response of a discrete LTI system with input
sequence x(n) and impulse response h(n) by using linear convolution.
TOOLS REQUIRED:
TMS 320 C6713 Simulator/Kit,
Code Composer Studio Software,
MATLAB Software,
Personal Computer
PROCEDURE FOR CODE COMPOSER STUDIO:
1. Create a Project in Code Composer Studio.
2. Create a Source file in C language for Linear Convolution and add it to the project.
3. Add both hello.cmd & rts6700.lib files to the current project folder from the
following locations:
C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd and
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib
4. Compile C file for debugging errors.
5. Build the project.
6. Load Program (.out file) into DSK from file menu.
7. Run the program from Debug menu.
8. Plot the Graph of linear convolution from View – graph menu.

C-PROGRAM FOR LINEAR CONVOLUTION:

#include<stdio.h>
int x[20],h[20],y[20],N1,N2,n,m;
main()
{
printf("Enter the length of input sequence x(n)\t:N1=");
scanf("%d",&N1);
printf("Enter the length of impulse response h(n)\t:N2=");
scanf("%d",&N2);
printf("Enter %d samples for input sequence x(n):\n",N1);
for(n=0;n<N1;n++)
scanf("%d",&x[n]);
printf("Enter %d samples for impulse response h(n):\n",N2);
for(n=0;n<N2;n++)

23
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

scanf("%d",&h[n]);
printf("Input sequence \nx(n)=");
for(n=0;n<N1;n++)
printf("\t%d",x[n]);
printf("\nImpulse Response \nh(n)=");
for(n=0;n<N2;n++)
printf("\t%d",h[n]);
for(n=0;n<N1+N2-1;n++)
{
y[n]=0;
for(m=0;m<=n;m++)
y[n]=y[n]+x[m]*h[n-m];
}
printf("\n Response of LT1 system is\ny(n)=");
for(n=0;n<N1+N2-1;n++)
printf("\t%d",y[n]);
}
INPUT:
Enter the length of input sequence x(n) :N1=
Enter the length of impulse response h(n):N2=
Enter 4 samples for input sequence x(n):
Enter 4 samples for impulse response h(n):

Response of LT1 system is

y(n) =

24
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MODEL GRAPH:

MATLAB PROGRAM FOR LINEAR CONVOLUTION:


clc;
clear all;
close all;
x1=input('enter the sequence'); % input sequence one
x2=input('enter the sequence'); %input sequence two
n1=length(x1); %finding length of x1
n2=length(x2); %finding length of x2
n=n1+n2-1;
x=x1'*x2; %multiplying the two sequences
display(x); %display x values
s=zeros(1, n); %add zeros to x
for i=1:n1 % increment the 1st sequence with for loop
for j=1:n2 %increment the 2nd sequence with for loop
k=i+j; %k for incrementing output sequence
s(k-1)=s(k-1)+x(i, j); %output equation for linear convolution
display(s); %display output values
end
end
display(s);
subplot(3, 1, 1);
stem(x1); %plot for input sequence one
xlabel(‘n1--->’);
ylabel(‘amplitude’);
title(‘input sequence one’);
subplot(3, 1, 2);
25
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

stem(x2);
xlabel(‘n2--->’); %plot for input sequence two
ylabel(‘amplitude’);
title(‘input sequence two’);
subplot(3, 1, 3);
stem(s);
xlabel(‘n--->’); %plot for linear convolution sequence
ylabel(‘amplitude’);
title(‘linear convolution sequence ’);

MODEL GRAPH:

input sequence one


5
amplitude

0
1 1.5 2 2.5 3 3.5 4
n1--->
input sequence two
4
amplitude’

0
1 1.5 2 2.5 3 3.5 4
n2--->
linear convolution sequence
40
amplitude

20

0
1 2 3 4 5 6 7
n--->

RESULT:

26
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
TO VERIFY CIRCULAR CONVOLUTION
AIM: To write a program to compute the response of a discrete LTI system with input
sequence x(n) and impulse response h(n) by using Circular convolution.
TOOLS REQUIRED:
TMS 320 C6713 Simulator/Kit,
Code Composer Studio Software,
MATLAB Software,
Personal Computer
PROCEDURE:
1. Create a Project in Code Composer Studio.
2. Create a Source file in C language for Circular Convolution and add it to the project.
3. Add both hello.cmd & rts6700.lib files to the current project folder from the
following locations:
4. C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd and
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib
5. Compile C file for debugging errors.
6. Build the project.
7. Load Program (.out file) into DSK from file menu.
8. Run the program from Debug menu.
9. Plot the Graph of Circular convolution from View – graph menu.
C-PROGRAM FOR CIRCULAR CONVOLUTION:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
27
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

if(m-n!=0) /*If length of both sequences are not equal*/


{
{
if(m>n) /* Pad the smaller sequence with zero*/
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf(“%d \t”,y[i]);
}

28
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

INPUT:
Enter the length of input sequence x(n) :N1=
Enter the length of impulse response h(n):N2=
Enter 4 samples for input sequence x(n):
Enter 4 samples for impulse response h(n):
Input sequence after zero padding
x(n)=
Impulse Response after zero padding

h(n)=

Response of LT1 system is


y(n)=
GRAPH SETTINGS:

MODEL GRAPH

29
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MATLAB PROGRAM FOR CIRCULAR CONVOLUTION:


clc;
clear all;
close all;
x1= input ('enter the first sequence');
x2= input ('enter the second sequence');
n1= length(x1);
n2= length(x2);
N=max(n1,n2);%length of sequence
x1=[x1 zeros(1,N-n1)]; %modified first sequence
x2=[x2 zeros(1,N-n2)]; %modified second sequence
for n=0:N-1
y(n+1)=0;
for i=0:N-1
j=mod(n-i,N);
y(n+1)=y(n+1)+x1(i+1)*x2(j+1); %shifting and adding
end
end
%to display and plot circular convolution
n=1:N;
disp('output sequence of circular convolution');
disp(y); %to view output in command window
%plotting circular convolution
subplot(3,1,1);
stem(x1);
xlabel('n1---->');
ylabel('amplitude');
title('first sequence');
subplot(3,1,2);
stem(x2);
xlabel('n2---->');
ylabel('amplitude');
title('second sequence');
subplot(3,1,3);
stem(n,y);
xlabel('n--->');

30
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

ylabel('amplitude');
title('circular convolution sequence of x and h');

MODEL GRAPH:

first sequence
4
amplitude

0
1 1.5 2 2.5 3 3.5 4
n1---->
second sequence
2
amplitude

0
1 1.5 2 2.5 3 3.5 4
n2---->
circular convolution sequence of x and h
20
amplitude

10

0
1 1.5 2 2.5 3 3.5 4
n--->

RESULT:

31
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO FIND ADDITION OF SINUSOIDAL SIGNALS


AIM: To find addition of sinusoidal signals using MATLAB
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM:

clc;
clear all;
close all;
t=0:0.001:20;
x1=sin(2*pi*t/5);
subplot(3,1,1);
plot(t,x1);
xlabel('TIME INDEX');
ylabel('AMPLITUDE');
title('SUM OF SINE WAVES');
x2=sin(2*pi*t/7);
subplot(3,1,2);
plot(t,x2);
xlabel('TIME INDEX');
ylabel('AMPLITUDE');
x=x1+x2;
subplot(3,1,3);
plot(t,x);
xlabel('TIME INDEX');
ylabel('AMPLITUDE');

32
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MODEL GRAPH:
SUM OF SINE WAVES
1

AMPLITUDE 0

-1
0 2 4 6 8 10 12 14 16 18 20
TIME INDEX
1
AMPLITUDE

-1
0 2 4 6 8 10 12 14 16 18 20
TIME INDEX
2
AMPLITUDE

-2
0 2 4 6 8 10 12 14 16 18 20
TIME INDEX

RESULT:

33
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO VERIFY DISCRETE FOURIER TRANSFORM (DFT)


AND
INVERSE DISCRETE FOURIER TRANSFORM (IDFT)

AIM: To verify Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform
(IDFT) using MATLAB
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM:

clc;
clear all;
close all;
x=input('enter the input sequence')
N=length(x);
% predefined function DFT
y1=fft(x);
y1
% user defined function DFT
for n=0:N-1
y(n+1)=0;
for k=0:N-1
y(n+1)=y(n+1)+x(k+1)*exp(-1i*2*pi*k*n/N);
end
end
% user defined function IDFT
for k=0:N-1
y2(k+1)=0;
for n=0:N-1
y2(k+1)=y2(k+1)+y(n+1)*exp(1i*2*pi*k*n/N);
end
end
y3=y2/N;
y3
m=20*log10(abs(y));
34
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

f =(0:length(y)-1)*100/length(y);
subplot(2,2,1)
stem(x)
xlabel(' sample index')
ylabel('amplitude')
title('Input sequence');grid on;
subplot(2,2,2)
plot(f,m) ;
xlabel(' Normalized Frequency')
ylabel('magnitude in dB ')
title('Magnitude Response of a given sequence x[n]');grid on;
subplot(2,2,3)
stem(abs(y3))
xlabel(' sample index')
ylabel('amplitude')
title('Inverse DFT plot');grid on;
subplot(2,2,4)
plot(f,angle(y)*(180/pi))
xlabel(' Normalized Frequency')
ylabel('Phase in Radians')
title('phase Response of a given sequence x[n]');grid on;
MODEL GRAPH:

Input sequence Magnitude Response of a given sequence x[n]


1 200
magnitude in dB

0
amplitude

0.5
-200

0 -400
0 2 4 6 8 0 20 40 60 80 100
sample index Normalized Frequency
Inverse DFT plot phase Response of a given sequence x[n]
1.5 200
Phase in Radians

100
1
amplitude

0
0.5
-100

0 -200
0 2 4 6 8 0 20 40 60 80 100
sample index Normalized Frequency

RESULT:

35
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TRANSFER FUNCTION STABILITY ANALYSIS :


USING POLE-ZERO PLOT, BODE PLOT, NYQUIST PLOT,
Z-PLANE PLOT
AIM: To verify Transfer Function Stability Analysis: using pole-zero plot, bode plot,
Nyquist plot, z-plane plot using MATLAB
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR POLE-ZERO PLOT:

clc;
clear all;
close all;
num=input('enter the numerator polynomial vector\n'); % [1 -2 1]
den=input('enter the denominator polynomial vector\n'); % [1 6 11 6]
H=tf(num,den)
[p z]=pzmap(H);
disp('zeros are at ');
disp(z);
disp('poles are at ');
disp(p);
pzmap(H);
if max(real(p))>=0
disp(' All the poles do not lie in the left half of S-plane ');
disp(' the given LTI system is not a stable system ');
else
disp('All the poles lie in the left half of S-plane ');
disp(' the given LTI system is a stable system ');
end;

36
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MODEL GRAPH FOR POLE ZERO PLOT:

Pole-Zero Map
1

0.8

0.6
Imaginary Axis (seconds-1)

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1
-1
Real Axis (seconds )

MATLAB PROGRAM FOR Z-PLANE PLOT:

clc; clear all;


close all;
num=input('enter the numerator polynomial vector \n'); %[1 0 0]
den=input('enter the denominator polynomial vector \n');%[1 1 0.16]
H=filt(num,den)
z=zero(H);
disp('the zeros are at ');
disp(z);
[r p k]=residuez(num,den);
disp('the poles are at ');
disp(p);
zplane(num,den);
title('Pole-Zero map in the Z-plane');
if max(abs(p))>=1
disp('all the poles do not lie within the unit circle');
disp('hence the system is not stable');
else
disp('all the poles lie within the unit circle');
disp('hence the system is stable');
end;
37
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

MODEL GRAPH FOR Z-PLANE PLOT:


Pole-Zero map in the Z-plane

0.8

0.6

0.4
Imaginary Part

0.2
2
0

-0.2

-0.4

-0.6

-0.8

-1
-1 -0.5 0 0.5 1
Real Part

RESULT:

38
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

PART -2 (FILTERS)

39
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
FREQUENCY RESPONSE OF IIR BUTTERWORTH
LOWPASS FILTER
AIM: To find frequency response of IIR low pass Butterworth filter using MATLAB

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR IIR BUTTERWORTH LOW PASS FILTER:
clc; clear all; close all;
fp=input('Enter the pass band frequency: ');
fs=input('Enter the stop band frequency: ');
rp=input('Enter the pass band ripple: ');
rs=input('Enter the stop band ripple: ');
f=input ('Enter the sample frequency: ');
wp=2*pi*fp;
ws=2*pi*fs;
w1=wp/f;
w2=ws/f;
[N,WN]=buttord(w1,w2,rp,rs);
[B,A]=butter(N,WN,'LOW');
w=0:0.01:pi;
[H1,om]=freqz(B,A,w);
m=20*log10(abs(H1));
an=angle(H1);
subplot(2,1,1);
plot(om/pi,m);
xlabel(' (a) Normalised frequency');
ylabel(' Gain in dB');
title('BUTTERWORTH LOW PASS FILTER');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel(' (b) Normalised frequency');
ylabel(' Phase in radians');
grid;

40
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

INPUTS:
Enter the pass band frequency: 500
Enter the stop band frequency: 550
Enter the pass band ripple 0.1
Enter the stop band ripple 0.2
Enter the sample frequency 10000

MODEL GRAPH:
BUTTERWORTH LOW PASS FILTER
100

0
Gain in dB

-100

-200

-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency

4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency

RESULT:

41
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
FREQUENCY RESPONSE OF IIR BUTTERWORTH
HIGH PASS FILTER
AIM: To find the frequency response of IIR high pass Butterworth filter using MATLAB

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR IIR BUTTERWORTH HIGH PASS FILTERS:
clc; clear all; close all;
fp=input('Enter the pass band frequency:');
fs=input('Enter the stop band frequency:');
rp=input('Enter the pass band ripple:');
rs=input('Enter the stop band ripple:');
f=input ('Enter the sample frequency :');
wp=2*pi*fp;
ws=2*pi*fs;
w1=wp/f;
w2=ws/f;
[N,WN]=buttord(w1,w2,rp,rs);
[B,A]=butter(N,WN,'HIGH');
w=0:0.01:pi;
[H1,om]=freqz(B,A,w);
m=20*log10(abs(H1));
an=angle(H1);
subplot(2,1,1);
plot(om/pi,m);
xlabel(' (a) Normalised frequency');
ylabel(' Gain in dB');
title('BUTTERWORTH HIGH PASS FILTER');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel(' (b) Normalised frequency');
ylabel(' Phase in radians');
grid;

42
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

INPUTS:

Enter the pass band frequency: 550


Enter the stop band frequency: 500
Enter the pass band ripple: 0.1
Enter the stop band ripple: 0.2
Enter the sample frequency: 10000

MODEL GRAPH:

BUTTERWORTH HIGH PASS FILTER


50

0
Gain in dB

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency

4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency

RESULT:

43
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
FREQUENCY RESPONSE OF IIR LOWPASS
CHEBYSHEV FILTER
AIM: To find the frequency response of IIR low pass Chebyshev filter using MATLAB

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR IIR CHEBYSHEV LOW PASS FILTER:
clc; clear all; close all;
fp=input('Enter the pass band frequency: ');
fs=input('Enter the stop band frequency: ');
rp=input('Enter the pass band ripple: ');
rs=input('Enter the stop band ripple: ');
f=input ('Enter the sample frequency: ');
wp=2*pi*fp;
ws=2*pi*fs;
w1=wp/f;
w2=ws/f;
[N,WN]=cheb1ord(w1,w2,rp,rs);
[B,A]=cheby1(N,rp,WN,'LOW');
w=0:0.01:pi;
[H,om]=freqz(B,A,w);
m=20*log10(abs(H));
an=angle(H);
subplot(2,1,1);
plot(om/pi,m);
xlabel(' (a) Normalised frequency');
ylabel(' Gain in dB');
title('CHEBYSHEV LOW PASS FILTER');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel(' (b) Normalised frequency');
ylabel(' Phase in radians');
grid;

44
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

INPUTS:
Enter the pass band frequency: 500
Enter the stop band frequency: 550
Enter the pass band ripple: 0.1
Enter the stop band ripple: 0.2
Enter the sample frequency: 10000

MODEL GRAPH:
CHEBYSHEV LOW PASS FILTER
0

-50
Gain in dB

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency

0
Phase in radians

-1

-2

-3

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency

RESULT:

45
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:
FREQUENCY RESPONSE OF IIR HIGHPASS
CHEBYSHEV FILTER
AIM: To find the frequency response of IIR High pass Chebyshev Filter using MATLAB

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR IIR CHEBYSHEV HIGH PASS FILTER:
clc; clear all; close all;
fp=input('Enter the pass band frequency: ');
fs=input('Enter the stop band frequency: ');
rp=input('Enter the pass band ripple: ');
rs=input('Enter the stop band ripple: ');
f=input ('Enter the sample frequency: ');
wp=2*pi*fp;
ws=2*pi*fs;
w1=wp/f;
w2=ws/f;
[N,WN]=cheb1ord(w1,w2,rp,rs);
[B,A]=cheby1(N,rp,WN,'high');
w=0:0.01:pi;
[H,om]=freqz(B,A,w);
m=20*log10(abs(H));
an=angle(H);
subplot(2,1,1);
plot(om/pi,m);
xlabel(' (a) Normalised frequency');
ylabel(' Gain in dB');
title('CHEBYSHEV TYPE-1 HIGH PASS FILTER');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel(' (b) Normalised frequency');
ylabel(' Phase in radians');
grid;

46
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

INPUTS:
Enter the pass band frequency: 550
Enter the stop band frequency: 500
Enter the pass band ripple: 0.1
Enter the stop band ripple: 0.2
Enter the sample frequency: 10000

MODEL GRAPH:
CHEBYSHEV TYPE-1 HIGH PASS FILTER
0

-20
Gain in dB

-40

-60

-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency

4
Phase in radians

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency

RESULT:

47
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

FREQUENCY RESPONSE OF FIR LOWPASS FILTER USING


RECTANGULAR WINDOW

AIM: To write a program to design a FIR Low pass filter using Rectangular windowing
technique.

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of filter.
5. Find filter coefficients.
6. Draw the magnitude and phase response.
MATLAB PROGRAM FOR FIR FILTER USING RECTANGULAR WINDOW:
clc; clear all; close all;
fp=input('Enter the pass band frequency: ');
fs=input('Enter the stop band frequency: ');
rp=input('Enter the pass band ripple: ');
rs=input('Enter the stop band ripple: ');
f=input ('Enter the sample frequency: ');
wp=2*fp;
ws=2*fs;
w1=wp/f;
w2=ws/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;

48
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

end
y=boxcar(n1);
n1
b=fir1(n,w1,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
ylabel('Gain in dB -->');
xlabel('Normalised frequency');
title('FIR FILTER USING RECTANGULAR WINDOW');

INPUTS:
Enter the pass band frequency: 40
Enter the stop band frequency: 30
Enter the pass band ripple: 2
Enter the stop band ripple: 3
Enter the sample frequency: 500

MODEL GRAPH:
FIR FILTER USING RECTANGULAR WINDOW
20

-20
Gain in dB -->

-40

-60

-80

-100

-120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

RESULT:

49
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

FREQUENCY RESPONSE OF FIR LOWPASS FILTER USING


TRIANGULAR WINDOW

AIM: To write a program to design a FIR Low pass filter using Triangular windowing
technique.
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of filter.
5. Find filter coefficients.
6. Draw the magnitude and phase response
MATLAB PROGRAM FOR FIR FILTER USING TRIANGULAR WINDOW:

clc;
clear all;
close all;
fp=input('Enter the pass band frequency: ');
fs=input('Enter the stop band frequency: ');
rp=input('Enter the pass band ripple: ');
rs=input('Enter the stop band ripple: ');
f=input ('Enter the sample frequency: ');
wp=2*fp;
ws=2*fs;
w1=wp/f;
w2=ws/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
n1=n;
50
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

n=n-1;
end
%low pass filter
y=triang(n1);
n1
b=fir1(n,w1,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
ylabel('Gain in dB -->');
xlabel('Normalised frequency');
title('FIR FILTER LOWPASS FILTER USING TRIANGLAR WINDOW');

INPUTS:
Enter the pass band frequency: 40
Enter the stop band frequency: 30
Enter the pass band ripple: 2
Enter the stop band ripple: 3
Enter the sample frequency: 500
MODEL GRAPH:

FIR FILTER LOWPASS FILTER USING TRIANGLAR WINDOW


0

-10

-20
Gain in dB -->

-30

-40

-50

-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

RESULT:

51
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

PART -3
(IMAGE PROCESSING)

52
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

AN IMAGE PROCESSING IN A FALSE CONTOURING SYSTEM


AIM: To write a program to design an image processing in a false contouring system
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR A FALSE CONTOURING SYSTEM:

clc;
clear;
close all;
I=imread('cameraman.tif');
% A 256 gray-level image:
[I256,map256]=gray2ind(I,256);
[I128,map128]=gray2ind(I,128);
[I64,map64]=gray2ind(I,64);
[I32,map32]=gray2ind(I,32);
[I16,map16]=gray2ind(I,16);
[I8,map8]=gray2ind(I,8);
[I4,map4]=gray2ind(I,4);
[I2,map2]=gray2ind(I,2);
subplot(241);subimage(I256,map256);title('256');
subplot(242);subimage(I128,map128);title('128');
subplot(243);subimage(I64,map64);title('64');
subplot(244);subimage(I32,map32);title('32');
subplot(245);subimage(I16,map16);title('16');
subplot(246);subimage(I8,map8);title('8');
subplot(247);subimage(I4,map4);title('4');
subplot(248);subimage(I2,map2);title('2');

53
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

OUTPUT:

RESULT:

54
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO GENERATE THE HISTOGRAM EQUALIZATION TO THE IMAGE

AIM: To write a program to generate the histogram equalization to the image


TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM FOR HISTOGRAM EQUALIZATION TO THE IMAGE:

%Matlab Program for histogram equalization


clc;
clear;
close all;
I1=imread('pout.tif');
I = double(I1);
[m,n] = size(I);
%defining all possible image intensities in an array
L = 0:255;
% No of pixels of each intensity
C = zeros(1,256);
for i = 1:m
for j = 1:n
for k = 1:256
if I(i,j) == L(k)
C(k) = C(k) + 1;
end
end
end
end
% probability of each intensity
c_prob = C/(m*n);
% Cumulative sum of probabilities
cc_prob = cumsum(c_prob);
% converting these cumulative intensities into integers
out_int = zeros(1,256);
for i = 1:256
out_int(i) = floor(((cc_prob(i) - min(cc_prob))/(1 - min(cc_prob)))*255 + 0.5);
55
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

end
I_out = zeros(m,n);
for i = 1:m
for j = 1:n
I_out(i,j) = out_int(I(i,j) + 1);
end
end
subplot(131);
imshow(uint8(I));
title('original image');
subplot(132);
imshow(uint8(I_out));
title('histogram equalized image');
K1 = histeq(I1);
subplot(133);
imshow(K1);
title('matlab generated');

OUTPUT:

ANOTHER METHOD:

clc;
clear all;
close all;
I = imread('tire.tif');
J = histeq(I);
title('Original Image');
imshow(I)

56
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

title('Histogram Equilized Image');


figure, imshow(J)
% Display a histogram of the original image.
title('Histogram for Original');
figure; imhist(I,64)

% Compare it to a histogram of the processed image.


title('Histogram for Histogram Equilized image');
figure; imhist(J,64)

RESULT:

57
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO VERIFY THE NORMALIZED CROSS CORRELATION TO THE


ADDITION OF NOISE AND REMOVAL OF NOISE USING FILTERS
TO AN IMAGE
AIM: To write a program to verify the normalized cross correlation to the addition of noise
and removal of noise using filters to an image
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM TO VERIFY THE NORMALIZED CROSS CORRELATION
TO THE ADDITION OF NOISE AND REMOVAL OF NOISE USING FILTERS TO
AN IMAGE

% Matlab program for image smoothing


clc;
clear;
close all;
a = imread('cameraman.tif');
b = im2double(a);
c = imnoise(b,'gaussian',0,0.01);
psnr_noise= psnr(b,c);
mask = 1/9*ones(3);
d = imfilter(c,mask,'replicate');
psnr_filter = psnr(b,d);
imshow([b c d]);
title('orignial image, noisy image, filtered image');
psnr_noise
psnr_filter

OUTPUT VALUES:

psnr_noise = 20.3766
psnr_filter = 24.3529

58
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

OUTPUT:

% Matlab program for image smoothing


clc;
clear;
close all;
a = imread('cameraman.tif');
b = im2double(a);
c = imnoise(b,'salt & pepper');
psnr_noise= psnr(b,c);
[m,n] = size(b);
d_max = zeros(m,n);
d_min = zeros(m,n);
d_median = zeros(m,n);
for i = 2:m-1
for j = 2:n-1
d_max(i,j) = max(max(c(i-1:i+1,j-1:j+1)));
d_min(i,j) = min(min(c(i-1:i+1,j-1:j+1)));
d_median(i,j) = median(median(c(i-1:i+1,j-1:j+1)));
end
end
imshow([b d_max d_min d_median]);
title('original image,max output,min output,median output');
psnr_median = psnr(b,d_median);
psnr_max = psnr(b,d_max);
psnr_min = psnr(b,d_min);
psnr_noise
psnr_median
psnr_max
59
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

psnr_min
OUTPUT VALUES:

psnr_noise = 17.9269
psnr_median = 21.7282
psnr_max = 10.4916
psnr_min = 11.3655

OUTPUT:

ANOTHER METHOD:

%normalized cross correlation function verification


clc;
clear all;
close all;
A = imread('pout.tif');
B = imnoise(A,'salt & pepper', 0.02);
figure
subplot(1,2,1), imshow(A); % Display image
title('original image');
subplot(1,2,2), imshow(B); % Display image
title('Noise Effected image');
Num=sum(sum((A-mean2(A)).*(B-mean2(B))));
den1=sum(sum((A-mean2(A)).^2));
den2=sum(sum((B-mean2(B)).^2));
den=sqrt(den1*den2);
NCC=Num/den;
disp(NCC)

RESULT:

60
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

COMPUTE THE EDGE OF AN IMAGE USING SPATIAL FILTERS


AIM: To write a program to compute the edge of an image using spatial filters.
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM TO COMPUTE THE EDGE OF AN IMAGE USING SPATIAL
FILTERS.

% Edge of an image using roberts Operator % Gx = Gradient in X-Direction = [+1 0 ; 0 -1]


% Gy = Gradient in Y-Direction = [0 +1 ; -1 0]
clc;
clear;
close all;
I = imread('rice.png');
I = im2double(I);
[m,n] = size(I);
Gx = zeros(m,n);
Gy = zeros(m,n);
G = zeros(m,n);
for i = 2:(m-1)
for j = 2:(n-1)
Gx(i,j) = (I(i-1,j-1) - I(i,j));
Gy(i,j) = (I(i-1,j) - I(i,j-1));
G(i,j) = sqrt(Gx(i,j).^2 + Gy(i,j).^2);
end
end
imshow([Gx Gy G]);
title('Gradient in X-Direction Gradient in Y-Direction Edge Detected Image')
OUTPUT:

61
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

% Edge of an image using Prewitt Operator


% Gx = Gradient in X-Direction = [-1 0 1; -1 0 1;-1 0 1]
% Gy = Gradient in Y-Direction = [1 1 1 ;0 0 0;-1 -1 -1]
clc;
clear;
close all;
A = imread('rice.png');
A = im2double(A);
[m,n] = size(A);
Gx = zeros(m,n);
Gy = zeros(m,n);
G = zeros(m,n);
for i = 2:(m-1)
for j = 2:(n-1)
Gx(i,j) = (A(i-1,j+1) + A(i,j+1) + A(i+1,j+1)) - (A(i-1,j-1) + A(i,j-1) + A(i+1,j-1));
Gy(i,j) = (A(i-1,j-1) + A(i-1,j) + A(i-1,j+1)) - (A(i+1,j-1) + A(i+1,j) + A(i+1,j+1));
G(i,j) = sqrt(Gx(i,j).^2 + Gy(i,j).^2);
end
end
imshow([Gx Gy G]);
title('Gradient in X-Direction Gradient in Y-Direction Edge Detected Image');

OUTPUT:

62
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

% Edge of an image using sobel Operator


% Gx = Gradient in X-Direction = [-1 0 1; -2 0 2;-1 0 1]
% Gy = Gradient in Y-Direction = [1 2 1 ;0 0 0;-1 -2 -1]
clc;
clear;
close all;
A = imread('rice.png');
A = im2double(A);
[m,n] = size(A);
Gx = zeros(m,n);
Gy = zeros(m,n);
G = zeros(m,n);
for i = 2:(m-1)
for j = 2:(n-1)
Gx(i,j) = (A(i-1,j+1) + 2*A(i,j+1) + A(i+1,j+1)) - (A(i-1,j-1) + 2*A(i,j-1) + A(i+1,j-1));
Gy(i,j) = (A(i-1,j-1) + 2*A(i-1,j) + A(i-1,j+1)) - (A(i+1,j-1) + 2*A(i+1,j) + A(i+1,j+1));
G(i,j) = sqrt(Gx(i,j).^2 + Gy(i,j).^2);
end
end
imshow([Gx Gy G]);
title('Gradient in X-Direction Gradient in Y-Direction Edge Detected Image');

OUTPUT:

63
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

% Edge of an image using laplacian


% laplacian kernel : [0 -1 0;-1 4 -1;0 -1 0] without diagonals
% laplacian kernel : [-1 -1 -1;-1 8 -1;-1 -1 -1] with diagonals
clc;
clear;
close all;
A = imread('testpat1.png');
A = im2double(A);
[m,n] = size(A);
G1 = zeros(m,n);
G2 = zeros(m,n);
G = zeros(m,n);
for i = 2:(m-1)
for j = 2:(n-1)
G1(i,j) = 4*A(i,j) - (A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i,j+1));
G2(i,j) = 8*A(i,j) - (A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i,j+1) + A(i-1,j-1) + A(i+1,j-1) + A(i-1,j+1) +
A(i+1,j+1));
end
end
imshow([G1 G2]);
title('Laplacian without Diagonals Laplacian with Diagonals');

OUTPUT:

64
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

ANOTHER METHOD:

% This program demonstrates edge information of an image by using various


% edge operators
I=imread('cameraman.tif'); % Read in image
IEr = edge(I,'roberts'); % roberts edges
IEp = edge(I,'prewitt'); % prewitt edges
IEs = edge(I,'sobel'); % sobel edges
IEc = edge(I,'canny'); % canny edege detection
IElog = edge(I,'log'); % Laplacian of Gaussian edge detection
figure
subplot(2,3,1), imshow(I); % Display image
title('original image');
subplot(2,3,2), imshow(IEr); % Display image
title('Roberts');
subplot(2,3,3), imshow(IEp); % Display image
title('Prewitt');
subplot(2,3,4), imshow(IEs); % Display image
title('Sobel');
subplot(2,3,5), imshow(IEc); % Display image
title('Canny');
subplot(2,3,6), imshow(IElog); % Display image
title('Laplacian of Gaussian');

RESULT:

65
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

PERFORM THE IMAGE MOTION BLUR AND CALCULATE PSNR TO


THE NOISE IMAGE AND ALSO NOISE FREE IMAGE.
AIM: To write a program to perform the image motion blur and calculate PSNR to the noise
image and also noise free image.

TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM TO PERFORM THE IMAGE MOTION BLUR AND
CALCULATE PSNR TO THE NOISE IMAGE AND ALSO NOISE FREE IMAGE

clc;
clear;
close all;
%matlab program for debluring a motion blurred image using wiener filter
I = im2double(imread('cameraman.tif'));
% Simulate a Motion blur % defining the width of blurred pixels
LEN = 20;
% defining the angle of blur
THETA = 10;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
%restoring the blurred image using wiener filter
wnr1 = deconvwnr(blurred, PSF, 0);
imshow([I blurred wnr1]);
title('original image, motion blurred, deblurred using wiener filter');

OUTPUT:

66
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

ANOTHER METHOD:

clc;
clear all;
close all;
% Read an image into the MATLAB workspace
I = imread('cameraman.tif');
figure; imshow(I); title('Original Image');
% Motion Blur
h = fspecial('motion');
aw1 = imfilter(I,h);
figure;
imshow(aw1);
title('Motion Blurred Image');
A=I;
B=aw1;
ref=I;
A=aw1;
%Calculate the PSNR.
[peaksnr, snr] = psnr(A, ref);
fprintf('\n The Peak-SNR value is %0.4f', peaksnr);
fprintf('\n The SNR value is %0.4f \n', snr);

RESULT:

67
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

Expt.No: Date:

TO VERIFY THE PSNR TO THE SECOND ORDER DECOMPOSITION


OF DISCRETE WAVELET TRANSFORMS (DWT) AND
TO THE RECONSTRUCTED IMAGE USING
INVERSE DISCRETE WAVELET TRANSFORM (IDWT)
AIM: To write a program to verify the PSNR to the Second order Decomposition of
Discrete Wavelet transforms and to the reconstructed image using inverse Discrete Wavelet
transform
TOOLS REQUIRED:
MATLAB Software,
Personal Computer.
MATLAB PROGRAM TO VERIFY THE PSNR TO THE SECOND ORDER
DECOMPOSITION OF DISCRETE WAVELET TRANSFORMS AND TO THE
RECONSTRUCTED IMAGE USING INVERSE DISCRETE WAVELET
TRANSFORM

clc;
clear;
close all
a = imread('cameraman.tif');
a = im2double(a);
% 1st level DWT Decomposition
[LL1, LH1, HL1, HH1] = dwt2(a,'db1');
imshow([LL1 LH1;HL1 HH1]);
title('1st level DWT with db4 wavelet');
% 2nd level DWT Decomposition
[LL2, LH2, HL2, HH2] = dwt2(LL1,'db1');
temp = [LL2 LH2;HL2 HH2];
figure;
imshow([temp LH1;HL1 HH1]);
title('2nd level DWT with db4 wavelet');
% reconstruction using inverse dwt
rec_1 = idwt2(LL2, LH2, HL2, HH2,'db1');
figure;imshow(rec_1);
title('reconstruction level 1');
% reconstruction using inverse dwt
rec_2 = idwt2(rec_1, LH1, HL1, HH1,'db1');

68
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

figure;imshow(rec_2);
title('reconstruction level 2');
psnr_rec = psnr(a,rec_2)
OUTPUT:

69
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB Dept. of ECE

psnr_rec = 309.9025

RESULT:

70
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY

You might also like