You are on page 1of 47

# 2010

EXPERIMENTS ON

1
2010

## Unit Impulse Sequence

1

0.9

0.8

0.7

0.6
Amplitude

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Time index n

## Unit Step Sequence

1

0.9

0.8

0.7

0.6
Amplitude

0.5

0.4

0.3

0.2

0.1

0
-4 -3 -2 -1 0 1 2 3 4
Time index n

2
2010

## I. GENERATION OF STANDARD WAVEFORMS

AIM:
To generate the standard waveforms

PROGRAMS:

## a) Program to generate an impulse

clc;
n=input('Enter the value of n : ');
t=-n:1:n;
y=[zeros(1,n),ones(1,1),zeros(1,n)];
stem(t,y);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit Impulse Sequence');
grid;

## b) Program to generate a unit step

3
2010

clc;
n=input('Enter the value of n : ');
t=-n:1:n;
y=[zeros(1,n),ones(1,n+1)];
stem(t,y);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit Step Sequence');
grid;

SINE WAVE

## Enter the frequency (KHz) : 5

Enter the amplitude (Volts) 4

4
2010

Sine Wave
4

Amplitude (Volts)
0

-1

-2

-3

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (Milliseconds)

SQUARE WAVE
Enter the frequency (KHz) : 5
Enter the duty cycle (in %) : 75
Enter the amplitude (V) : 4
Square Wave
4

1
Amplitude (Volts)

-1

-2

-3

-4
0 100 200 300 400 500 600 700 800 900 1000
Time (Microseconds)

5
2010

## c) Program to generate a sine wave

clc;
f=input('Enter the frequency (KHz) : ');
a=input('Enter the amplitude (Volts) : ');
t=0:0.001:1;
x=a*(sin(2*pi*f*t));
plot(t,x);
title('Sine Wave');
xlabel('Time (Milliseconds)');
ylabel('Amplitude (Volts)');
grid;

## d) Program to generate a square wave

clc;
f=input('Enter the frequency (KHz) : ');
duty=input('Enter the duty cycle (in %) : ');
a=input('Enter the amplitude (V) : ');
t=0:1000;
y=a*(square(2*pi*f*t/1000,duty));
plot(t,y);
xlabel('Time (Microseconds)');

6
2010

ylabel('Amplitude (Volts)');
title('Square Wave');
grid;

RAMP SIGNAL

## Enter the value of n : 6

7
2010

Ramp Sequence
6

Amplitude
3

0
0 1 2 3 4 5 6
Time index n

EXPONENTIAL
Enter the value of a : 4
Enter the value of b : 3
11 Exponential signal
x 10
2.5

1.5
Amplitude

0.5

0
0 1 2 3 4 5 6 7
Time index x

8
2010

## a) Program to generate a ramp signal

clc;
n=input('Enter the value of n : ');
t=0:1:n;
stem(t,t);
xlabel('Time index n');
ylabel('Amplitude');
title('Ramp Sequence');
grid;

## b) Program to generate an exponential signal

clc;
a=input('Enter the value of a : ');
b=input('Enter the value of b : ');
x=linspace(0,2*pi,20);
y=b*exp(a*x);
stem(x,y);
xlabel('Time index x');
ylabel('Amplitude');
title('Exponential signal');
grid;

9
2010

RESULT:
The standard waveforms of various signals are generated.

## Enter the sequence : [4 3 2 1]

10
2010

Magnitude of fft
10

Absolute magnitude
5

0
1 1.5 2 2.5 3 3.5 4

Phase of fft
1

0.5
Phase angle

-0.5

-1
1 1.5 2 2.5 3 3.5 4
Time index n

## II. DFT AND IDFT OF A GIVEN SEQUENCE

AIM:
To compute the DFT and IDFT of a given sequence using DFT and IDFT function
and using direct computation.

11
2010

PROGRAMS:

## x=input('Enter the sequence : ');

f=fft(x);
len=length(f);
t=1:len;
subplot(2,1,1);
stem(t,abs(f));
title('Magnitude of fft');
ylabel('Absolute magnitude');
grid;
subplot(2,1,2);
stem(t,angle(f));
title('Phase of fft');
ylabel('Phase angle');
xlabel('Time index n');
grid;

12
2010

## Magnitude of Inverse fourier transform

6
Absolute magnitude

0
0 0.5 1 1.5 2 2.5 3

## Phase of Inverse fourier transform

4

2
Phase angle

-2

-4
0 0.5 1 1.5 2 2.5 3
Time index n

13
2010

## x=input('Enter the sequence : ');

f=ifft(x);
len=length(f);
t=0:1:len-1;
subplot(2,1,1);
stem(t,abs(f));
title('Magnitude of Inverse fourier transform');
ylabel('Absolute magnitude');
grid;
subplot(2,1,2);
stem(t,angle(f));
title('Phase of Inverse fourier transform');
ylabel('Phase angle');

14
2010

## xlabel('Time index n');

grid;

RESULT:
The DFT and IDFT of the two sequences are found using different methods and
figures are obtained.

15
2010

80

70

60

50
Amplitude

40

30

20

10

0
1 2 3 4 5 6 7
Time index n

AIM:

16
2010

PROGRAMS:

## x=input('Enter the first sequence : ');

y=input('Enter the second sequence : ');
z=conv(x,y);
len=length(z);
t=1:len;
stem(t,z);
title('Convolution of two sequences');
xlabel('Time index n');
ylabel('Amplitude');
grid;

17
2010

80

70

60

50
Amplitude

40

30

20

10

0
1 2 3 4 5 6 7
Time index n

18
2010

## x=input('Enter the first sequence : ');

y=input('Enter the second sequence : ');
m=length(x);
n=length(y);
len=m+n-1;
x1=[x,zeros(1,n-1)];
y1=[y,zeros(1,m-1)];
X=fft(x1);
Y=fft(y1);
c=X.*Y;
z=ifft(c);
t=1:len;
stem(t,z);
title('Convolution of two sequences');
xlabel('Time index n');
ylabel('Amplitude');
grid;

RESULT:
The convolution of two sequences is obtained with and without using ‘conv’
function.

19
2010

## Enter the sampling frequency in Hz : 2000

20
2010

-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

0

-1

-2

-3

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency

## IV. DIGITAL BUTTERWORTH FILTERS

[IIR TECHNIQUE]
AIM:
To design Digital Butterworth Filters using IIR technique.
PROGRAM:
a) Butterworth Digital Low Pass Filter

21
2010

clc;
clear all;
close all;
format long;
alphap=input('Enter the passband attenuation in dB : ');
alphas=input('Enter the stopband attenuation in dB : ');
fp=input('Enter the passband frequency in Hz : ');
fs=input('Enter the stopband frequency in Hz : ');
f=input('Enter the sampling frequency in Hz : ');
w1=2*fp/f;
w2=2*fs/f;
[n,wn]=buttord(w1,w2,alphap,alphas);
[b,a]=butter(n,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);
ylabel('Gain in dB');
subplot(2,1,2);
plot(om/pi,an);

22
2010

xlabel('Normalized frequency');
grid;

## Enter the sampling frequency in Hz : 3000

23
2010

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

4

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency

## b) Butterworth Digital Band Stop Filter

clc;
clear all;
close all;

24
2010

format long;
alphap=input('Enter the passband attenuation in dB : ');
alphas=input('Enter the stopband attenuation in dB : ');
fp=input('Enter the passband frequency in Hz : ');
fs=input('Enter the stopband frequency in Hz : ');
f=input('Enter the sampling frequency in Hz : ');
w1=2*fp/f;
w2=2*fs/f;
[n,wn]=buttord(w1,w2,alphap,alphas);
[b,a]=butter(n,wn,'stop');
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);
ylabel('Gain in dB');
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency');
grid;

25
2010

RESULT:
The Digital Filters are designed using IIR technique and the frequency responses
obtained are shown in the figures.

## Enter the sampling frequency in Hz : 2000

26
2010

-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

4

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency

## V. DIGITAL CHEBYSHEV FILTERS

[IIR TECHNIQUE]
AIM:
To design digital Chebyshev filters using IIR technique.
PROGRAM
a) Chebyshev Type-1 Digital High Pass Filter

clc;
clear all;
close all;
format long;

27
2010

## alphap=input('Enter the passband attenuation in dB : ');

alphas=input('Enter the stopband attenuation in dB : ');
fp=input('Enter the passband frequency in Hz : ');
fs=input('Enter the stopband frequency in Hz : ');
f=input('Enter the sampling frequency in Hz : ');
w1=2*fp/f;
w2=2*fs/f;
[n,wn]=cheb1ord(w1,w2,alphap,alphas);
[b,a]=cheby1(n,alphap,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);
ylabel('Gain in dB');
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency');
grid;

28
2010

## Enter the sampling frequency in Hz : 2500

29
2010

-100

Gain in dB
-200

-300

-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

4

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency

clc;
clear all;
close all;
format long;

30
2010

## alphap=input('Enter the passband attenuation in dB : ');

alphas=input('Enter the stopband attenuation in dB : ');
fp=input('Enter the passband frequency in Hz : ');
fs=input('Enter the stopband frequency in Hz : ');
f=input('Enter the sampling frequency in Hz : ');
w1=2*fp/f;
w2=2*fs/f;
[n,wn]=cheb2ord(w1,w2,alphap,alphas);
[b,a]=cheby2(n,alphas,wn,'bandpass');
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);
ylabel('Gain in dB');
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency');
grid;

RESULT:

31
2010

The Digital Chebyshev Filters are designed using IIR technique and the frequency
responses obtained are shown in the figures.

32
2010

## magnitude and phase response of FIR HPF

20

Magnitude (dB)
0

-20

-40

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

0
Phase (degrees)

-500

-1000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

## VI. DIGITAL FILTERS [FIR TECHNIQUE]

AIM:
To design digital FIR filters using Hanning window.
PROGRAMS:

33
2010

clc;
clear all;
close all;
format long;
alphap=input('Enter the passband attenuation in dB : ');
alphas=input('Enter the stopband attenuation in dB : ');
fp=input('Enter the passband frequency in Hz : ');
fs=input('Enter the stopband frequency in Hz : ');
f=input('Enter the sampling frequency in Hz : ');
w1=2*fp/f;
w2=2*fs/f;
wn=(w1+w2)/2;
num=-20*log10(sqrt(alphap*alphas))-13;
dem=14.6*(fs-fp)/f;
n=ceil(abs(num/dem));
m=n+1;
w=hann(m);
b=fir1(n,wn,’low’,w);
freqz(b,1,512,4000);
grid;

RESULT:
The Digital Filters are designed using FIR technique and the frequency responses
obtained are shown in the figures.

34
2010

EXPERIMENTS ON

## DIGITAL IMAGE PROCESSING

35
2010

R o(x ′ )
0
60

50

40

30

20

10

0
-80 -60 -40 -20 0 20 40 60 80

Figure 1 Figure 2

36
2010
R (X′)
R (x′ ) θ
45o
80 70
-60
70
60
-40
60
50
-20
50
40
40 0

X′
30
30 20

20
20
40

10 10
60

0 0
-80 -60 -40 -20 0 20 40 60 80 0 20 40 60 80
θ(degrees)

Figure 3 Figure 4

clc;
clear all;
close all;
I=zeros(100,100);
I(25:75, 25:75)=1;
imshow(I);
figure,plot(xp, R(:,1)),title('R_{0^o}(x\prime)')
figure,plot(xp, R(:,2)),title('R_{45^o}(x\prime)')
theta=0:180;
figure,imagesc(theta,xp,R);
title('R_{\theta}(X\prime)');
xlabel('\theta(degrees)');

37
2010

ylabel('X\prime');
set(gca,'XTick',0:20:80);
colormap(hot);
colorbar;
grid;

Distance Transform

38
2010

Figure 1

## II. DISTANCE TRANSFORM

clc;

39
2010

clear all;
close all;
center1=-10;
center2=-center1;
dist=sqrt(2*(2*center2)^2);
[x,y]=meshgrid(lims(1):lims(2));
bw=bw1|bw2;
subplot(1,2,1),imshow(bw),title('bw');
D=bwdist(~bw);
subplot(1,2,2),imshow(D,[]),title('distance transform of ~bw')

40
2010

## The mask at the position of face

Figure 1

The input image The image with ROI ,the face unsharpened

Figure 2

41
2010

## III. FILTERING A REGION IN AN IMAGE

clc;
close all;
clear all;
%Here the region of face of the boy is taken by
%specifying the values of the corresponding c and r
c=[70 156 152 75];
r=[25 23 128 123];
BW= roipoly(I,c,r);
%Step 3:Use fspecial to create the filter.
h=fspecial('unsharp');
%Step 4: call roifilt2,specifying the filter,
%the image to be filtered ,and the mask
I2=roifilt2(h,I,BW);
imshow(BW);
title(The mask at the position of face');
figure
subplot(1,2,1);
imshow(I);
title ('The input image');
subplot(1,2,2);
imshow(I2);
title ('The image with ROI ,the face unsharpened');

42
2010

2D Spatial Transform

Figure 1

43
2010

## IV. 2D SPACIAL TRANSFORM

clc;
close all;
clear all;
%Step 1:import the image to be transformed
cb=checkerboard;
subplot(1,2,1);
imshow(cb);
title('image to be transformed');
%Step2:define the Spacial transformation
xform = [1 0 0
010
40 40 1];
%Step 3:Create the TFORM structure
tform_translate =maketform('affine',xform);
%Step 4: Perform the Transformation
[cb_trans xdata ydata] = imtransform(cb,tform_translate)
%Step 5 : Show the transformed image
subplot(1 ,2 ,2);
imshow (cb_trans);
title('Transformed angle');

44
2010

45
2010

Figure 1

## V. DISCRETE COSINE TRANSFORM

clc;
close all;
clear all;
%convert the image array to double precision
I=im2double(I);
%form the dct transform matrix
T=dctmtx(8);
%create function handle for dct
dct=@(x) T*x*T';
%block processing using the created function handle-dct
B=blkproc(I,[8,8],dct);
mask=[1 1 1 1 0 0 0 0
11100000
11000000
10000000
00000000
00000000
00000000
0 0 0 0 0 0 0 0];
%block processing using the created mask

46
2010