How is that after random numbers with their negatives alternating passing through 5, 4, 3 order moving average filter, become quasi sinusoidals?

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$$

• 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. – Marcus Müller Jan 20 '16 at 11:17
• 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 – Marcus Müller Jan 20 '16 at 11:56
• 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 – Laurent Duval Jan 20 '16 at 12:59
• Marcus Müller, yes I am sure did moving average. – George Theodosiou Jan 20 '16 at 13:52
• Marcus Müller and Laurent Duval, now that I have changed incorrect numbers in last sequence, do you agree with new numbers? – George Theodosiou Jan 21 '16 at 13:11

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.

• Mr Jason, many thanks for your answer and the link to wikipedia. But wiki's articles are too rigorous for me. Thanks. – George Theodosiou Jan 28 '16 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.

• 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. – George Theodosiou Jan 28 '16 at 12:38
• I just tried to explain why. Perhaps you should study Fourier analysis. Your background in music should make it easier. – Emre Jan 28 '16 at 19:42
• Mr Emre, many thanks for link to Coursera but it is in french and although I live in France my french are few tips. – George Theodosiou Jan 29 '16 at 12:14