0
|
8636 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# ListCorrelate results in a time shifted vector

Posted 10 years ago
 Hi, I have two data sets that I want to cross-correlate, let's say a square pulse and a square pulse surrounded by zeros. I have tried to use ListCorrelate for this, but I keep getting a result that is centered either at the beginning of the pulse or at the end. If I do the calculation by hand then I get the a result that is centered in the middle of the square pulse (as expected). What is going on? ListCorrelate[ideal, test, 1]/Total[ListCorrelate[ideal, test, 1]] gives
8 Replies
Sort By:
Posted 10 years ago
 I think this sounds right, Cole. With the square pulse in the list being the same duration as the kernel, the max will occur when the correlation has lined up the kernel with the pulse in the list. Since we are indexing to the 1st position in the kernel, the index of the correlation is at the 1st position of the pulse when they are aligned, so the max occurs at the position of the leading edge of the pulse in the list. (With the 1st position index, there is no overhang of the kernel on the left of the list, so we would not need padding to preserve this -- the result is shortened from the right only.)With alignment to the middle position of the kernel, the max occurs when the index is at the center of the pulse in the list. but if we want positions in the result to correspond to the positions in the list we do need padding to lengthen the list on the left before correlation, so we don't shorten the result on the left.Best, David
Posted 10 years ago
 Update:I get the expected result if I align to the middle of the pulse. ListCorrelate[pulse, sample, Round[Length[pulse]/2], 0]; In general, if two square pulses are convolved, why wouldn't the resultant vector be max in the center?
Posted 10 years ago
 Thanks for the reply. You are correct that in this example it returns the expected result. I am at a loss for why it does not give the desire outcome with my larger data sets.I have uploaded the full length data sets if anyone is willing to run the data.As you can see from the uploaded image above the peak from the correlation is located at the beginning of the square pulse instead of the middle. I am confident it should be in the middle. In principle this larger data sets are a high res case of the previous example.Thanks Attachments:
Posted 10 years ago
 You can align the 1st element of the kernel with each element, and pad with 0s to get a list of the same length as the original: In[1]:= test = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}; In[2]:= ideal = {1, 1, 1}; In[3]:= wantedResult = {0, 0, 0, 0, 0, 0, 1, 2, 3, 2, 1, 0, 0, 0, 0, 0, 0}; In[4]:= result = ListCorrelate[ideal, test, 1, 0] Out[4]= {0, 0, 0, 0, 0, 0, 1, 2, 3, 2, 1, 0, 0, 0, 0, 0, 0} In[5]:= wantedResult === result Out[5]= True 
Posted 10 years ago
 I have tried: ListCorrelate[ideal, test] and ListCorrelate[ideal, test,-1] and ListCorrelate[ideal, test,{-1,1},0]. None have worked.
Posted 10 years ago
 Thanks for the replies.Lets say my data set is test = {0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0} and I want to correlate this with ideal = {1,1,1} - the pulse I want to find.If I correlate these two lists then I should get something like result = {0,0,0,0,0,0,1,2,3,2,1,0,0,0,0,0,0}. But when I use ListCorrelate as above I actually get actual = {0,0,0,0,1,2,3,2,1,0,0,0,0,0,0,0,0} Notice that the second data set is shifted in time.My question is why do I get the time shift from the expected result and how do I fix it?Thanks
Posted 10 years ago
 Cole,You are more likely to get a useful response if you post usable code. Please see: How to postKind regards, David
Posted 10 years ago
 It is very hard to respond without full code to replicate, along with some clear indication of what is the expected or desired result.