I am back with another question.

Context for the question: I am trying to smooth out the angular velocity data from an encoder. The encoder has 720 ppr and the rough angular speed of the wheel is around 327 rpm (5.45 Hz). Thus, the maximum update rate of the encoder is around 4000 Hz (encoder gives velocity update every pulse). My data acquisition setup samples at 16.67 kHz from the calculated speed. I have downsampled the signal to 4 kHz.

The recorded data is noisy mainly due to encoder eccentricity error (seen as low freq oscillations). But there is also a considerable amount of variation due to other encoder errors (cycle error, state width error, position error). By applying uncertainty propagation, I have found that to reduce the uncertainties to the desired value, I have to average over 20 points of data. i.e, I have to take one estimate every 20 samples by averaging all the 20 samples. I want the data to behave as if the encoder only gave a measurement every 20 pulses instead of one pulse. This will be the average angular speed over that much rotation.

Without knowing what a moving average filter was, I applied it and got a reasonable reduction in variations. However, then someone told me that moving average is not taking one sample for every 20 samples, and it doesn't reduce the no of samples. What I wanted to do (from my logic) was bin averaging. Here I divide the signal into several bins of 20 and take the mean, thereby reducing sampling freq to 200 Hz. I compared both the moving average and bin average methods in time and freq domain, shown below. Blue is signal at 4 kHz. Orange is moving average. Yellow is bin average.

Time domain pic Time domain

FFT of moving average and original signal FFT of moving average and original signal

FFT of bin average and original signal FFT of bin average and original signal

In the time domain, both look similar, although by zooming in, the variations in the bin average is lower, which I understand. The problem comes in freq domain. I compared fft of both filters to the fft of the downsampled signal. Here the moving average heavily attenuates frequencies above 200 Hz, which I understand. For the bin average, fft only goes till 100 Hz, BUT, there is a false peak introduced at 77 Hz which is not there in the original signal! WHERE IS THIS COMING FROM?

I want to use the bin average, because the logic behind it I understand. But if it modifies the frequency content, then I shouldn't use it probably. Would someone please explain why a random peak is generated in the bin averaging method? I tried on a different dataset (different repeat of the same experiment) still this remains. Please help!

  • $\begingroup$ Please tell us which color is what in each graphic. $\endgroup$ Mar 1, 2023 at 22:22
  • 1
    $\begingroup$ ah, ok. Yeah, you're aliasing. $\endgroup$ Mar 1, 2023 at 23:00
  • 1
    $\begingroup$ aliasing happens when you sample a signal at a rate lower than necessary to represent its full bandwidth. In your case, your "averaging" does not fullfill the need to reduce the bandwidth sufficiently prior to "condensing" many samples to one. So, yeah, not sure whether it really pays writing pages of explanation here: when dealing with digital signals, it would make more sense to read a good introductory book than to ask pages of questions that would, in the end, just tell you to read a good introductory book! $\endgroup$ Mar 1, 2023 at 23:09
  • 1
    $\begingroup$ Your averaging is a low-passing operation, it's just not sufficiently good at it. Again, a textbook would have explained that in the time you must have taken to write down your question! I'm not reproducing the first four chapters of Oppenheim/Schafer's Discrete-Time Signal Processing in the comments here – I couldn't do it as well as them, and it would be longer and harder to understand than that classic textbook. $\endgroup$ Mar 1, 2023 at 23:18
  • 1
    $\begingroup$ I know I sound kind of mean here, but really, this is basic stuff and it would be easier for you to understand it by going through a coherent text that introduces things consistently: You're making a lot of "I gather it's like this and that" assumptions, whilst the math behind aliasing is actually exact and not that hard :) $\endgroup$ Mar 1, 2023 at 23:22

1 Answer 1


@MarcusMuller already answered in his comment, but I'll elaborate a little.

  • In one approach, you're applying a moving average filter. That's perfectly fine.
  • In your other approach, your decimating your signal by factor 20.

Here's the catch: to properly decimate a signal, you need to first apply a low pass filter with cut-off equal to 1/2 of the target rate to avoid aliasing when throwing away samples. I won't get into why here, there's plenty of resources on this website and elsewhere on why that is. Bottom line, Low-pass filter + down-sampling = proper decimating.

By averaging every 20 samples, you're effectively decimating, but the filter used is a moving average low-pass filter, which is a poor choice of LPF for decimating purposes, due to the comb-like frequency response (see picture), which results in aliasing during the down-sampling operation (hence your "false peak" at $77 \texttt{Hz}$).

Here is what your decimating LPF looks like:

enter image description here

If you want to decimate your signal, apply an appropriate low-pass filter with cut-off at $100 \texttt{Hz}$, then throw away every 20 samples.

  • $\begingroup$ I tried it just now. It works. Thankyou! Its just I have trouble seeing both the operations as equal. My motivation behind all of this is to reduce the uncertainty in speed, by taking the average of multiple samples. Is this and lowpassing at the equivalent frequency the same thing ? $\endgroup$
    – S_holmes
    Mar 1, 2023 at 23:29
  • 1
    $\begingroup$ In both cases you're using the same low-pass filter (a moving average). But in the case where you throw away samples, you get aliasing because that low-pass filter is a poor choice for decimating purposes. It's a perfectly fine choice as a low-pass filter depending on your application, just not for decimation. Don't forget to accept the answer if you're satisfied. $\endgroup$
    – Jdip
    Mar 1, 2023 at 23:34
  • $\begingroup$ Now I am confused as to whether I should decimate. But I think the bin average might have been a bad idea. It just made intuitive sense. My aim is to still reduce the uncertainty. I guess lowpassing and then decimating will give me what I want. Thanks for being patient. $\endgroup$
    – S_holmes
    Mar 1, 2023 at 23:41
  • 1
    $\begingroup$ You don't need to down-sample unless you're worried about resources like time or memory. Just design a low-pass filter of your choosing (again, a moving average is perfectly fine, depending on which frequencies you're interested in keeping) and forget the down-sampling part. $\endgroup$
    – Jdip
    Mar 1, 2023 at 23:46
  • 1
    $\begingroup$ Glad I could hep :) As long as you're happy with what you see after filtering, you don't have to, no. But it's always good practice to look at both domains IMO. $\endgroup$
    – Jdip
    Mar 1, 2023 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.