I have passed random numbers $${89, 58, 13, 70, 24}$$ with their negatives alternating, through 5 order moving average filter and output was positive and negative numbers alternating. After I have passed output through 4 order mov. average filter, output was positive and negative semi-periods! although no quasi-sinusoidal. But after passing this second output through 3 order moving average filter, output was quasi-sinusoidal! How then all that happened?

Following are input signal and outputs.

Random numbers alternate with their negatives:

$${89, -89, 58, -58, 13, -13, 70, -70, 24, -24, 89, -89, 58, -58, 13, -13, 70, -70, 24, -24, 89, -89, 58, -58}$$

After passing through 5 order moving average: $$2.6, -17.8, 14, -11.6, 4.8, -2.6, 17.8, -14, 11.6, -4.8, 2.6, -17.8, 14, -11.6, 4.8, -2.6, 17.8, -14, 11.6, -4.8$$

After passing through 4 order moving average: $$-3.2, -2.65, 1.15, 2.1, 1.5, 3.2, 2.65, -1.15, -2.1, -1.5, -3.2, -2.65, 1.15, 2.1, 1.5, 3.2, 2.65 $$

After passing through 3 order moving average:

$$-1.56667, 0.2, 1.58333, 2.26667, 2.45, 1.56667, -0.2, -1.58333, -2.26667, -2.45, -1.56667, 0.2, 1.58333, 2.26667, 2.45$$

  • 1
    $\begingroup$ Are you sure you're actually doing a moving average, and not just something that "feels" like a moving average, for example the "exponential weighted moving average" emulation in form of an IIR? For me, I get completely different values, and obviously, you expect different values, too, so writing down very precisely how you implemented the MA would probably make your question answerable. $\endgroup$ Jan 20, 2016 at 11:17
  • 1
    $\begingroup$ Also, I don't really think your original question is hard to answer: Any moving average is, purely by thinking what its job is, a low pass filter. Now, what does a low pass filter do to a signal that has sharp edges? Right. It makes it more sinusoidal $\endgroup$ Jan 20, 2016 at 11:56
  • $\begingroup$ If I multiply your first result by $5$, I get the vector $ [13,-89, 70,-58, 24,-13, 89,-70, 58,-24,13,-89, 70,-58, 24,-13, 89,-70, 58,-24]$. Which is weird. As @ Marcus Müller, I get different results $\endgroup$ Jan 20, 2016 at 12:59
  • $\begingroup$ Marcus Müller, yes I am sure did moving average. $\endgroup$ Jan 20, 2016 at 13:52
  • $\begingroup$ Marcus Müller and Laurent Duval, now that I have changed incorrect numbers in last sequence, do you agree with new numbers? $\endgroup$ Jan 21, 2016 at 13:11

2 Answers 2


There isn't a mystery here. Your input signal isn't random; you chose 5 numbers at random, perhaps, but then you repeated the sequence of 5 numbers several times. This is a periodic signal.

In continuous time, a periodic signal has a Fourier series representation; its spectrum contains discrete lines (i.e. sinusoidal tones).

In a finite-length discrete-time signal, such as the one you proposed, you see a similar phenomenon. The spectrum of a signal that is periodic within its duration will have a line structure to it.

Your moving averages are simple lowpass filters. As you apply more and more averages, you're filtering out the higher harmonics, leaving a combination of relatively fewer sinusoids. Thus, output of the cascade of moving average filters has a readily discernible structure as a sum of a relatively small number of sinusoids, as you described.

  • $\begingroup$ Mr Jason, many thanks for your answer and the link to wikipedia. But wiki's articles are too rigorous for me. Thanks. $\endgroup$ Jan 28, 2016 at 12:42

The spectrum of white noise is flat, constant. If you pass that through a low-pass filter, you'll get a rectangle, which translated back into the time domain becomes a sinc. Of course, you are not dealing with perfectly white noise, but it seems to be close enough for you to observe what you did.

  • $\begingroup$ My input signal is pretty good periodic of random numbers with zero sum of its period. I observe that final output is quasi sinusoidal (indeed first harmonic) burdened with upper harmonics attenuation as Mr Jason means. To me it remains mystery that by so simple process first harmonic is extracted from periodic signal of random numbers. $\endgroup$ Jan 28, 2016 at 12:38
  • $\begingroup$ I just tried to explain why. Perhaps you should study Fourier analysis. Your background in music should make it easier. $\endgroup$
    – Emre
    Jan 28, 2016 at 19:42
  • $\begingroup$ Mr Emre, many thanks for link to Coursera but it is in french and although I live in France my french are few tips. $\endgroup$ Jan 29, 2016 at 12:14

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.