# Building a Signal Model for Samples from a Sensor

I have a signal I'm getting from a sensor (shown below in the photo of an excel plot) and I need to process it to get it to look something like the red line I've overdrawn on it. Sort of a moving average type process that doesn't fall too quickly unless the overall signal is actually falling.

Anyone have any ideas as to what the best method(algo) would be to approach this problem?

Any suggestions on directions I could look towards would be helpful as well, it's been years since I took signal processing in school and I don't remember what methods are even out there that could be tried.

Thanks!

Jonathan

• The way you draw your red line is not consistent as far as I can tell (you use some of the blue peaks and ignore others). Please state your problem more precisely. What type of sensor? What does the output represent? – starblue Nov 30 '13 at 19:16
• Hi sorry for being vague; This is essentially an absolute'd audio signal [abs(signal)] output. Ignore the red line for now. Basically I'm trying to figure out how to do a sort of floating average that will track with the maximum points without falling into the dips, until the overall signal starts to track down then it will follow it. So I guess I would like to give the biggest peaks most of the weight of the averaging. Oh and the output is essentially a voltage vs. time (abs(V) vs. ms). – Killer Penguin Nov 30 '13 at 20:48
• it's not absV vs. ms, time units are 1/44100 s – Killer Penguin Nov 30 '13 at 20:54
• You should really say what you need the envelope for. The application has a lot of influence on the actual realization. Your description is too vague for at least me to provide a coherent answer – Jazzmaniac Dec 1 '13 at 8:55
• Are you trying to build a VU meter or a peak programme meter or something else? The "action" of the meter is different for each. – endolith Dec 2 '13 at 14:44

A simple exponential average has the following difference equation:

y(n) = (1-alpha) * x(n) + alpha * y(n-1)

To get a different rise and fall rate, you can dynamically choose alpha depending on whether x(n) is larger than y(n-1). For example, you could build have alpha = 0 when x(n) > y(n-1), and alpha = 0.99 otherwise. This could accomplish the "peak hold" goal, and the second value of alpha would let you control the decay after each peak.

Try raising the input to the Nth power, then 1st- order low pass filtering, followed by the Nth root. If N is 2 then this is equivalent to rms with exponential forgetting factor.

Bob

Are you trying to do half wave rectification? A resistance and a diode will work...

Looks like you're looking for the envelope of that signal. You can actually go back to your original audio signal, load it into Matlab, or something that has the necessary functions, and take the sum of the signal and [imaginary unit] times it's Hilbert transform to get a complex-valued "analytic signal". The magnitude of the analytic signal is the envelope, and should be pretty close to what you are drawing for a red line.

You can read up on it here: http://en.wikipedia.org/wiki/Analytic_signal

• Hilbert envelopes are only meaningful for so called single-component signals. For more general signals the components interfere and create unwanted oscillations. – Jazzmaniac Dec 1 '13 at 8:53
• The red line shown is not an envelope; the signal exceeds it regularly. – endolith Dec 2 '13 at 14:46
• Thank you for the help, I'm going to look into the exponential average first and then try the enveloping concepts and get back to you. – Killer Penguin Dec 9 '13 at 20:16