RAKSHK SPLAB

Preview:

DESCRIPTION

SPLAB

Citation preview

  • RAKESHASERY (09EC73)

    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)CommandsforManagingaSession :-

    1) Clc:- ClearsCommandwindow. ItclearsallinputandoutputfromtheCommandWindowdisplay,givingyoua"cleanscreen."

    Afterusingclc,youcannotusethescrollbartoseethehistoryoffunctions,butyoustillcanusetheuparrowtorecallstatementsfromthecommandhistory.Syntax:clc

    2) Clear:- Removesvariablesfrommemory.ClearnameremovesjustthecodefileorMEX-filefunctionorvariablenamefromyourbaseworkspace.Ifcalledfromafunction,clearnameremovesnamefromboththefunctionworkspaceandinyourbaseworkspace.

    Syntax:clearnameorclearname1name2name3...orclearkeyword

    3) Exist:- Checksforexistenceoffileorvariableorfunctionorclass. Asanalternativetotheexistfunction,usetheWorkspaceBrowserortheCurrentFolderbrowser.

    Syntax:existnameorexistnamekind

    4) global:- Declaresvariablestobeglobal. Ordinarily,eachMATLABfunctionhasitsownlocalvariables,whichareseparatefromthoseofotherfunctions,andfromthoseofthebaseworkspace. globalXYZdefinesX,Y,andZas globalinscope.

    Syntax:globalXYZ

    5) Help:- Searchesforahelptopic. helpfunction_namedisplaysabriefdescriptionandthesyntaxforfunction_nameintheCommandWindow.

  • RAKESHASERY (09EC73)

    TheinformationisknownasthehelpcommentsbecauseitcomesfromthecommentsatthetopoftheMATLABfunctionfile.

    Syntax:helporhelpfunction_nameorhelpmodelname.mdl

    6) lookfor:- Searcheshelpentriesforakeyword.lookfortopicsearchesforthestringtopicinthefirstcommentline(theH1line)ofthehelptext inallMATLABprogramfilesfoundonthesearchpath.lookfortopic-allsearchestheentirefirstcommentblockofaMATLABprogramfilelookingfortopic.

    Syntax:lookfortopic

    Forexample:lookforinverse

    7) quit:- StopsMATLAB.quitdisplaysaconfirmationdialogboxiftheconfirmuponquittingpreferenceisselected,andifconfirmedoriftheconfirmationpreferenceisnotselected,terminatesMATLABafterrunningfinish.m,iffinish.mexists.Theworkspaceisnotautomaticallysavedbyquit.Tosavetheworkspaceorperformotheractionswhenquitting,createafinish.mfiletoperformthoseactions.

    Syntax:quitorquitcancel

    8) who:- Listscurrentvariables. log.whoorwho(log)liststhenamesofthetop-levelsignalloggingobjectscontainedbylog,wherelogisthehandleofaSimulink.ModelDataLogsobjectname.

    Syntax:log.whoorlog.who('all')

    9) whos:- Listscurrentvariables(longdisplay). Listnamesandtypesoftop-leveldataloggingobjectsinSimulinkdatalog.

    Syntax:log.whos

    (B)System and File Commands :-

    1) cd:- Changescurrentdirectory. oldFolder=cd(newFolder)returnstheexistingcurrentfolderasastringtooldFolder,andthenchangesthe

  • RAKESHASERY (09EC73)

    currentfoldertonewFolder.

    cdnewFolderisthecommandsyntax.

    2) date:- Displayscurrentdate.Syntax:str=date

    3) delete:- Deletesafile.delete('fileName1','filename2',...)deletesthefilesfileName1,fileName2.

    Asdeletedoesnotaskforconfirmation,toavoidaccidentallylosingfilesorgraphicsobjects,makesuretospecifyaccuratelytheitemstodelete.

    4) diary:- Switcheson/offdiaryfilerecording. Thediaryfunctioncreatesalogofkeyboardinputandtheresultingtextoutput,withsomeexceptions(seeRemarksfordetails).TheoutputofdiaryisanASCIIfile,suitableforsearchingin,printing,inclusioninmostreportsandotherdocuments.

    Syntax:diaryordiary('filename')ordiaryoff

    5) dir:- Listsallfilesincurrentdirectory. dirliststhefilesandfoldersintheMATLABcurrentfolder.Resultsappearintheorderreturnedbytheoperatingsystem.

    6) load:- Loadsworkspacevariablesfromafile.

    S=load(filename)loadsthevariablesfromaMAT-fileintoastructurearray,ordatafromanASCIIfileintoadouble-precisionarray.

    S=load(filename,variables)loadsthespecifiedvariablesfromaMAT-file.

    7) path:- Displayssearchpath. pathdisplaystheMATLABsearchpath,whichisstoredinpathdef.m.

    8) pwd:- Displayscurrentdirectory.Syntax:currentFolder=pwd

    9) save:- Savesworkspacevariablesinafile.

    save(filename)storesallvariablesfromthecurrentworkspaceinaMATLABformattedbinaryfile(MAT-file)calledfilename.

    save(filename,variables)storesonlythespecifiedvariables.

  • RAKESHASERY (09EC73)

    (C)Plotting Commands :-

    1) axis:- Setsaxislimits.

    axismanipulatescommonlyusedaxesproperties.

    axis([xminxmaxyminymax])setsthelimitsforthex-andy-axisofthecurrentaxes.

    Syntax:axis([xminxmaxyminymax])oraxisautooraxismanual

    2) fplot:- Intelligentplottingoffunctions. fplotplotsafunctionbetweenspecifiedlimits.Thefunctionmustbeoftheformy=f(x),wherexisavectorwhoserangespecifiesthelimits,andyisavectorthesamesizeasxandcontainsthefunction'svalueatthepointsinx(seethefirstexample).

    Syntax:fplot(fun,limits)

    3) grid:- Displaysgridlines.

    Thegridfunctionturnsthecurrentaxes'gridlinesonandoff.

    gridonaddsmajorgridlinestothecurrentaxes.

    gridoffremovesmajorandminorgridlinesfromthecurrentaxes.

    4) plot:- Generatesxyplot.plot(Y)plotsthecolumnsofYversustheindexofeachvaluewhenYisarealnumber.ForcomplexY,plot(Y)isequivalenttoplot(real(Y),imag(Y)).

    plot(X1,Y1,...,Xn,Yn)plotseachvectorYnversusvectorXnonthesameaxes.IfoneofYnorXnisamatrixandtheotherisavector,plotsthevectorversusthematrixroworcolumnwithamatchingdimensiontothevector.IfXnisascalarandYnisavector,plotsdiscreteYnpointsverticallyatXn.

    5) print: Printsplotorsavesplot toafile. printandprintoptproducehard-copyoutput.Allargumentstotheprintcommandareoptional.Youcanusetheminanycombinationororder.

    6) title:- Putstextattopofplot.Thiscommandisusedtoaddatitletoanygraph.

  • RAKESHASERY (09EC73)

    Syntax:title(nameoftitle)

    7) xlabel:- Addstextlabeltox-axis.Wecanaddlabelonx-axisusingsyntax:xlabel(labelname)

    8) ylabel:- Addstextlabeltoy-axis.Wecanaddlabelonx-axisusingsyntax:ylabel(labelname)

    9) axes:-Createsaxesobjects. axescreatesanaxesgraphicsobjectinthecurrentfigureusingdefaultpropertyvalues.axesisthelow-levelfunctionforcreatingaxesgraphicsobjects.MATLABautomaticallycreatesanaxes,ifonedoesnotalreadyexist,whenyouissueacommandthatcreatesagraph.

    10) close:- Closesthecurrentplot.closedeletesthecurrentfigureorthespecifiedfigure(s).Itoptionallyreturnsthestatusofthecloseoperation.

    11) figure:- Opensanewfigurewindow.figurecreatesfiguregraphicsobjects.FigureobjectsaretheindividualwindowsonthescreeninwhichtheMATLABsoftwaredisplaysgraphicaloutput.

    12) gtext:- Enableslabelplacementbymouse.gtextdisplaysatextstringinthecurrentfigurewindowafteryouselectalocationwiththemouse.

    13) hold:- Freezescurrentplot. Theholdfunctiondetermineswhethernewgraphicsobjectsareaddedtothegraphorreplaceobjectsinthegraph.holdtogglestheNextPlotpropertybetweentheaddandreplacestates.

    14) legend:- Legendplacementbymouse. legendplacesalegendonvarioustypesofgraphs(lineplots,bargraphs,piecharts,etc.).Foreachlineplotted,thelegendshowsasampleofthelinetype,markersymbol,andcolorbesidethetextlabelyouspecify.Whenplottingfilledareas(patchorsurfaceobjects),thelegendcontainsasampleofthefacecolornexttothetextlabel.

    15) refresh:- Redrawscurrentfigurewindow.r efresherasesandredrawsthe current figure.

    16) subplot:-Createsplotsinsubwindows.subplotdividesthecurrentfigureintorectangularpanesthatarenumberedrowwise.Eachpane

  • RAKESHASERY (09EC73)

    containsanaxesobjectwhichyoucanmanipulateusingAxesProperties.Subsequentplotsareoutputtothecurrentpane.

    Syntax:subplot(m,n,P)

    17) text:- Places stringinfigure. textisthelow-levelfunctionforcreatingtextgraphicsobjects.Usetexttoplacecharacterstringsatspecifiedlocations.

    18) stem:- Createsstemplot. Atwo-dimensionalstemplotdisplaysdataaslinesextendingfromabaselinealongthex-axis.Acircle(thedefault)orothermarkerwhosey-positionrepresentsthedatavalueterminateseachstem.Itisbasicallyadiscreteversionofplot.Itrepresentsagraphindiscreteform.

    Syntax:stem(Y)orstem(X,Y)

  • RAKESHASERY (09EC73)

    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.

  • RAKESHASERY (09EC73)

    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 bandpass filter with 3dB passband w1

  • RAKESHASERY (09EC73)

    function returns an order 2N bandpass filter with passband w1

  • RAKESHASERY (09EC73)

    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 withnumerator 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.

  • RAKESHASERY (09EC73)

    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.

  • RAKESHASERY(09EC73)

    Object:-To realising a given block diagram having multiplier,adder/subtractor and system (Discrete) with given Impulseresponse.Calculatingoutputforgiveninput.

    Ans=>

    We can design it as given below :

    Response at various blocks is showen below:-

    Figure :- Response after subtractor block

  • RAKESHASERY(09EC73)

    Figure :-Response after adder block

    Figure:-Response after multiplier block

  • RAKESHASERY(09EC73)

    Figure:-Response after discrete system block(Discrete filter)

    At Display output was

    Amplitude of sine wave =0.5

    Amplitude of constant signal = 1

    Amplitude of step signal =1

    Slope of ramp signal = 0.2

  • RAKESHASERY (09EC73)

    Object:- To realising a given block diagram having multiplier, adder/subtractor and system (Continuous) with given Impulse response. Calculating output for given input.Ans = We can design it as given below

    Responseatvariousblocksisshown below-

    Figure :- Response after adder block

  • RAKESHASERY (09EC73)

    Figure:-Response after subtractor block

    Figure :Response after multiplier block

  • RAKESHASERY (09EC73)

    Figure :-Response after continuous system block(Derivative) AtDisplayoutputwas

    Amplitude of sine wave =0.5 Amplitude of step signal = 1 Amplitude of pulse generator =1 Slope of ramp signal = 0.2

  • RAKESHASERY (09EC73)

    Object:- WAP to generate a sine and cosine wave using subplot in discrete form. Answer:-

    %SINEWAVEANDCOSINEWAVEGENERATION%USINGSUBPLOTINDISCRETEFORM%PERFORMEDBYRAKESHASERYt=-pi:1:pi;y=sin(t);subplot(2,2,1);stem(t,y);xlabel('timeaxis');ylabel('amp.axis');title('sinewave');gridon;y=cos(t);subplot(2,2,2);stem(t,y);title('cosinewave');xlabel('timeaxis');ylabel('amp.axis');gridon;Figure:-

  • RAKESHASERY (09EC73)

    Object:-WAP for verification of sampling theorem.

    %VERIFICATION OF SAMPLING THEOREM %T=0.04; %Time period of 50 Hz signalt=0:0.0005:0.02; f=1/T;

    xa_t=sin(2*pi*2*t/T); subplot(2,2,1);plot(200*t,xa_t); title ('continuous signal');xlabel('t');ylabel('x(t)'); ts1=0.002;%>niq rate ts2=0.01;%=niq rate ts3=0.1;%

  • RAKESHASERY (09EC73)

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

  • RAKESHASERY (09EC73)

    Object: - Write a program to verification of circular convolution.

    x=input('Enterthesequenceofx[n]');h=input('Enterthesequenceofh[n]');p=input('Entervalueofp');subplot(3,1,1);stem(x);title('seuqencex[n]');xlabel('n');ylabel('x[n]');subplot(3,1,2);stem(h);title('seuqenceh[n]');xlabel('n');ylabel('h[n]');y=cconv(x,h,p);subplot(3,1,3);stem(y);title('CircularConvolution');xlabel('n');ylabel('y[n]');

  • RAKESHASERY(09EC73)

    Figure:-

    thesequenceofx[n][1602]thesequenceofh[n][083]Entervalueofp4Circularconvolutionofx[n]andh[n]=[16145118]

  • RAKESHASERY (09EC73)

    OBJECT:-Write a program to perform convolution of Two input sequences.%Program:x=input('Enter sequence x[n]');h=input('Enter sequence h[n]'); y=conv(x,h); subplot(3,1,1);stem(x); title('x[n]');subplot(3,1,2);stem(h); title('h[n]'); subplot(3,1,3);stem(y); title('y[n]=x[n]*h[n]'); Enter sequence x[n] [1 2 3 1]

    Enter sequence h[n] [0 1 2]

  • RAKESHASERY (09EC73)

    result: - Thus we have successfully performed the linear convolution.

    1 1.5 2 2.5 3 3.5 40

    2

    4x[n]

    1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 30

    1

    2h[n]

    1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 60

    5

    10y[n]=x[n]*h[n]

  • RAKESHASERY (09EC73)

    Object:-To verify Sampling Theorem. %VERIFICATION OF SAMPLING THEOREM %t=0:.0001:1; Generate 8 Hz sinusoidal signal. fm=8; x=sin(2*pi*fm*t); subplot(4,2,1) plot(t,x);title('Continuous Sine Wave'); xlabel('t-->'); ylabel('x(t)-->'); %Analog signal sampled at fs>2fm fs=80; n=0:1/fs:1;xn=sin(2*pi*fm*n);subplot(4,2,2);stem(n,xn); title('Sampling At fs>2fm'); xlabel('n-->'); ylabel('x(n)-->'); %Its Continuous Waveform:fs=60; n=0:1/fs:1;xn=sin(2*pi*fm*n);subplot(4,2,3);plot(n,xn);title('Continuous Waveform Of Sampled Signal At fs>2fm'); xlabel('n-->'); ylabel('x(n)-->');

  • RAKESHASERY (09EC73)

    %Analog signal sampled at fs

  • RAKESHASERY (09EC73)

    %Its Continuous Waveform:fs=16; n=0:1/fs:1;xn=sin(2*pi*fm*n);subplot(4,2,7);plot(n,xn);title('Continuous Waveform Of Sampled Signal At fs=2fm'); xlabel('n-->'); ylabel('x(n)-->');

  • RAKESHASERY (09EC73)

    RESULT:-Wesuccessfullyverify Sampling Theorem.

  • RAKESHASERY (09EC73)

    Object: - To simulate the transmitter and receiver for BPSK.% simulation of BPSK transmitter and receiverWe can design BPSK transmitter as given below

    Response at various blocks is shown below-

    Figure: Carrier signal

  • RAKESHASERY (09EC73)

    Figure: Input Binary data sequence

    Figure: Bipolar NRZ signal

  • RAKESHASERY (09EC73)

    Figure: BPSK signal

    We can design BPSK receiver as given below

  • RAKESHASERY (09EC73)

    Response at various blocks is shown below:-

    Figure: Incoming BPSK signal

    Figure: Demodulated waveAmplitude of sine wave =1.0Amplitude of constant signal = -0.5Amplitude of step signal =2Input binary sequence = [1 1 0 0 1 0 0 1 0 1]Result:- Thus we have successfully simulated BPSK transmitter and receiver

  • RAKESHASERY (09EC73)

    Object: - To design FIR digital High pass filter. % FIR digital HPWs = input('Enter the value of sampling frequency\n');%Nyquist frequency Nq= Ws/2 wp = input('Enter the value of passband corner frequency\n');ws = input('Enter the value of stopband corner frequency\n'); Nq= Ws/2;wpn = wp/Nq;wsn = ws/Nq;Rp = input('Enter the value of passband ripple in db\n');Rs = input('Enter the value of stopband attenuation in db\n');[n,Wn] = buttord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);b = fir1(n,Wn);g = firlp2hp(b); freqz(g); % Command window - Enter the value of sampling frequency8000Enter the value of passband corner frequency1500Enter the value of stopband corner frequency2000Enter the value of passband ripple in db1Enter the value of stopband attenuation in db5Order of filter =3

  • RAKESHASERY (09EC73)

    Figure: filter design magnitude & phase diagram of 3th order butterworth filter Result: - Thus we have successfully designed FIR digital High pass(Butterworth) filter.

  • RAKESHASERY (09EC73)

    Object: - To design FIR digital Low pass filter.% FIR digital LPWs = input('Enter the value of sampling frequency\n'); %Nyquist frequency Nq= Ws/2wp = input('Enter the value of passband corner frequency\n'); ws = input('Enter the value of stopband corner frequency\n'); Nq= Ws/2; wpn = wp/Nq; wsn = ws/Nq; Rp = input('Enter the value of passband ripple in db\n');Rs = input('Enter the value of stopband attenuation in db\n');[n,Wn] = buttord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);b = fir1(n,Wn); freqz(b); % Command window - Enter the value of sampling frequency 8000 Enter the value of passband corner frequency1500 Enter the value of stopband corner frequency 2000 Enter the value of passband ripple in db1Enter the value of stopband attenuation in db5Order of filter =3

  • RAKESHASERY (09EC73)

    Figure: filter design magnitude & phase diagram of 3th order butterworth filter Result: - Thus we have successfully designed FIR digital Low pass(Butterworth) filter.

  • RAKESHASERY (09EC73)

    Object: - To design IIR digital High pass filter.

    % IIR digital HP Ws = input('Enter the value of sampling frequency\n'); %Nyquist frequency Nq= Ws/2wp = input('Enter the value of passband corner frequency\n'); ws = input('Enter the value of stopband corner frequency\n'); Nq= Ws/2; wpn = wp/Nq; wsn = ws/Nq; Rp = input('Enter the value of passband ripple in db\n');Rs = input('Enter the value of stopband attenuation in db\n');[n,Wn] = buttord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);[b,a]= butter(n,Wn);[c,d]= iirlp2hp(b,a,wpn,wsn);freqz(c,d); % Command window - Enter the value of sampling frequency 8000 Enter the value of passband corner frequency1500 Enter the value of stopband corner frequency 2000 Enter the value of passband ripple in db1Enter the value of stopband attenuation in db10Order of filter =5

  • RAKESHASERY (09EC73)

    Figure: filter design magnitude & phase diagram of 5th order butterworth filter Result: - Thus we have successfully designed IIR digital High pass (Butterworth) filter.

  • RAKESHASERY (09EC73)

    Object: - To design IIR digital low pass filter. % IIR digital LPWs = input('Enter the value of sampling frequency\n'); %Nyquist frequency Nq= Ws/2wp = input('Enter the value of passband corner frequency\n'); ws = input('Enter the value of stopband corner frequency\n'); Nq= Ws/2; wpn = wp/Nq; wsn = ws/Nq; Rp = input('Enter the value of passband ripple in db\n');Rs = input('Enter the value of stopband attenuation in db\n');[n,Wn] = buttord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);[b,a] = butter(n,Wn);freqz(b,a); % Command window - Enter the value of sampling frequency 8000 Enter the value of passband corner frequency1500 Enter the value of stopband corner frequency 2000 Enter the value of passband ripple in db1Enter the value of stopband attenuation in db10Order of filter =5

  • RAKESHASERY (09EC73)

    Figure: - filter design magnitude & phase diagram of 5th order butterworth filter Result: - Thus we have successfully designed IIR digital Low pass(Butterworth) filter.

Recommended