Top Banner
EXPERIMENT NO. 01 AIM:- For the given sequence x(n)=1 for 0<n<3 and 0 elsewhere (a) Write a program to produce dtft of the signal and plot its magnitude and phase spectrum. PROGRAM :- clc; clear all; x= input('Enter input signal:') len=length(x) k=1 for w=0:0.1:2*pi X(k)=0 for n=0:len-1 X(k)=X(k)+x(n+1)*exp(-j*w*n) end k=k+1 end w=0:0.1:2*pi subplot(2,2,1) plot(w,abs(X)) xlabel('frequency---------->>>') ylabel('amplitude---------->>>') title('magnitude spectrum') subplot(2,1,2) plot(w,angle(X)) xlabel('frequency---------->>>') ylabel('angle---------->>>') title('phase spectrum')
19
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MATLAB LAB FILE

EXPERIMENT NO. 01

AIM:- For the given sequence x(n)=1 for 0<n<3 and

0 elsewhere(a) Write a program to produce dtft of the signal and plot its magnitude and

phase spectrum.

PROGRAM :-

clc;clear all;x= input('Enter input signal:')len=length(x)k=1for w=0:0.1:2*pi X(k)=0 for n=0:len-1 X(k)=X(k)+x(n+1)*exp(-j*w*n) end k=k+1endw=0:0.1:2*pisubplot(2,2,1)plot(w,abs(X))xlabel('frequency---------->>>')ylabel('amplitude---------->>>')title('magnitude spectrum')subplot(2,1,2)plot(w,angle(X))xlabel('frequency---------->>>')ylabel('angle---------->>>')title('phase spectrum')

Page 2: MATLAB LAB FILE

RESULT:-

Enter input signal : [ 1 1 1 1]

Page 3: MATLAB LAB FILE

(b) :- Write a program to produce dft of the signal and plot its magnitude and angle spectrum.

PROGRAM :-

clc;clear all;x= input('Enter input signal:')N=input('How many points dft you want:')len=length(x)for k=1:N X(k)=0 for n=0:len-1 X(k)=X(k)+x(n+1)*exp((-j*2*pi*k*n)/N) endendn=0:N-1subplot(2,1,1)stem(n,abs(X))xlabel('magnitude---------->>>')ylabel('frequency---------->>>')title('magnitude plot')subplot(2,1,2)stem(n,angle(X))xlabel('phase---------->>>')ylabel('frequency---------->>>')title('phase plot')

Page 4: MATLAB LAB FILE

RESULT:-

Enter input signal:[1 1 1 1]

x =

1 1 1 1

How many points dft you want:8

N =

8

len =

4

Page 5: MATLAB LAB FILE

EXPERIMENT NO. 02

AIM:- Wap to observe the effect of match band and simultaneous contrast.

PROGRAM:-

clear all;clc;% to observe the effect of matchband---->a1=zeros(1000,100);a7=ones(1000,100);a2=0.143*a7;a3=2*0.143*a7;a4=3*0.143*a7;a5=4*0.143*a7;a6=5*0.143*a7;a=[a1 a2 a3 a4 a5 a6 a7];

% to observe the efect of simultaneous contrast---->ob=0.1*ones(100,100);b1=zeros(100,300);b2=zeros(100,100);b=[b1;b2 ob b2;b1];subplot(1,3,1);imshow(b);g1=0.5*ones(100,300);g2=0.5*ones(100,100);g=[g1;g2 ob g2;g1];subplot(1,3,2);imshow(g);w1=ones(100,300);w2=ones(100,100);w=[w1;w2 ob w2;w1];subplot(1,3,3);imshow(w);figure,imshow(a);

Page 6: MATLAB LAB FILE

RESULT:-

Page 7: MATLAB LAB FILE
Page 8: MATLAB LAB FILE

EXPERIMENT NO. 03

AIM:- Wap to enhance the image from histogram equalization technique.

PROGRAM:-

close all;clear all;clc;a=imread('pout.tif');subplot(2,2,1)imshow(a);subplot(2,2,2)imhist(a);b=histeq(a);subplot(2,2,3)imshow(b);subplot(2,2,4)imhist(b);

Page 9: MATLAB LAB FILE

RESULT:-

Page 10: MATLAB LAB FILE

EXPERIMENT NO. 05

Aim: Observe the effect of shifting and rotation property of 2-D DFT.

Theory:

Discrete Fourier Transform

Working with the Fourier transform on a computer usually involves a form of the transform known as the discrete Fourier transform (DFT).There are two principal reasons for using this form: The input and output of the DFT are both discrete, which makes it convenient for computer manipulations. There is a fast algorithm for computing the DFT known as the fast Fourier transform (FFT).

The DFT is usually defined for a discrete function that is nonzero only over the finite region 0<=m<=M-1.The two dimensional M-by-N DFT and inverse M-by-N DFT relationships are given by

The matlab functions fft,fft2 and fftn implement the fast Fourier algorithm for computing 1-dimensional DFT, 2-dimensional DFT and n dimensional DFT respectively. The functions ifft, ifft2 and ifftn compute the inverse dft.

PROGRAM:-

clear allclca=imread('pout.tif');c=fft2(a);%2-D dft of the imagesubplot(2,3,1)d=imrotate(a,45);%rotated image by 45 degreesimshow(d);title('rotated image')subplot(2,3,2)imshow(c);e=fft2(d);%dft of the rotated imagetitle('dft of original image')

Page 11: MATLAB LAB FILE

subplot(2,3,3)imshow(e);f=fftshift(c);%origin being shifted to the centretitle('dft of the rotated image')subplot(2,3,4)imshow(f);g=fftshift(e);%shifted dft of the imagetitle('shifted dft')subplot(2,3,5)imshow(g);title('shifted dft of the rotated image')

Page 12: MATLAB LAB FILE

RESULT:-

Page 13: MATLAB LAB FILE

EXPERIMENT NO .6

AIM:-Program for image enhancement in spatial domain: smoothing.

THEORY:

Smoothing:

Smoothing is a spatial domain image enhancement method which is used to reduce blurring and noise.

Smoothing is accomplished by convoluting the given image to be processed with a filter mask. The output of a smoothing, linear spatial is the average of the pixels contained in the neighborhood of the filter mask.

In smoothing, the data points of a signal are modified so that individual points that are higher than the immediately adjacent points (presumably because of noise) are reduced, and points that are lower than adjacent points are increased. This naturally leads to a smoother signal. As long as the true underlying signal is actually smooth, then the true signal will not be much distorted by smoothing, but the noise will be reduced.

PROGRAM:-

clc;clear all;close all;a1=imread('pout.tif');subplot(2,1,1);imshow(a1);title('BEFORE SMOOTING');H = fspecial('average', [5 5]); c = imfilter(a1, H); subplot(2,1,2);imshow(c);title('AFTER SMOOTING');

Page 14: MATLAB LAB FILE

RESULT:-

Page 15: MATLAB LAB FILE

EXPERIMENT NO .7

AIM: Program for image enhancement in spatial domain: sharpening.

THEORY:

Sharpening:

The principle objective of sharpening is to highlight transitions in intensity. Image sharpening is used in various applications like military systems, medical imaging and electronic printing etc.

Image sharpening is accomplished by spatial differentiation. Image differentiation enhances edges and other discontinuities and deemphasizes areas with slowly varying intensities. Image sharpening can also be done by defining a discrete formulation of the second order derivatives and then constructing a filter mask based on it.

PROGRAM:

I = imread('moon.tif');h = fspecial('unsharp');I2 = imfilter(I,h);subplot(1,2,1);imshow(I), title('ORIGNAL IMAGE')subplot(1,2,2);imshow(I2), title('SHARPED IMAGE')

Page 16: MATLAB LAB FILE

RESULT:-