# Extract a signal that is known to repeat every 4 samples at a known phase i.e. exactly 500 Hz signal in 2000 Hz data

I have a situation that the measurement device is generating a known signal in the data at 1/4 of the rate. In this case that is a 500 Hz signal when sampling at 2000 Hz.

Now I can extract the 500 Hz signal using a Butterworth Band-Pass at 490–510 Hz which works, but it takes >1/8th of a second to extract the signal. In our setup we know the measurement and the signal are perfect in sync (same clock source etc) so a perfect 500 Hz filter would be ideal.

Is there a better extraction method? Ideally without the latency of the Butterworth or more computationally efficient or more accurate to extract the signal?

Here is an example of the 2 kHz data:

-34561, -32650, -3422, -5064, -33967, -32061, -2807, -4436, -33364, -31447, -2108, -3771, -32863, -31050, -1801, -3516, -32634, -30871, -1711, -3496, -32761, -31115, -2027, -3919, -33237, -31652, -2684, -4606, -33831, -32279, -3394, -5291, -34442, -32775, -3764, -5582, -34667, -32969, -3872, -5589, -34532, -32665, -3446, -5064, -34014, -32082, -2771, -4385, -33355, -31437, -2114, -3771, -32854, -31032, -1796, -3501, -32651, -30819, -1593, -3425, -32671, -31067, -1924, -3859, -33214, -31631, -2639, -4519, -33802, -32225, -3301, -5254, -34406, -32736, -3741, -5594, -34652, -32932, -3886, -5572, -34453, -32592, -3377, -5056, -33953, -32043 Edit: The aspect of interest is the amplitude of the 500hz signal, the amplitude can be converted to give a circuit impedance which we wish to efficiently measure. The butterworth takes a long time for a 1st order butterworth to converge to a steady amplitude measurement with fixed circuit impedance. A higher order could viable but this feels like overkill and as there is so many known about the signal so a more efficient approach would feel to be viable, just magnitude is the key. I tried some simple approached but these still had oscillation of amplitude at 50hz albeit the average was good, there may be formal methods I'd like to try.

Update: Here is a plot showing the butterworth vs the given solution shown in Green which does exactly what I had hoped with 4 samples latency! Previously I had looked at peak-signal but taking peak-average does look preferable anyway and what the solution is giving us. Thankyou for your help. • Welcome to SE.SP! What order Butterworth filter are you using? – Peter K. May 22 '20 at 15:36
• If you know that it is clock-sync-ed to the sampling clock, what aspect of the signal is it that you need? Its amplitude? Phase? – Knut Inge May 22 '20 at 15:36
• Unless you have literal billions of numbers, your 1/8 is a sign of incredibly inefficient filter implementation (and little else) – Marcus Müller May 22 '20 at 16:06
• I'd repeat very much what Knut asked: you don't need to actually get a signal out of this when you know exactly the frequency, then the only unknown is amplitude and phase, and you'd need very few samples to estimate these – and then you can recreate your signal simply using $A\cos(2\pi \cdot 500\,\text{Hz}\cdot t+\varphi)$. Maybe you could elaborate on your use case a bit! I bet you get a much more useful answer that way. – Marcus Müller May 22 '20 at 16:08
• also, as you can see from the plot, your signal's period is really not 4 samples, so it's really not at 500 Hz = 2000 Hz / 4 – Marcus Müller May 22 '20 at 16:12

To estimate the amplitude of the 500 Hz signal, a simple moving average filter will give you the best estimate in the presence of white Gaussian noise. This can be easily done by doing a moving average on the result of converting the 500 Hz signal to baseband as described below. This filter will have a Sinc response in frequency, so has high sidelobes which means it would be sensitive to the presence of other stronger signals if present. A very simple work-around is to just window the time domain signal first and then follow the same process (downcovert to baseband and sum the result over N samples where N is the length of the moving average). This is essentially a bandpass filter (using the windowing filter design approach) but in any filter used there will be a trade between frequency selectivity and time of convergence.

A convenience of having a "digital IF" that is exactly $$Fs/4$$ is you can down-convert to baseband (create the equivalent baseband analytic signal) by just multiplying by +/-1 as follows:

To get I you multiply by

I = 1 0 -1 0 1 0 -1 0

To get Q you multiply by

Q = 0 -1 0 1 0 -1 0 1

As these would be the values for the Local Oscillator $$e^{-j\omega t}$$ for $$\omega = \pi/2$$ which is the normalized radian frequency at an LO of $$f_s/4$$.

I detail this approach further at this post:

DAC and ADC architecture in SDRs

• Thanks for this response. I am a softy, sounds like this has some grounding I could use but will take a while for me to worm out the terms possibly. On Monday I will take a look into thi and report back. – Crog May 23 '20 at 19:31
• @Crog--- Simply "down-covert" your signal to baseband by multiplying it with $e^{-j \omega t}$ where $\omega$ is your normalized angular frequency-- Normalized just means divide the frequency by your sampling rate (at $f_s/4$, $\omega = 2\pi f/f_s = \pi/2$), you are multiplying by a digital signal that is at -500 Hz, which moves your signal to baseband. The average of this result will be proportional to the amplitude of your signal at 500 Hz. – Dan Boschen May 23 '20 at 19:34
• Using your linked reference and a very handy comment you added to that post it all seems pretty explanatory. A wonderful solution and exactly what I had hoped for. – Crog May 25 '20 at 8:42
• I don't have direct knowledge of the phase where I am using this, my naive assumption is that the correct phase is the one which gives the largest amplitude? I did a quick check offsetting the data and two gave negative amplitude and one was closer to zero and one is correct. Naively I would just take the biggest as being the phase of our signal or is there much preferred method? Thanks again for your help. – Crog May 25 '20 at 12:16
• &Crog since you down covert to I (Real) and Q (Imaginary) you will be able to measure the phase and magnitude—- I and Q is a phasor I + jQ – Dan Boschen May 25 '20 at 12:41