Вы находитесь на странице: 1из 36

2010

Jerald cleetus

EXPERIMENTS ON

DIGITAL SIGNAL PROCESSING

2010

UNIT IMPULSE RESPONSE Enter the value of n : 5


1 0.9 0.8 0.7 Amplitude 0.6 0.5 0.4 0.3 0.2 0.1 0 -5 -4 -3 -2 -1 0 1 Time index n 2 3 4 5 Unit Impuls e Sequenc e

UNIT STEP SEQUENCE Enter the value of n : 4


1 0.9 0.8 0.7 Amplitude 0.6 0.5 0.4 0.3 0.2 0.1 0 -4 -3 -2 -1 0 Time index n 1 2 3 4 Unit Step Sequenc e

2010

I.
AIM:

GENERATION OF STANDARD WAVEFORMS

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

2010

SINE WAVE Enter the frequency (KHz) : 5 Enter the amplitude (Volts) 4
4 3 2 Amplitude (Volts ) 1 0 -1 -2 -3 -4 Sine W ave

0.1

0.2

0.3

0.4 0.5 0.6 Time (Millis ec onds )

0.7

0.8

0.9

SQUARE WAVE Enter the frequency (KHz) : 5 Enter the duty cycle (in %) : 75 Enter the amplitude (V) : 4
4 3 2 Amplitude (Volts ) 1 0 -1 -2 -3 -4 Square W ave

100

200

300

400 500 600 Time (Mic ros ec onds )

700

800

900

1000

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)'); ylabel('Amplitude (Volts)'); title('Square Wave'); grid;

2010

RAMP SIGNAL Enter the value of n : 6


6 Ramp Sequenc e

4 Amplitude

3 Time index n

Enter the value of a : 4 Enter the value of b : 3


2.5 x 10
11

EXPONENTIAL

Ex ponential s ignal

Amplitude

1.5

0.5

3 4 Time index x

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;

RESULT: The standard waveforms of various signals are generated.

2010

DFT-MAGNITUDE & PHASE PLOT

Enter the sequence : [4 3 2 1]

10 Abs olute magnitude

Magnitude of fft

1.5

2.5 Phas e of fft

3.5

1 Phas e angle 0.5 0 -0.5 -1 1 1.5 2

2.5 Time index n

3.5

2010

II.
AIM:

DFT AND IDFT OF A GIVEN SEQUENCE

To compute the DFT and IDFT of a given sequence using DFT and IDFT function and using direct computation. PROGRAMS: a) Program to find DFT of a sequence using FFT function. 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;

2010

IDFT-MAGNITUDE & PHASE PLOT

Enter the sequence : [4 5 6 7]

6 Abs olute magnitude 4 2 0

Magnitude of Invers e fourier trans form

0.5

1.5

2.5

4 Phas e angle 2 0 -2 -4 0 0.5

Phas e of Invers e fourier trans form

1.5 Time index n

2.5

10

2010

b) Program to find IDFT of a sequence using IFFT function 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'); xlabel('Time index n'); grid;

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

11

2010
CONVOLUTION OF TWO SEQUENCE(Using conv function) Enter the first sequence : [2 3 4 5] Enter the second sequence : [4 5 6 7]

80 70 60 50 Amplitude 40 30 20 10 0

Convolution of two s equenc es

4 Time index n

12

2010

III. CONVOLUTION OF TWO SEQUENCES


AIM: To compute the convolution of two sequences. PROGRAMS: a) Program to find convolution of two sequences using conv function 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;

13

2010

CONVOLUTION OF TWO SEQUENCE(Without Using conv function)

Enter the first sequence : [3 4 5 6] Enter the second sequence : [5 3 6 1]

80 70 60 50 Amplitude 40 30 20 10 0

Convolution of two s equenc es

4 Time index n

14

2010

b) Program to find convolution of two sequences without using conv function. 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.

15

2010
DIGITAL BUTTERWORTH FILTERS

Enter the passband attenuation in dB : 3 Enter the stopband attenuation in dB : 15 Enter the passband frequency in Hz : 400 Enter the stopband frequency in Hz : 800 Enter the sampling frequency in Hz : 2000

0 -50 -100 -150

Gain in dB

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

0 Phas e in radianc e -1 -2 -3 -4 0 0.1 0.2 0.3 0.4 0.5 0.6 Normaliz ed frequenc y 0.7 0.8 0.9 1

16

2010

IV.
AIM:

DIGITAL BUTTERWORTH FILTERS [IIR TECHNIQUE]

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;

17

2010

BUTTERWORTH DIGITAL BAND STOP FILTER

Enter the passband attenuation in dB : 3 Enter the stopband attenuation in dB : 20 Enter the passband frequency in Hz : [500 1000] Enter the stopband frequency in Hz : [600 900] Enter the sampling frequency in Hz : 3000

100 0 -100 -200 -300 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Gain in dB

4 Phas e in radianc e 2 0 -2 -4 0 0.1 0.2 0.3 0.4 0.5 0.6 Normaliz ed frequenc y 0.7 0.8 0.9 1

18

2010

b) Butterworth Digital Band Stop 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,'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.

19

2010

CHEBYSHEV TYPE-1 DIGITAL HIGH PASS FILTER

Enter the passband attenuation in dB : 3 Enter the stopband attenuation in dB : 18 Enter the passband frequency in Hz : 900 Enter the stopband frequency in Hz : 500 Enter the sampling frequency in Hz : 2000

0 -50 -100 -150

Gain in dB

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

4 Phas e in radianc e 3 2 1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 Normaliz ed frequenc y 0.7 0.8 0.9 1

20

2010

V.
AIM:

DIGITAL CHEBYSHEV FILTERS [IIR TECHNIQUE]

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;

21

2010
CHEBYSHEV TYPE-II DIGITAL BAND PASS FILTER

Enter the passband attenuation in dB : 3 Enter the stopband attenuation in dB : 16 Enter the passband frequency in Hz : [300 800] Enter the stopband frequency in Hz : [200 900] Enter the sampling frequency in Hz : 2500

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

Gain in dB

4 Phas e in radianc e 2 0 -2 -4 0 0.1 0.2 0.3 0.4 0.5 0.6 Normaliz ed frequenc y 0.7 0.8 0.9 1

22

2010

b) Chebyshev Type-II Digital Band 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]=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.

23

2010

DIGITAL FILTERS [FIR TECHNIQUE]

Enter the stopband attenuation in dB 15 Enter the passband frequency in Hz 400 Enter the stopband frequency in Hz 900 Enter the sampling frequency in Hz 2000

20 Magnitude (dB) 0 -20 -40 -60 0 0.1

magnitude and phas e res pons e of FIR HPF

0.2

0.3 0.4 0.5 0.6 0.7 0.8 Normaliz ed Frequenc y ( rad/s ample)

0.9

0 Phas e (degrees )

-500

-1000

0.1

0.2

0.3 0.4 0.5 0.6 0.7 0.8 Normaliz ed Frequenc y ( rad/s ample)

0.9

24

2010

VI.
AIM:

DIGITAL FILTERS [FIR TECHNIQUE]

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.

25

2010

EXPERIMENTS ON

DIGITAL IMAGE PROCESSING

26

2010

Radon Transform
R0o(x )

60

50

40

30

20

10

0 -80

-60

-40

-20

20

40

60

80

Figure 1

Figure 2

80 70 60 50 40 30 20 10 0 -80

R45o(x )

R (X ) -60 -40 -20 0 20 40 60 70 60 50 40 30 20 10 0

-60

-40

-20

20

40

60

80

20

40

60

80 (degrees )

Figure 3

Figure 4

27

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;

28

2010

Distance Transform

bw

dis tanc e trans form of ~ bw

Figure 1

29

2010

II.

DISTANCE TRANSFORM

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

30

2010

Filtering a region in an image


The mas k at the pos ition of fac e

Figure 1

The input image

The image with ROI ,the fac e uns harpened

Figure 2

31

2010

III.

FILTERING A REGION IN AN IMAGE

clc; close all; clear all; %Step 1:Read in the image I=imread('pout.tif'); I= imadjust(I); %Step 2:Create a binary mask. %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');

32

2010

2D Spatial Transform

image to be trans formed

Trans formed angle

Figure 1

33

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

34

2010

Discrete Cosine Transform

Original image

Rec ons truc ted image

Figure 1

35

2010

V.

DISCRETE COSINE TRANSFORM

clc; close all; clear all; I=imread ('cameraman.tif'); %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 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');

36

Вам также может понравиться