0
$\begingroup$

I have a signal (in blue) that I would like to smooth out (in red, moving average).

I would like to get red peaks to look more round than triangular and at the same time their width would become closer to the original ones.

enter image description here

Do you know / can you suggest a filter that would yield such result ?

Background:

The input is the zero-crossing rate from a song, for building a colored waveform as I've tried in this question : Coloring a waveform with spectral centroid or by other means

Here's the result of the new approach:

(unprocessed)

enter image description here

(ideal result, cheated somehow here using a post, expensive gaussian blur)

enter image description here

Update

Here's the result, using @Laurent Duval answer:

enter image description here

Also, I still need to try all of your suggestions again as my input/initial take was buggy, surprisingly now the ZCR yields better output than using FFTW out of the box (pics on the right):

enter image description here

Update 2

Simple moving average (green: 1-pass, gold: 2-passes)

enter image description here

$\endgroup$
  • $\begingroup$ can you share the excel file? $\endgroup$ – geometrikal Sep 16 '15 at 1:32
  • $\begingroup$ Here it is ! 1drv.ms/1KeVzIh $\endgroup$ – Aybe Sep 16 '15 at 3:20
2
$\begingroup$

I am not sure I understand "round" versus "triangular". Yet in chemistry, least-squares polynomial fitting filters are used to keep the smooth shape of spectra peaks. The most famous are the Savitzky–Golay filters. They have been revived in signal processing by a recent overview paper by R. W. Shafer: What Is a Savitzky-Golay Filter? (2011).

$\endgroup$
  • $\begingroup$ Well, I would like those red peaks to be wider than they are now, I guess they would look more round/sinusoid-like, if that makes sense ! Anyway, going to dig on your suggestion and come here for feedback, thank you ! $\endgroup$ – Aybe Sep 14 '15 at 21:18
  • $\begingroup$ Your solution looks promising, I haven't coded the filter by myself but I think I've found a pretty good implementation based on "Numerical recipes in C" (altaxo.sourceforge.net/AltaxoClassRef). Could you suggest some parameters regarding my update section in the question ? Basically, I would to keep each of the second bump to roughly the same level instead of being halved. Thank you ! $\endgroup$ – Aybe Sep 16 '15 at 3:43
  • $\begingroup$ Thank you for the update, excellent news. As for the parameters, I do not have access to your sampling and signal properties, thus not able to have a guess. The definition and explanation of SG filters in Numerical Recipes is pretty good to, and might help you to this respect $\endgroup$ – Laurent Duval Sep 17 '15 at 5:54
  • $\begingroup$ Thank you, it does really address the initial concern, I'll read the article in detail. $\endgroup$ – Aybe Sep 17 '15 at 7:30
3
$\begingroup$

Use two or three passes of moving average (can be pipelined).

$\endgroup$
  • $\begingroup$ This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. $\endgroup$ – jojek Sep 15 '15 at 11:48
  • 2
    $\begingroup$ @jojek: I don't agree. $\endgroup$ – Yves Daoust Sep 15 '15 at 11:53
  • $\begingroup$ Going to give it a try and come back here. $\endgroup$ – Aybe Sep 16 '15 at 3:44
  • $\begingroup$ See my update, basically it works but there's latency being introduced and original level is drastically reduced ... is there any way to overcome these two issues ? thank you. $\endgroup$ – Aybe Sep 16 '15 at 7:18
  • $\begingroup$ You don't seem to have the latency problem in @Laurent Duval's solution. How come ? $\endgroup$ – Yves Daoust Sep 16 '15 at 7:35
1
$\begingroup$

Try a small Gaussian filter.

An approximation to the Gaussian can be achieved by applying a moving average filter multiple times.

$\endgroup$
  • $\begingroup$ Ok, going to give it a try and come back. $\endgroup$ – Aybe Sep 16 '15 at 3:43
  • $\begingroup$ Thanks ! it works well too though the signal shape degrades quite quickly. $\endgroup$ – Aybe Sep 17 '15 at 22:18
0
$\begingroup$

In the question Aybe implied that the red curve is a moving average of the blue curve. That doesn't look correct to me. (It seems to me that a moving-averaged output would not have the sharp peaks seen in the red curve.) My first thought was to suggest, as Yves Daoust did, a moving average filter as a possible answer to the question. If Yves and I had access the the blue curve's sample values we could see if a true moving average filter will satisfy Aybe.

$\endgroup$
  • $\begingroup$ That's a moving average trendline I've added using the wizard in Excel. Here's the file : 1drv.ms/1KeVzIh $\endgroup$ – Aybe Sep 16 '15 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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