Professional Documents
Culture Documents
EXPERIMENTS ON
1
2010
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
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
AIM:
To generate the standard waveforms
PROGRAMS:
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;
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;
3
2010
SINE WAVE
1
Amplitude (Volts)
-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
4
2010
Square Wave
4
Amplitude (Volts)
0
-1
-2
-3
-4
0 100 200 300 400 500 600 700 800 900 1000
Time (Microseconds)
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;
clc;
f=input('Enter the frequency (KHz) : ');
duty=input('Enter the duty cycle (in %) : ');
a=input('Enter the amplitude (V) : ');
t=0:1000;
5
2010
y=a*(square(2*pi*f*t/1000,duty));
plot(t,y);
xlabel('Time (Microseconds)');
ylabel('Amplitude (Volts)');
title('Square Wave');
grid;
RAMP SIGNAL
Ramp Sequence
6
4
Amplitude
0
0 1 2 3 4 5 6
Time index n
6
2010
EXPONENTIAL
Enter the value of a : 4
Enter the value of b : 3
11
x 10 Exponential signal
2.5
1.5
Amplitude
0.5
0
0 1 2 3 4 5 6 7
Time index x
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;
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);
7
2010
RESULT:
The standard waveforms of various signals are generated.
8
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
AIM:
To compute the DFT and IDFT of a given sequence using DFT and IDFT function and
using direct computation.
PROGRAMS:
9
2010
10
2010
Absolute magnitude
4
0
0 0.5 1 1.5 2 2.5 3
2
Phase angle
-2
-4
0 0.5 1 1.5 2 2.5 3
Time index n
11
2010
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');
xlabel('Time index n');
grid;
RESULT:
The DFT and IDFT of the two sequences are found using different methods and figures
are obtained.
12
2010
70
60
50
Amplitude
40
30
20
10
0
1 2 3 4 5 6 7
Time index n
AIM:
13
2010
PROGRAMS:
14
2010
70
60
50
Amplitude
40
30
20
10
0
1 2 3 4 5 6 7
Time index n
15
2010
RESULT:
The convolution of two sequences is obtained with and without using ‘conv’ function.
16
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
Phase in radiance
-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
17
2010
AIM:
To design Digital Butterworth Filters using IIR technique.
PROGRAM:
a) Butterworth Digital Low Pass Filter
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);
ylabel('Phase in radiance');
xlabel('Normalized frequency');
grid;
18
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
Phase in radiance
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency
19
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,'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);
ylabel('Phase in radiance');
xlabel('Normalized frequency');
grid;
RESULT:
The Digital Filters are designed using IIR technique and the frequency responses
obtained are shown in the figures.
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
4
Phase in radiance
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency
21
2010
[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;
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);
ylabel('Phase in radiance');
xlabel('Normalized frequency');
grid;
22
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
Phase in radiance
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency
23
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]=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);
ylabel('Phase in radiance');
xlabel('Normalized frequency');
grid;
RESULT:
The Digital Chebyshev Filters are designed using IIR technique and the frequency
responses obtained are shown in the figures.
24
2010
-20
-40
-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
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
Normalized Frequency ( rad/sample)
25
2010
AIM:
To design digital FIR filters using Hanning window.
PROGRAMS:
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.
26
2010
EXPERIMENTS ON
27
2010
Radon Transform
R0o(x )
60
50
40
30
20
10
0
-80 -60 -40 -20 0 20 40 60 80
Figure 1 Figure 2
R (X )
R45o(x )
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
28
2010
I. RADON TRANSFORM
clc;
clear all;
close all;
I=zeros(100,100);
I(25:75, 25:75)=1;
imshow(I);
[R,xp]=radon(I,[0,45]);
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;
[R,xp]=radon(I,theta);
figure,imagesc(theta,xp,R);
title('R_{\theta}(X\prime)');
xlabel('\theta(degrees)');
ylabel('X\prime');
set(gca,'XTick',0:20:80);
colormap(hot);
colorbar;
grid;
29
2010
Distance Transform
Figure 1
30
2010
clc;
clear all;
close all;
center1=-10;
center2=-center1;
dist=sqrt(2*(2*center2)^2);
radius=dist/2*1.4;
lims=[floor(center1-1.2*radius) ceil(center2+1.2*radius)];
[x,y]=meshgrid(lims(1):lims(2));
bw1=sqrt((x-center1).^2+(y-center1).^2)<=radius;
bw2=sqrt((x-center2).^2+(y-center2).^2)<=radius;
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')
31
2010
Figure 1
32
2010
The input image The image with ROI ,the face unsharpened
Figure 2
33
2010
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');
2D Spatial Transform
34
2010
Figure 1
35
2010
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');
36
2010
Figure 1
37
2010
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
B2=blkproc(B,[8,8],@(x)mask.*x); %imshow(B2)
%create the function handle for inverse DCT
invdct=@(x)T'*x*T;
%block processing using created function-invdct(reconstruction)
I2=blkproc (B2,[8,8],invdct);
subplot(1,2,1);
imshow(I);
title('Original image');
subplot(1,2,2);
imshow(I2);
title('Reconstructed image');
38