matlab codec

6
>>[y1,fs1,nbits1]=wavread('admindavid1.wav'); >>[y2,fs2,nbits2]=wavread('admindipta1.wav'); >>plot(y1) >>plot(y2) >>helpxcorr XCORRCross-correlationfunctionestimates. C=XCORR(A,B),wh ereAandBarelengthM vectors(M>1),returns thelength2*M-1c ross-correlationsequenc eC.IfAandBareof differentlength, theshortestoneiszero-padded.Cwillbea rowvectorifAis arowvector,andacolumnvectorifAisa columnvector. XCORRproducesan estimateofthecorrelationbetweentworandom (jointlystationary)sequences: C(m)=E[A(n+m)*conj(B(n))]=E[A(n)*conj(B(n-m))] Itisalsothedet erministiccorrelationbetweentwodeterministic signals. XCORR(A),whenAi savector,istheauto- correlationsequence. XCORR(A),whenAi sanM-by-Nmatrix,isa largematrixwith 2*M-1rowswhoseN^2columnscontainthecross-correlation sequencesforallcombinationsofthecolumnsofA. Thezerothlagof theoutputcorrelationi sinthemiddleofthe sequence,atelementorrowM. XCORR(...,MAXLAG) computesthe(auto/cross)correlationoverthe rangeoflags:-MAXLAGtoMAXLAG,i.e.,2*MAXLAG+1lags. Ifmissing,defaultisMAXLAG=M-1. [C,LAGS]=XCORR(. ..)returnsavectorof lagindices(LAGS). XCORR(...,SCALEOPT ),normalizesthecorrelationaccordingtoSCALEOPT: 'biased'-scalestherawcross-correlationby1/M. 'unbiased'-sca lestherawcorrelation by1/(M-abs(lags)). 'coeff'-nor malizesthesequenceso thattheauto-correlations atzerolagareidentically1.0. 'none'-noscaling(thisisthedefault). Seealsoxcov,corrcoef,conv,cconv,covandxcorr2. ReferencepageinHelpbrowser docxcorr >>[c,lags]=xcorr(y1,y2); >>plot(lags,c) >>plot(y1) >>max(lags) ans= 1135679 >>helpfind FINDFindindicesofnonzeroelements. I=FIND(X)returnsthelinearindicescorrespondingto thenonzeroentrie softhearrayX.Xmay bealogicalexpression. UseIND2SUB(SIZE(X ),I)tocalculatemultiplesubscriptsfrom thelinearindicesI. I=FIND(X,K)retu rnsatmostthefirstK indicescorrespondingto

Upload: david-setiawan

Post on 06-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 1/6

>>[y1,fs1,nbits1]=wavread('admindavid1.wav');>>[y2,fs2,nbits2]=wavread('admindipta1.wav');>>plot(y1)>>plot(y2)>>helpxcorrXCORRCross-correlationfunctionestimates.C=XCORR(A,B),whereAandBarelengthMvectors(M>1),returnsthelength2*M-1cross-correlationsequenceC.IfAandBareofdifferentlength,theshortestoneiszero-padded.CwillbearowvectorifAisarowvector,andacolumnvectorifAisacolumnvector.XCORRproducesanestimateofthecorrelationbetweentworandom(jointlystationary)sequences:C(m)=E[A(n+m)*conj(B(n))]=E[A(n)*conj(B(n-m))]Itisalsothedeterministiccorrelationbetweentwodeterministicsignals.XCORR(A),whenAisavector,istheauto-correlationsequence.XCORR(A),whenAisanM-by-Nmatrix,isalargematrixwith2*M-1rowswhoseN^2columnscontainthecross-correlationsequencesforallcombinationsofthecolumnsofA.Thezerothlagoftheoutputcorrelationisinthemiddleofthesequence,atelementorrowM.

XCORR(...,MAXLAG)computesthe(auto/cross)correlationovertherangeoflags:-MAXLAGtoMAXLAG,i.e.,2*MAXLAG+1lags.Ifmissing,defaultisMAXLAG=M-1.[C,LAGS]=XCORR(...)returnsavectoroflagindices(LAGS).XCORR(...,SCALEOPT),normalizesthecorrelationaccordingtoSCALEOPT:'biased'-scalestherawcross-correlationby1/M.'unbiased'-scalestherawcorrelationby1/(M-abs(lags)).'coeff'-normalizesthesequencesothattheauto-correlationsatzerolagareidentically1.0.'none'-noscaling(thisisthedefault).

Seealsoxcov,corrcoef,conv,cconv,covandxcorr2.

ReferencepageinHelpbrowserdocxcorr

>>[c,lags]=xcorr(y1,y2);>>plot(lags,c)>>plot(y1)>>max(lags)

ans=

1135679

>>helpfindFINDFindindicesofnonzeroelements.I=FIND(X)returnsthelinearindicescorrespondingtothenonzeroentriesofthearrayX.Xmaybealogicalexpression.UseIND2SUB(SIZE(X),I)tocalculatemultiplesubscriptsfromthelinearindicesI.I=FIND(X,K)returnsatmostthefirstKindicescorrespondingto

Page 2: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 2/6

thenonzeroentriesofthearrayX.Kmustbeapositiveinteger,butcanbeofanynumerictype.I=FIND(X,K,'first')isthesameasI=FIND(X,K).I=FIND(X,K,'last')returnsatmostthelastKindicescorrespondingtothenonzeroentriesofthearrayX.[I,J]=FIND(X,...)returnstherowandcolumnindicesinsteadoflinearindicesintoX.Thissyntaxisespeciallyusefulwhenworkingwithsparsematrices.IfXisanN-dimensionalarraywhereN>2,thenJisalinearindexovertheN-1trailingdimensionsofX.[I,J,V]=FIND(X,...)alsoreturnsavectorVcontainingthevaluesthatcorrespondtotherowandcolumnindicesIandJ.Example:A=magic(3)find(A>5)findsthelinearindicesofthe4entriesofthematrixAthataregreaterthan5.[rows,cols,vals]=find(speye(5))

findstherowandcolumnindicesandnonzerovaluesofthe5-by-5sparseidentitymatrix.Seealsosparse,ind2sub,relop,nonzeros.

Overloadedmethods:codistributed/findcgprojconnections/findconinputfactor/findsweepsetfilter/findsweepset/findcgddnode/find

ReferencepageinHelpbrowserdocfind

>>n=find(lags==max(lags))

n=

2271359

>>[m,n,val]=find(lags==max(lags))

m=

1

n=

2271359

val=

Page 3: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 3/6

1

>>n=find(c==max(c))

n=

1247531

>>lags(n)

ans=

111851

>>y1c=y1(n:end);>>length(y2)

ans=

1021920

>>length(y1c)

ans=

0

>>plot(y1c???plot(y1c|Error:Expressionorstatementisincorrect--possiblyunbalanced(,{,or[.>>plot(y1c)>>plot(y1c)>>y1c

y1c=

Emptymatrix:0-by-1

>>plot(y1)>>y1c=y1(n:end);>>y1c

y1c=

Emptymatrix:0-by-1

>>y1(1)

ans=

0

>>y1(1000)

ans=

Page 4: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 4/6

-6.1035e-005

>>n

n=

1247531

>>y1(n)???Attemptedtoaccessy1(1.24753e+006);indexoutofboundsbecausenumel(y1)=1135680.>>y1c=y1(lags(n):end);>>plot(y1c)>>length(y1c)

ans=

1023830

>>length(y2)

ans=

1021920

>>y1c=y1c(1:length(y2));>>length(y2)==length(y1c)

ans=

1

>>error=y1c-y2;>>nilai_rmse=sqrt(sum(error.^2)/length(y1c))

nilai_rmse=

0.0983

>>length(y2)==length(y1)

ans=

0

>>length(1)

ans=

1

>>length(y1)

ans=

1135680

>>length(y2)

Page 5: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 5/6

ans=

1021920

>>y1a=y1(1:length(y2));>>error2=y1a-y2;>>nilai_rmse2=sqrt(sum(error2.^2)/length(y1a))

nilai_rmse2=

0.1744

>>plot(lags,c)>>plot(error)>>plot(error2)>>holdCurrentplotheld>>plot(error,r)???Undefinedfunctionorvariable'r'.>>plot(error,"r")???plot(error,"r")|Error:TheinputcharacterisnotvalidinMATLABstatementsor

expressions.>>plot(error,'r')>>plot(y1c,'g')>>plot(error,'r')>>holdoff>>plot(y1c,'g')>>plot(y2,'r')>>plot(y1,'b')>>plot(y1c,'g')>>holdCurrentplotheld>>plot(y2,'r')

>>plot(y2,'r')>>plot(y1,'b')>>holdoff>>plot(error)>>plot(lags)>>y2cut=y2(1:1000);>>[c2cut,lags2cut]=xcorr(y1,y2cut);???Errorusing==>fftfiltat78Filtersoflengthgreaterthan2^20arenotsupported.Usedfilt.fftfirinstead.

Errorin==>xcorr>vectorXcorrat126neg_c=conj(fftfilt(conj(x),flipud(y)));%negativelags

Errorin==>xcorrat54[c,M,N]=vectorXcorr(x,autoFlag,varargin{:});

>>[c2cut,lags2cut]=xcorr(y1,y2);>>y2cut=y2(1:10000);>>plot(y2cut)>>[c2cut,lags2cut]=xcorr(y1,y2cut);???Errorusing==>fftfiltat78Filtersoflengthgreaterthan2^20arenotsupported.Use

Page 6: Matlab Codec

8/2/2019 Matlab Codec

http://slidepdf.com/reader/full/matlab-codec 6/6

dfilt.fftfirinstead.

Errorin==>xcorr>vectorXcorrat126neg_c=conj(fftfilt(conj(x),flipud(y)));%negativelags

Errorin==>xcorrat54[c,M,N]=vectorXcorr(x,autoFlag,varargin{:});

>>y2cut=y2(1:100000);>>[c2cut,lags2cut]=xcorr(y1,y2cut);???Errorusing==>fftfiltat78Filtersoflengthgreaterthan2^20arenotsupported.Usedfilt.fftfirinstead.

Errorin==>xcorr>vectorXcorrat126neg_c=conj(fftfilt(conj(x),flipud(y)));%negativelags

Errorin==>xcorrat54[c,M,N]=vectorXcorr(x,autoFlag,varargin{:});

>>y2cut=y2(1:end);>>[c2cut,lags2cut]=xcorr(y1,y2cut);>>length(y2)

ans=

1021920

>>y2cut=y2(1:length(y2)/4);>>[c2cut,lags2cut]=xcorr(y1,y2cut);>>lags2cut(find(c2cut==max(c2cut)))

ans=

111851

>>lags(find(c==max(c)))

ans=

111851