Reply by sangthong February 12, 20082008-02-12
>I think you're at the stage where it would help to think of the
correlation
>process in a somewhat different framework. Correlation, particularly
when
>one of the sequences is short, is perhaps better viewed as a filtering >operation. When you have a short sequence, that's the same as a short >filter. A short filter generally has frequency response that's coarser
than
>a long filter. > >Take two cases (one of which is the one you stated): >Case 1: A long and relatively noisy sequence. Compute the
autocorrelation.
>Convolve it with itself. Think of this as a matched filter. When the >registration is exact you expect to get maximum output. > >Case 2: Same as above but take shorter and shorter sequences to be the >"filter" half of the convolution. As the filter gets shorter, the >correlation peak is reduced. As the filter gets shorter, it's possible
>that some parts of the longer sequence actually correlate *better* than
its
>exact matched sequence because: >- they are shaped similarly enough .. are "OK" >- the "OK" parts have higher amplitude than the exact match. >Note that the correlation peak will reduce more or less proportionately
to
>the length of the "filter" sequence. Is it obvious enough why? > >I have avoided getting into time reversal and the difference between >convolution and correlation. If the sequences are even, it doesn't
matter.
>If not, then you can figure it out. > >Fred > > >
Thanks again, I think I understand the problem now. I've found out that as I used x(t) as a random number (with the same location of y(t) copied from x(t)) and each time I randomed it, the correlation gave peaks at different locations, only some times that it gave peaks at the correct lcoation. So now I know that it's up to the amplitude of orginal data. But I still don't understand how to solve the problem. Does normalization do the job. I've tried but it didn't work out correctly.
Reply by Fred Marshall February 12, 20082008-02-12
"sangthong" <sangthong2548@yahoo.com> wrote in message 
news:vuadnXWJybqDdy3anZ2dnUVZ_judnZ2d@giganews.com...
> Thanks, Fred > > I think I can figure out the relationship of the scale now as I've tried > and compared the result with the correlation by FFT method, which I can > get the same result and I can shift the lag time backward and get the > correct location of the peak. > > However, I now have a problem that for some correlation, if the signal of > y(t) that I have copied from part of signal x(t) is very small, there will > be a problem that the peak occurs at the wrong location because at some > point, the amplitude of data is higher than the expected peak at > particualr location. I don't know how to fix this. I've thought of > normalized cross correlation because I've read that it will give the peak > at amplitude of 1, am I correct about this? > > and how can I do this in Matlab? I found only the function for 2D > normalized cross correlation not for 1D. Do you have any idea about the > code to do so? > > Thanks, > Sangthong
I think you're at the stage where it would help to think of the correlation process in a somewhat different framework. Correlation, particularly when one of the sequences is short, is perhaps better viewed as a filtering operation. When you have a short sequence, that's the same as a short filter. A short filter generally has frequency response that's coarser than a long filter. Take two cases (one of which is the one you stated): Case 1: A long and relatively noisy sequence. Compute the autocorrelation. Convolve it with itself. Think of this as a matched filter. When the registration is exact you expect to get maximum output. Case 2: Same as above but take shorter and shorter sequences to be the "filter" half of the convolution. As the filter gets shorter, the correlation peak is reduced. As the filter gets shorter, it's possible that some parts of the longer sequence actually correlate *better* than its exact matched sequence because: - they are shaped similarly enough .. are "OK" - the "OK" parts have higher amplitude than the exact match. Note that the correlation peak will reduce more or less proportionately to the length of the "filter" sequence. Is it obvious enough why? I have avoided getting into time reversal and the difference between convolution and correlation. If the sequences are even, it doesn't matter. If not, then you can figure it out. Fred
Reply by sangthong February 11, 20082008-02-11
Thanks, Fred

I think I can figure out the relationship of the scale now as I've tried
and compared the result with the correlation by FFT method, which I can
get the same result and I can shift the lag time backward and get the
correct location of the peak.

However, I now have a problem that for some correlation, if the signal of
y(t) that I have copied from part of signal x(t) is very small, there will
be a problem that the peak occurs at the wrong location because at some
point, the amplitude of data is higher than the expected peak at
particualr location. I don't know how to fix this. I've thought of
normalized cross correlation because I've read that it will give the peak
at amplitude of 1, am I correct about this?

and how can I do this in Matlab? I found only the function for 2D
normalized cross correlation not for 1D. Do you have any idea about the
code to do so?

Thanks,
Sangthong
Reply by Fred Marshall January 29, 20082008-01-29
"sangthong" <sangthong2548@yahoo.com> wrote in message 
news:o46dndLmdo-0oQDanZ2dnUVZ_uSgnZ2d@giganews.com...
> Hi, > > I forgot to detail that as I changed the series I copied from x(t) to > y(t), the overall signal has moved its location from left to right, but > the peak was at the same location (at 1024). I still don't get it, please > explain if you could. > > Thanks, > Sangthong
You need to manage the indices. That is, you need to keep track of where time=0 is. It would also be helpful to express your situation more clearly. I take it that you mean this: There is a sequence x(k) that represents a time sequence. There is another sequence y(k) that represents another time sequence. For some reason, it appears y(k) is shorter than x(k) because you said you zero-padded y(k). Is that right? Now, is y(k) shorter than x(k) because it has a different underlying sample rate? Or, is y(k) shorter than x(k) just because it covers a different/shorter time span? This is important!! You need to have sequences with the same underlying sample rate. Perhaps you're already there. Anyway, only then can you make them the same length by zero-padding the shorter one or plug them into xcorr. Then, it appears you're summing a segment of one into the other so that you can do some correlation computation experiments. Right? If you know where zero time is for each sequence then it should be easy to know the time at which the summed short sequence is placed. xcorr takes care of the zero padding. The description of xcorr isn't very easy to figure out how the indices work out but that's something you have to figure out. You could experiment with some very simple functions - that's what I do. I haven't thought about it much but the "time" scale for the correlated output is expressed in "delay" and not absolute time. Does that help at all? I think it means that you have to decide for yourself how the scales relate. It takes a bit of time and effort. Fred
Reply by sangthong January 27, 20082008-01-27
Hi,

I forgot to detail that as I changed the series I copied from x(t) to
y(t), the overall signal has moved its location from left to right, but
the peak was at the same location (at 1024). I still don't get it, please
explain if you could.

Thanks,
Sangthong
Reply by sangthong January 27, 20082008-01-27
Hi,

I quiet confuse with using 'xcorr' function. I understand that there is a
problem of wrap-around effect so it gives the result of N+M-1, but I don't
understand how to observe that the result of the correlation occurs at the
right place.

For example, if I have signal x(t) = 1024 numbers (length) and same for
y(t) but the later is padded to zero and I copy 501:532 of x(t) into y(t)
I should have the peak occur at 501.

However from the function xcorr(x(t),y(t)), which gave me the result of
length 2047 as expected and it gave me a peak at 1024 and when I change
the copy series from x(t) to 301:332, I still got the result with paek at
1024.

So could anyone explain to me what should it be or what function do I need
so as to do the cross correlation in matlab correctly?

Thanks,
Sangthong