This is a follow-on to the original post ...
I am trying to implement real-time correlation of two signals. I noticed the CIC Filter discussion here:
... however I need to use a normalized correlation for detection. What would the complete block diagram or equation be for a normalized CIC Filter?
Additional: I don't have to use the CIC - it just appeared to be computationally cheap and simple to implement. Would a moving window sum of the signal product, divided by the product of stdevs (to normalize) also work?
I.e., if I took the most recent N samples of each signal, and computed the normalized cross correlation, would that be the typical approach?
Follow-on: I have experimented with various ways of measuring signal similarity, and am getting some odd results. My scenario is two signals, X and Y, aligned in time. The X series counts from 0 to 20 over 21 samples (N). The Y series counts from 20 to 0.
I calculate the Pearson product-moment correlation coefficient over the entire series and get an R value of '-1', as expected. But since I'm interested in getting (near) real-time indication of similarity, I implemented the CIC filter approach, as discussed below, and normalized the value by dividing by the square root of the product of two other CIC filters (that each square the X and Y inputs, respectively).
So I am computing the normalized cross correlation of X and Y, using a 'window' of 3, by:
R(normal) = Rxy / (Rxx * Ryy)^0.5, using three CIC structures suggested by Boschen in:
Note I am not scaling this by N, as suggested by the answer below (I'm still not clear on this).
Now the problem ... the normalized value I get is '+1', not '-1'. Also, the result using the three CIC filter structures seems to be sensitive to when the data series is near, or crosses, zero. My guess is I'm still not implementing this correctly ... or is the CIC approach just sensitive this way?
As a further experiment, I implemented a 'windowed' Pearson correlation calculation, computing normalized value 'R' for the most recent 3 samples, and obtained correlation values near '-1', as expected, and it does this consistently regardless of whether the data series is near or crosses zero.
The CIC approach would seem to be preferred as a faster computation, but is giving inconsistent results.