7 ece Sp lab.docx

March 21, 2018 | Author: Rajesh Tyagi | Category: Data Compression, Matlab, Telecommunications Engineering, Applied Mathematics, Signal Processing


Comments



Description

EXPERIMENT LIST1. To simulate the transmitter and receiver for BPSK. 2. To design and simulate FIR digital filter (LP/HP). 3. To design and simulate IIR digital filter (LP/HP). 4. Reading and displaying Gray/ Colour images of different formats. 5. RGB/HSI conversions in an image, Image arithmetic operations. 6. Image Histogram and histogram equalization. 7. Image filtering in Spatial and frequency domain. 8. Morphological operations in analyzing image structures. 9. Thresholding-based image segmentation. 10. Study of image compression. Zero Lab AIM - To familiarize with MATLAB and its functions. THEORY- What Is MATLAB:MATLAB® is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include:       Math and computation. Algorithm development. Data acquisition. Modeling, simulation, and prototyping. Data analysis, exploration, and visualization. Scientific and engineering graphics. Application development, including graphical user interface building. The MATLAB System:The MATLAB system consists of five main parts:1 2 3 4 Desktop Tools and Development Environment:- This is the set of tools and facilities that help you use MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and Command Window, a command history, an editor and debugger, and browsers for viewing help, the workspace, files, and the search path. The MATLAB Mathematical Function Library:- This is a vast collection of computational algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigen values, Bessel functions, and fast Fourier transforms. The MATLAB Language:- This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create large and complex application programs. Graphics:- MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications. 5 The MATLAB External Interfaces/API:- This is a library that allows you to write C and Fortran programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files. MATLAB makes it possible to view the result of processing and gain understanding into complicated operations. The tool box support a wide range of signal processing from waveform generation to filter design and implementation, parametric modelling and spectral analysis. There are two categories of tools Signal processing functions Graphical interaction tools. The first category of tools is made of functions that we can call from the common line or from your own application. Many of the functions are MATLAB statements that implement specialized signal processing algorithm. RESULT – The familiarization of MATLAB was completed. Assignments1. 2. 3. 4. 5. 6. 7. What is MATLAB? What is the air mantic operation of matlab? What commercially available MATLAB-type environments are sold? What non-commercial MATLAB-type environments exist? Are there any standards for MATLAB-type tools? How can I join a MATLAB user group? Are there any software archives? EXPERIMENT 01 Aim- . To simulate the transmitter and receiver for BPSK . Software Required- Matlab 7.0.1 Theory- PN Sequence:1000011 Sine wave: Amplitude: Frequency: 1 10 Hz Cutoff frequency of low pass filter: 10Hz OUTPUT GRAPH:- Result- We have simulated the transmitter and receiver for BPSK. EXPERIMENT 02 Aim- To design and simulate FIR digital filter (LP/HP). Software Required- Matlab 7.0.1 version Theory- Finite impulse response A finite impulse response (FIR) filter is a filter structure that can be used to implement almost any sort of frequency response digitally. An FIR filter is usually implemented by using a series of delays, multipliers, and adders to create the filter's output. Figure shows the basic block diagram for an FIR filter of length N. The delays result in operating on prior input samples. The hk values are the coefficients used for multiplication, so that the output at time n is the summation of all the delayed samples multiplied by the appropriate coefficients. Figure: The logical structure of an FIR filter The process of selecting the filter's length and coefficients is called filter design. The goal is to set those parameters such that certain desired stopband and passband parameters will result from running the filter. Most engineers utilize a program such as MATLAB to do their filter design. But whatever tool is used, the results of the design effort should be the same:  A frequency response plot, like the one shown in Figure 1, which verifies that the filter meets the desired specifications, including ripple and transition bandwidth.  The filter's length and coefficients. The longer the filter (more taps), the more finely the response can be tuned. With the length, N, and coefficients, float h[N] = { ... }, decided upon, the implementation of the FIR filter is fairly straightforward. Listing 1 shows how it could be done in C. Running this code on a processor with a multiply-and-accumulate instruction (and a compiler that knows how to use it) is essential to achieving a large number of taps. Program- FIR low pass filter clc; clear all; close all; b=fir1(50,0.48,'low'); freqz(b,1,512); OUTPUT GRAPH:- FIR high pass filter clc; clear all; close all; b=fir1(50,0.48,'high'); freqz(b,1,512); OUTPUT GRAPH:- Result-We have designed FIR low pass and high pass filter AssignmentQ.1Explian FIR high pass filter.. Q.2.Explain digital filter. Q.3 Explain FIR low pass filter. Q.4 Write different types of window of matlab. Q.5 Explain figure window. Experiments-04 Aim- To design and simulate IIR digital filter (LP/HP) Software Required- Matlab 7.0.1version TheoryIIR filters, the transfer function is a ratio of polynomials: The numerator of the transfer function. When this expression falls to zero, the value of the transfer function is zero as well. Called a zero of the function. The denominator of the transfer function. When this expression goes to zero (division by zero), the value of the transfer function tends to infinity; called a pole of the function or filter. PROGRAM : % IIR filters LPF & HPF clc; clear all; close all; disp('enter the IIR filter design specifications'); rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); wp=input('enter the passband freq'); ws=input('enter the stopband freq'); fs=input('enter the sampling freq'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs,'s'); c=input('enter choice of filter 1. LPF 2. HPF \n '); if(c==1) disp('Frequency response of IIR LPF is:'); [b,a]=butter(n,wn,'low','s'); end if(c==2) disp('Frequency response of IIR HPF is:'); [b,a]=butter(n,wn,'high','s'); end w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); figure,subplot(2,1,1);plot(om/pi,m); title('magnitude response of IIR filter is:'); xlabel('(a) Normalized freq. -->'); ylabel('Gain in dB-->'); subplot(2,1,2);plot(om/pi,an); title('phase response of IIR filter is:'); xlabel('(b) Normalized freq. -->'); ylabel('Phase in radians-->'); OUTPUT GRAPH:- Result- We have designed IIR low pass and high pass filter . AssignmentQ.1 1Explian IIR high pass filter.. Q.2.Explain digital filter. Q.3 Explain IIR low pass filter. EXPERIMENT 04 OBJECTIVE: Reading and displaying Gray/ Colour images of different formats. MATLAB CODE Reading/writing of sample image. imdata = imread('ngc6543a.jpg'); imshow(imdata); close all; F = imread('tajm1.jpg'); S = imread('tajm2.jpg'); RGB to GRAY scale conversion F = im2double(rgb2gray(F)); S = im2double(rgb2gray(S)); EXPERIMENT 05 OBJECTIVE: RGB/HSV/HSI conversions in an image, Image arithmetic operations. SOFTWARE REQUIRED: MATLAB rgb2hsv Convert RGB colormap to HSV colormap Syntax cmap = rgb2hsv(M) hsv_image = rgb2hsv(rgb_image) 1. adding of two image I = imread(‘image1.tif’); J = imread(‘image2.tif’); K = imadd(I,J); Imshow(K) 2. subtraction of two image I = imread(‘image1.tif’); J = imread(‘image2.tif’); K = imsubtract(I,J); Imshow(K) 3. multiplication of two image I = imread(‘image1.tif’); J = imread(‘image2.tif’); K = immultiply(I,J); Imshow(K) 4. Divide of two image I = imread(‘image1.tif’); J = imread(‘image2.tif’); K = imdivide(I,J); Imshow(K) THEORY: Description cmap = rgb2hsv(M) converts an RGB colormap M to an HSV colormap cmap. Both colormaps are m-by-3 matrices. The elements of both colormaps are in the range 0 to 1. The columns of the input matrix M represent intensities of red, green, and blue, respectively. The columns of the output matrix cmap represent hue, saturation, and value, respectively. hsv_image = rgb2hsv(rgb_image) converts the RGB image to the equivalent HSV image. RGB is an m-by-n-by-3 image array whose three planes contain the red, green, and blue components for the image. HSV is returned as an m-by-n-by-3 image array whose three planes contain the hue, saturation, and value components for the image. EXPERIMENT 06 OBJECTIVE: Image Histogram and histogram equalization. SOFTWARE REQUIRED: MATLAB THEORY: The Histogram block computes the frequency distribution of the elements in the input. You must use the Find the histogram over parameter to specify whether the block computes the histogram for Each column of the input or of the Entire input. The Running histogram check box allows you to select between basic operation and running operation, as described below. The block distributes the elements of the input into the number of discrete bins specified by the Number of bins parameter, n. y = hist(u,n) % Equivalent MATLAB code The Histogram block sorts all complex input values into bins according to their magnitude. The histogram value for a given bin represents the frequency of occurrence of the input values bracketed by that bin. You specify the upper boundary of the highest-valued bin in the Upper limit of histogram parameter, BM, and the lower boundary of the lowest-valued bin in the Lower limit of histogram parameter, Bm. Input values that fall on the border between two bins are placed into the lower valued bin; that is, each bin includes its upper boundary. For example, a bin of width 4 centered on the value 5 contains the input value 7, but not the input value 3. Input values greater than the Upper limit of histogram parameter or less than Lower limit of histogram parameter are placed into the highest valued or lowest valued bin, respectively. The values you enter for the Upper limit of histogram and Lower limit of histogram parameters must be real-valued scalars. NaN and inf are not valid values for the Upper limit of histogram and Lower limit of histogram parameters. Program >> S = imread('tajm2.jpg'); >> F = im2double(rgb2gray(S)); >> imhist(F); >>G = histeq(F,256); >>Imshow(G); Test image Image histogram Equalized histogram EXPERIMENT 07 AIM: Image filtering in Spatial and frequency domain SOFTWARE REQUIRED: MATLAB THEORY: The following provide a side by side comparison of MATLAB code required to yield the images in the table. MATLAB code to create filtered image. Spatial Domain Filtering entry=imread('entry2.JPG'); hz=fspecial('sobel'); filter_hz=imfilter(double(entry),hz,'replicate', 'conv'); Frequency Domain Filtering entry=imread('entry2.JPG'); hz=fspecial('sobel'); PQ=paddedsize(size(entry)); HZ=fft2(double(hz), PQ(1), PQ(2)); F=fft2(double(entry),PQ(1),PQ(2)); FDF=HZ.*F; fdf=ifft2(FDF); fdf=fdf(1:size(entry,1),1:size(entry,2)); RESULT AND DISCUSSION: image can be analyze through above spatial and frequency domain analysis. EXPERIMENT 08 OBJECTIVE: Morphological operations in analyzing image structures. SOFTWARE REQUIRED: MATLAB MATLAB CODE demonstrate boundary extraction, interior filling % demonstrate morphological boundary extraction % clear all, close all A0=imread('myshap4.bmp'); imshow(A0); % a heart shape hand drawing title('original image'); pause % A0 contains mostly 1s and the drawing contains 0s, uint8 A1=1-double(A0); % invert black and white B=ones(3); A2=imopen(imclose(A1,B),B); % fill 1 pixel hole and remove sticks A3=imfill(A2,[100 100]); % fill the interior A=double(A2) + double(A3); imshow(A),title('after interior filling using imfill'); pause Ab=A-double(erode(A,B)); imshow(Ab), title('extracted boundary'); clear A1 A2 A3; Ac=Ab; vidx=[[1:20:280] 280]; Ac(vidx,:)=1; Ac(:,vidx)=1; imshow(Ac) EXPERIMENT 09 OBJECTIVE: Thresholding-based image segmentation. SOFTWARE REQUIRED: MATLAB MATLAB CODE demonstration of global and local thresholding for segmentation % threshdemo.m % Demonstration of global and local threshold operations of an image clear all [tmp,idx]=imread('lena.bmp'); a=ind2gray(tmp,idx); % gray scale image of lena, value between 0 and 1 clear tmp idx figure(1),clf,colormap('gray'),imshow(a),title('original Lena image') [m,n]=size(a); % size of image a b=reshape(a,m*n,1); % into a column vector figure(2),hist(b,50),title('histogram of image') % first do global thresholding mu=rand(2,1); % value betwen 0 and 1, two clusters only [W,iter,Sw,Sb,Cova]=kmeansf(b,mu);% W is the mean, % Cova is the covariance matrices % member: membership of each X: K by 1 vector of elements 1 to c [d,member]=kmeantest(b,sort(W)); c=reshape(member-1,m,n); clear d member b figure(3),clf,colormap('gray'),imshow(c) title('global threshold') % next do local threshold, partition the image into 64 x 64 blocks % and do threshold within each block c=zeros(512,512); trials=0; for i=1:8, for j=1:8, trials=trials+1; disp([int2str(trials) ' of 64 iterations ...']); tmp=a(64*(i1)+1:64*i,64*(j-1)+1:64*j); tmpi=reshape(tmp,64*64,1); mu=sort(rand(2,1)); % value betwen 0 and 1, two clusters only [W,iter,Sw,Sb,Cova]=kmeansf(tmpi,mu);% W is the mean, % Cova is the covariance matrices % member: membership of each X: K by 1 vector of elements 1 to c [d,member]=kmeantest(tmpi,sort(W)); c(64*(i-1)+1:64*i,64*(j1)+1:64*j)=reshape(member,64,64); end end figure(4),clf,colormap('gray'),imshow(c-1), title('local threshold, 64x64 block EXPERIMENT 10 AIM: Study of image compression. THEORY: IMAGE COMPRESSION Image compression addresses the problem of reducing the amount of data required to represent a digital image. It is a process intended to yield a compact representation of an image, thereby reducing the image storage/transmission requirements. Compression is achieved by the removal of one or more of the three basic data redundancies: 1. Coding Redundancy 2. Interpixel Redundancy 3. Psychovisual Redundancy Coding redundancy is present when less than optimal code words are used. Interpixel redundancy results from correlations between the pixels of an image. Psychovisual redundancy is due to data that is ignored by the human visual system (i.e. visually non essential information). Image compression techniques reduce the number of bits required to represent an image by taking advantage of these redundancies. An inverse process called decompression (decoding) is applied to the compressed data to get the reconstructed image. The objective of compression is to reduce the number of bits as much as possible, while keeping the resolution and the visual quality of the reconstructed image as close to the original image as possible. Image compression systems are composed of two distinct structural blocks : an encoder and a decoder. Image f(x,y) is fed into the encoder, which creates a set of symbols form the input data and uses them to represent the image. If we let n1 and n2 denote the number of information carrying units( usually bits ) in the original and encoded images respectively, the compression that is achieved can be quantified numerically via the compression ratio, CR = n1 /n2 As shown in the figure, the encoder is responsible for reducing the coding, interpixel and psychovisual redundancies of input image. In first stage, the mapper transforms the input image into a format designed to reduce interpixel redundancies. The second stage, qunatizer block reduces the accuracy of mapper’s output in accordance with a predefined criterion. In third and final stage, a symbol decoder creates a code for quantizer output and maps the output in accordance with the code. These blocks perform, in reverse order, the inverse operations of the encoder’s symbol coder and mapper block. As quantization is irreversible, an inverse quantization is not included. BENEFITS OF COMPRESSION o It provides a potential cost savings associated with sending less data over switched telephone network where cost of call is really usually based upon its duration. o It not only reduces storage requirements but also overall execution time. o It also reduces the probability of transmission errors since fewer bits are transferred. o It also provides a level of security against illicit monitoring. IMAGE COMPRESSION TECHNIQUES The image compression techniques are broadly classified into two categories depending whether or not an exact replica of the original image could be reconstructed using the compressed image . These are: 1. Lossless technique 2. Lossy techniqhe Lossless compression technique In lossless compression techniques, the original image can be perfectly recovered form the compressed (encoded) image. These are also called noiseless since they do not add noise to the signal (image).It is also known as entropy coding since it use statistics/decomposition techniques to eliminate/minimize redundancy. Lossless compression is used only for a few applications with stringent requirements such as medical imaging. Following techniques are included in lossless compression:     Run length encoding Huffman encoding LZW coding Area coding Lossy compression technique Lossy schemes provide much higher compression ratios than lossless schemes. Lossy schemes are widely used since the quality of the reconstructed images is adequate for most applications .By this scheme, the decompressed image is not identical to the original image, but reasonably close to it. Prediction / Origina Transformation / l Data Decomposition Quantization Entropy (Lossless ) Coding Compressed data Figure: Outline of lossy image compression As shown above the outline of lossy compression techniques .In this prediction – transformation – decomposition process is completely reversible .The quantization process results in loss of information. The entropy coding after the quantization step, however, is lossless. The decoding is a reverse process. Firstly, entropy decoding is applied to compressed data to get the quantized data. Secondly, dequantization is applied to it & finally the inverse transformation to get the reconstructed image. Major performance considerations of a lossy compression scheme include: 1. Compression ratio 2. Signal - to – noise ratio 3. Speed of encoding & decoding. Lossy compression techniques includes following schemes:  Transformation coding  Vector quantization  Fractal coding  Block Truncation Coding  Subband coding MATLAB CODE load /home/nirav/elec301/lena256.mat; imagesc(lena256); colormap(gray(256)); [qmf, dqmf] = MakeBSFilter('Deslauriers', 3); % The MakeBSFilter function creates biorthonormal filter pairs. The filter % pairs that we're making is an Interpolating (Deslauriers-Dubuc) filter % of polynomial degree 3 wc = FWT2_PB(lena256, 1, qmf, dqmf); % % % % wc correspond to the wavelet coefficients of the sample image FWT2_PB is a function that takes a 2 dimensional wavelet transform We specify the image matrix, the level of coarseness (1), the quadrature mirror filter (qmf), and the dual quadrature mirror filter (dqmf) % we take a tolerance which is some fraction % of the norm of the sample image nl = norm(lena256) / (4 * norm(size(lena256))); % if the value of the wavelet coefficient matrix at a particular % row and column is less than the tolerance, we 'throw' it out % and increment the zero count. zerocount = 0; for i = 1:256 for j = 1:256 if ( abs(wc(i,j)) < nl) wc(i,j) = 0; zerocount = zerocount + 1; end end end x = IWT2_PB(wc, 1, qmf, dqmf); imagesc(x); % here is some sample code to view how these deslauriers wavelets look [qmf, dqmf] = MakeBSFilter('Deslauriers', 3); for i = 1:256 for j = 1:256 wc(i,j) = 0; end end % this is the Deslauriers(4,2) matrix wc(4, 2) = 1000; x = IWT2_PB(wc, 1, qmf, dqmf); imagesc(x);
Copyright © 2024 DOKUMEN.SITE Inc.