From: "willi" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Using correlation to search for subvector within a binary time series (bitstream)
Date: Tue, 9 Apr 2013 21:37:35 +0200
Organization: NNTP Server
Lines: 27
Message-ID: <kk1qm0$ffh$>
References: <kk1fn4$nrr$>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18463
X-Notice: Filtered by postfilter v. 0.8.2
X-Newsreader: Microsoft Windows Mail 6.0.6002.18197
X-Priority: 3
X-MSMail-Priority: Normal
Xref: comp.soft-sys.matlab:793100

"Matthew " <> wrote in message 
>I understand how the correlation between two time series is found.  I am 
>wondering if it is possible to use a correlation method in order to find a 
>particular sub-vector within a binary time series (e.g., a bitstream).
> For example, given a pseudo-random bitstream of length 1,500, say, can one 
> use a correlation technique to see if the vector v = [1 1 1 1 0 1] appears 
> somewhere in the bitstream?
> I am aware of Matlab's "find" function and its other built-in functions; I 
> am curious to see if this approach is valid as well.  Thanks!


v = [1 1 1 1 0 1];
vv = [round(rand(1,250))  v round(rand(1,250-numel(v)))];
xc = xcorr(2*vv-1,2*v-1); % make it a +1/-1-vector
xc = xc(500:end);
plot(xc/numel(v), '.-');grid

This algorithm will also find the inverse pattern.

Best rgds