Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

>> [y1, fs1, nbits1] = wavread('admindavid1.wav'); >> [y2, fs2, nbits2] = wavread('admindipta1.

wav'); >> plot(y1) >> plot(y2) >> help xcorr XCORR Cross-correlation function estimates. C = XCORR(A,B), where A and B are length M vectors (M>1), returns the length 2*M-1 cross-correlation sequence C. If A and B are of different length, the shortest one is zero-padded. C will be a row vector if A is a row vector, and a column vector if A is a column vector. XCORR produces an estimate of the correlation between two random (jointly stationary) sequences: C(m) = E[A(n+m)*conj(B(n))] = E[A(n)*conj(B(n-m))] It is also the deterministic correlation between two deterministic signals. XCORR(A), when A is a vector, is the auto-correlation sequence. XCORR(A), when A is an M-by-N matrix, is a large matrix with 2*M-1 rows whose N^2 columns contain the cross-correlation sequences for all combinations of the columns of A. The zeroth lag of the output correlation is in the middle of the sequence, at element or row M. XCORR(...,MAXLAG) computes the (auto/cross) correlation over the range of lags: -MAXLAG to MAXLAG, i.e., 2*MAXLAG+1 lags. If missing, default is MAXLAG = M-1. [C,LAGS] = XCORR(...) returns a vector of lag indices (LAGS). XCORR(...,SCALEOPT), normalizes the correlation according to SCALEOPT: 'biased' - scales the raw cross-correlation by 1/M. 'unbiased' - scales the raw correlation by 1/(M-abs(lags)). 'coeff' - normalizes the sequence so that the auto-correlations at zero lag are identically 1.0. 'none' - no scaling (this is the default). See also xcov, corrcoef, conv, cconv, cov and xcorr2. Reference page in Help browser doc xcorr >> >> >> >> [c,lags] = xcorr(y1,y2); plot(lags,c) plot(y1) max(lags)

ans = 1135679 >> help FIND I = the Use the find Find indices of nonzero elements. FIND(X) returns the linear indices corresponding to nonzero entries of the array X. X may be a logical expression. IND2SUB(SIZE(X),I) to calculate multiple subscripts from linear indices I.

I = FIND(X,K) returns at most the first K indices corresponding to

the nonzero entries of the array X. K must be a positive integer, but can be of any numeric type. I = FIND(X,K,'first') is the same as I = FIND(X,K). I = FIND(X,K,'last') returns at most the last K indices corresponding to the nonzero entries of the array X. [I,J] = FIND(X,...) returns the row and column indices instead of linear indices into X. This syntax is especially useful when working with sparse matrices. If X is an N-dimensional array where N > 2, then J is a linear index over the N-1 trailing dimensions of X. [I,J,V] = FIND(X,...) also returns a vector V containing the values that correspond to the row and column indices I and J. Example: A = magic(3) find(A > 5) finds the linear indices of the 4 entries of the matrix A that are greater than 5. [rows,cols,vals] = find(speye(5)) finds the row and column indices and nonzero values of the 5-by-5 sparse identity matrix. See also sparse, ind2sub, relop, nonzeros. Overloaded methods: codistributed/find cgprojconnections/find coninputfactor/find sweepsetfilter/find sweepset/find cgddnode/find Reference page in Help browser doc find >> n = find(lags == max(lags)) n = 2271359 >> [m,n,val] = find(lags == max(lags)) m = 1 n = 2271359 val =

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: Expression or statement is incorrect--possibly unbalanced (, {, or [. >> plot(y1c) >> plot(y1c) >> y1c y1c = Empty matrix: 0-by-1 >> plot(y1) >> y1c = y1(n:end); >> y1c y1c = Empty matrix: 0-by-1 >> y1(1) ans = 0 >> y1(1000) ans =

-6.1035e-005 >> n n = 1247531 >> y1(n) ??? Attempted to access y1(1.24753e+006); index out of bounds because numel(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)

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) >> hold Current plot held >> plot(error,r) ??? Undefined function or variable 'r'. >> plot(error,"r") ??? plot(error,"r") | Error: The input character is not valid in MATLAB statements or expressions. >> plot(error,'r') >> plot(y1c,'g') >> plot(error,'r') >> hold off >> plot(y1c,'g') >> plot(y2,'r') >> plot(y1,'b') >> plot(y1c,'g') >> hold Current plot held >> plot(y2,'r') >> plot(y2,'r') >> plot(y1,'b') >> hold off >> plot(error) >> plot(lags) >> y2cut=y2(1:1000); >> [c2cut,lags2cut] = xcorr(y1,y2cut); ??? Error using ==> fftfilt at 78 Filters of length greater than 2^20 are not supported. Use dfilt.fftfir instead. Error in ==> xcorr>vectorXcorr at 126 neg_c = conj(fftfilt(conj(x),flipud(y))); % negative lags Error in ==> xcorr at 54 [c,M,N] = vectorXcorr(x,autoFlag,varargin{:}); >> [c2cut,lags2cut] = xcorr(y1,y2); >> y2cut=y2(1:10000); >> plot(y2cut) >> [c2cut,lags2cut] = xcorr(y1,y2cut); ??? Error using ==> fftfilt at 78 Filters of length greater than 2^20 are not supported. Use

dfilt.fftfir instead. Error in ==> xcorr>vectorXcorr at 126 neg_c = conj(fftfilt(conj(x),flipud(y))); % negative lags Error in ==> xcorr at 54 [c,M,N] = vectorXcorr(x,autoFlag,varargin{:}); >> y2cut=y2(1:100000); >> [c2cut,lags2cut] = xcorr(y1,y2cut); ??? Error using ==> fftfilt at 78 Filters of length greater than 2^20 are not supported. Use dfilt.fftfir instead. Error in ==> xcorr>vectorXcorr at 126 neg_c = conj(fftfilt(conj(x),flipud(y))); % negative lags Error in ==> xcorr at 54 [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

You might also like