Signal Processing Lab, Lab Reports of Engineering

Matlab code for: To generate a sine and cosine wave, verification of sampling theorem, verification of circular convolution, convolution of two input seque nces, transmitter and receiver for BPSK, design FIR digital High pass filter, To design FIR digital Low pass filter, To design IIR digital High pass filter, To design IIR digital low pass filter

Typology: Lab Reports

2012/2013

Uploaded on 01/29/2023

rakeshasery
rakeshasery 🇮🇳

55 documents

1 / 40

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
RAKESH ASERY (09EC73)
INTRODUCTION:-
MATLAB developed by The MathWorks Inc. stands for Matrix
Laboratory.It is a software package used to perform scientific
computations and visualization.Its compatibility for analysis of
various scientific problems ,flexibility and powerful graphics make it
a very useful software package.
(A)Commands for Managing a Session :-
1) Clc:- Clears Command window. It clears all input and output from the
Command Window display, giving you a "clean screen."
After using clc, you cannot use the scroll bar to see the history of functions,
but you still can use the up arrow to recall statements from the command
history. Syntax: clc
2) Clear:- Removes variables from memory. Clear name removes just the
code file or MEX-file function or variable name from your base workspace.
If called from a function, clear name removes name from both the function
workspace and in your base workspace.
Syntax: clear name or clear name1 name2 name3 ... or clear keyword
3) Exist:- Checks for existence of file or variable or function or class. As an
alternative to the exist function, use the Workspace Browser or the Current
Folder browser.
Syntax: exist name or exist name kind
4) global:- Declares variables to be global. Ordinarily, each MATLAB
function has its own local variables, which are separate from those of other
functions, and from those of the base workspace. global X Y Z defines X, Y,
and Z as global in scope.
Syntax: global X Y Z
5) Help:- Searches for a help topic. help function_name displays a brief
description and the syntax for function_name in the Command Window.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download Signal Processing Lab and more Lab Reports Engineering in PDF only on Docsity!

INTRODUCTION:-

MATLAB developed by The MathWorks Inc. stands for Matrix Laboratory.It is a software package used to perform scientific computations and visualization.Its compatibility for analysis of various scientific problems ,flexibility and powerful graphics make it a very useful software package.

(A)Commands for Managing a Session :-

1) Clc:- Clears Command window. It clears all input and output from the

Command Window display, giving you a "clean screen." After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow to recall statements from the command history. Syntax: clc

2) Clear:- Removes variables from memory. Clear name removes just the

code file or MEX-file function or variable name from your base workspace. If called from a function, clear name removes name from both the function workspace and in your base workspace. Syntax: clear name or clear name1 name2 name3 ... or clear keyword

3) Exist:- Checks for existence of file or variable or function or class. As an

alternative to the exist function, use the Workspace Browser or the Current Folder browser. Syntax: exist name or exist name kind

4) global:- Declares variables to be global. Ordinarily, each MATLAB

function has its own local variables, which are separate from those of other functions, and from those of the base workspace. global X Y Z defines X, Y, and Z as global in scope. Syntax: global X Y Z

5) Help:- Searches for a help topic. help function_name displays a brief

description and the syntax for function_name in the Command Window.

The information is known as the help comments because it comes from the comments at the top of the MATLAB function file. Syntax: help or help function_name or help modelname.mdl

6) lookfor:- Searches help entries for a keyword. lookfor topic searches

for the string topic in the first comment line (the H1 line) of the help text in all MATLAB program files found on the search path. lookfor topic -all searches the entire first comment block of a MATLAB program file looking for topic. Syntax: lookfor topic For example: lookfor inverse

7) quit:- Stops MATLAB. quit displays a confirmation dialog box if the

confirm upon quitting preference is selected, and if confirmed or if the confirmation preference is not selected, terminates MATLAB after running finish.m, if finish.m exists. The workspace is not automatically saved by quit. To save the workspace or perform other actions when quitting, create a finish.m file to perform those actions. Syntax: quit or quit cancel

8) who:- Lists current variables. log.who or who(log) lists the names of

the top-level signal logging objects contained by log, where log is the handle of a Simulink.ModelDataLogs object name. Syntax: log.who or log.who('all')

9) whos:- Lists current variables (long display). List names and types of

top-level data logging objects in Simulink data log. Syntax: log.whos

(B)System and File Commands :-

1) cd:- Changes current directory. oldFolder = cd (newFolder) returns the

existing current folder as a string to oldFolder, and then changes the

(C)Plotting Commands :-

1) axis:- Sets axis limits.

axis manipulates commonly used axes properties. axis([xmin xmax ymin ymax]) sets the limits for the x- and y-axis of the current axes. Syntax: axis([xmin xmax ymin ymax]) or axis auto or axis manual

2) fplot:- Intelligent plotting of functions. fplot plots a function between

specified limits. The function must be of the form y = f(x), where x is a vector whose range specifies the limits, and y is a vector the same size as x and contains the function's value at the points in x (see the first example). Syntax: fplot(fun,limits)

3) grid:- Displays gridlines.

The grid function turns the current axes' grid lines on and off. grid on adds major grid lines to the current axes. grid off removes major and minor grid lines from the current axes.

4) plot:- Generates xy plot. plot(Y) plots the columns of Y versus the index

of each value when Y is a real number. For complex Y, plot(Y) is equivalent to plot(real(Y),imag(Y)). plot(X1,Y1,...,Xn,Yn) plots each vector Yn versus vector Xn on the same axes. If one of Yn or Xn is a matrix and the other is a vector, plots the vector versus the matrix row or column with a matching dimension to the vector. If Xn is a scalar and Yn is a vector, plots discrete Yn points vertically at Xn.

5) print: Prints plot or saves plot to a file. print and printopt produce hard-

copy output. All arguments to the print command are optional. You can use them in any combination or order.

6) title:- Puts text at top of plot.This command is used to add a title to any

graph.

Syntax: title(‘name of title’)

7) xlabel:- Adds text label to x-axis.We can add label on x- axis using

syntax : xlabel(‘label name’)

8) ylabel:- Adds text label to y-axis. We can add label on x- axis using

syntax : ylabel(‘label name’)

9) axes:- Creates axes objects. axes creates an axes graphics object in the

current figure using default property values. axes is the low-level function for creating axes graphics objects. MATLAB automatically creates an axes, if one does not already exist, when you issue a command that creates a graph.

10) close:- Closes the current plot. close deletes the current figure or the

specified figure(s). It optionally returns the status of the close operation.

11) figure:- Opens a new figure window. figure creates figure graphics

objects. Figure objects are the individual windows on the screen in which the MATLAB software displays graphical output.

12) gtext:- Enables label placement by mouse. gtext displays a text string

in the current figure window after you select a location with the mouse.

13) hold:- Freezes current plot. The hold function determines whether

new graphics objects are added to the graph or replace objects in the graph. hold toggles the NextPlot property between the add and replace states.

14) legend:- Legend placement by mouse. legend places a legend on

various types of graphs (line plots, bar graphs, pie charts, etc.). For each line plotted, the legend shows a sample of the line type, marker symbol, and color beside the text label you specify. When plotting filled areas (patch or surface objects), the legend contains a sample of the face color next to the text label.

15) refresh:- Redraws current figure window.r efresh erases and redraws

the current figure.

16) subplot:- Creates plots in sub windows. subplot divides the current

figure into rectangular panes that are numbered rowwise. Each pane

Matlab Function:- abs(x)=computes the absolute value o the elements o x, when x is complex , abs(x) is the complex magnitude of the elements of x. angle(x)=computes the phase angle of each component of the vector x. rem(n,N)=determines the reminder after dividing n and N. log 10(x)=compute the logarithm to the base 10 of the elements of x. mod(n,N)=compute n mod N. conv(x,h)=compute convolution of two sequences x and h. filter(b,a,x)=solves the difference equation given the input sequence x and difference equation coefficients b=[b1,b2,b3,.......bM] a=[a1,a2,a3,........aN] H=freqz(b,a,x) returns the frequency response at frequencies designated in vector w, in radians. [H,w]=freqz(b,a,N) returns an N-point frequency response vector and N-point frequency vector w in radians, where N is an integer and b,a are numerator and denominator coefficient vector. [R,p,k]=residuez(b,a) compute the residues ,poles in direct froms of the partical-fraction expansion of B(z)/A(z). fft(x,N) compute DFT of the sequence x using radix-2,N point FFT algorithem. ifft(X,N) compute IDFT of the sequence X using radix-2,N point FFT algorithem. w=boxcar(N0 returns the N-point rectangular window in array w.

w=bartlett(N) return the N-point triangular window. w=hamming(N) ) return the N-point Hamming window. w=hanning(N) return the N-point Hanning window. w=blackman(N) return the N-point Blackman window. w=kaiser(N,beeta) return the N-point Kaiser window function for the beeta value. [b,a]=butter [N,un] designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors b and a. wn is units of ∏. If wn=[w1,w2], this function returns an order 2N bandpass filter with 3dB passband w1<w<w2 in unit of ∏. [b,a]=butter [N,wn,’hight’] designs a hightpass digital Butterworth filter of order N and 3dB cutoff frequency wn in unit of ∏. [b,a]=butter[N1,wn’stop’] designs a band/digital Butterworth filter of order 2N with 3dB stopband w1<w<w2 in unit of ∏. [b,a]=cheby 1(N,Rp,wn) designs an Nth order lowpass digital Chebyshev 1 filter with Rp decibles of ripple in the passband. Wn is in units of ∏. b and a are filter co-efficients in length N+1.If wn =[w1,w2], this function returns an order 2N bandpass w1<w<w2. [b,a]=cheby(N,Rp,wn,’high’) designs a highpass digital Butterwoth filter of order N and 3dB cuttoff frequency wn in unit of ∏. [b,a]=cheby 1(N,Rp,wn,’stop’) designs an order 2N digital bandstop filter wn=[w1,w2] with 3dB stopband w1<w<w2 in unit of ∏. [b,a]=cheby 2(N,Rs,wn) designs an Nth order lowpass digital chebyshev 2filter with stopband attenuation Rs decibles.It returns the filter coefficients in length N+1 vectors b and a.If wn=[w1,w2],this

response (or the filter coefficients) are returned in array h of length N.The weighting function used in each band is equal to unity. [h]=remez(N,f,m,weigths) is similar to above function except weights specifies weighting function in each band. [h]=remez(N,f,m,ftype) is similar to first case except f type is the string ‘differentiator’ or ‘Hilbert’. [h]=remez(N,f,m,weights,ftype) is similar to the above case except that the array weight specifies the weighting function in each band. FilterSyntax: y = filter(b,a,X) Description: y = filter(b,a,X) filters the data in vector X with the filter described bynumerator coefficient vector b and denominator coefficient vector a.If a(1) is not equal to1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error. ImpzSyntax: [h,t] = impz(b,a,n) Description: [h ,t ] = impz(b,a,n) computes the impulse response of the filter withn umerator coefficients b and denominator coefficients a and computes n samples of theimpulse response when n is an integer (t = [0:n-1]'). If n is a vector of integers,impzcomputes the impulse response at those integer locations , starting the responsecomputation from 0 (and t = n or t = [0 n]).If, instead of n, you include the empty vector [] for the second argument, the number of samples is computed automatically by default.

FliplrSyntax: B =fliplr(A) Description: B = fliplr(A) returns A with columns flipped in the left-right direction, thatis, about a vertical axis.If A is a row vector, then fliplr(A) returns a vector of the samelength with the order of its elements reversed. If A is a column vector, then fliplr(A)simply returns A.

Figure :-Response after adder block Figure:-Response after multiplier block

Figure:-Response after discrete system block(Discrete filter) At Display output was Amplitude of sine wave =0. Amplitude of constant signal = 1 Amplitude of step signal = Slope of ramp signal = 0.

Figure:-Response after subtractor block Figure :Response after multiplier block

Figure :-Response after continuous system block(Derivative) At Display output was Amplitude of sine wave =0. Amplitude of step signal = 1 Amplitude of pulse generator = Slope of ramp signal = 0.

Object:-WAP for verification of sampling theorem.

%VERIFICATION OF SAMPLING THEOREM %

T=0.04; %Time period of 50 Hz signal t=0:0.0005:0.02; f=1/T; xa_t=sin(2pi2t/T); subplot(2,2,1); plot(200t,xa_t); title ('continuous signal'); xlabel('t'); ylabel('x(t)'); ts1=0.002;%>niq rate ts2=0.01;%=niq rate ts3=0.1;%<niq rate n=0:20; x_ts1=sin(2pints1/T); subplot(2,2,2); stem(n,x_ts1); title('greater than Nq'); xlabel('n'); ylabel('x(n)'); n=0:4; x_ts2=sin(2pints2/T); subplot(2,2,3); stem(n,x_ts2); title('equal to Nq'); xlabel('n'); ylabel('x(n)'); n=0:4; x_ts3=sin(2pin*ts3/T); subplot(2,2,4); stem(n,x_ts3);

title('less than Nq'); xlabel('n'); ylabel('x(n)');