View Full Version : Function to regularise a waveform
alexh110
14th March 2008, 16:55
Does anyone know of a C++ library function that can regularise an irregular waveform?
I need to equalise the width of each pulse, whilst preserving it's amplitude.
Ideally I'd like some source code that can apply this to an image file, and regularise the dominant waveform frequency in each row, such that the waveform maintains a constant frequency across the frame.
JohnnyMalaria
14th March 2008, 23:34
I doubt that there will be a C++ library function off-the-shelf that will do that. You'll have to write your own.
I would determine the zero-crossing points and calculate the average half-period across the whole line. I'd then stretch/compress each half-period to fit the average value. Since the average value is used for normalizing, the final line length should be very close to the original.
alexh110
15th March 2008, 19:32
Thanks for your reply.
As a beginner to C++, I'm not sure how to accomplish the stretching/compression. Is there a library function that would help me with this?
JohnnyMalaria
16th March 2008, 00:07
What you need is a resampling algorithm. Such algorithms are used widely for converting audio from one sampling rate to another - e.g., 48kHz to 44.1kHz. I suspect that any such libraries won't be versatile enough to support "unusual" values.
In your case, you'll need to be able to take, say, 123 points and resample them so they squeeze into 120 points.
You need to find a library that can fit a polynomial to the original data and then interpolate that polynomial at the points you need.
More crudely, you can linearly interpolate between the two data points either side of the new location.
There are lots of mathematics libraries for polynomial interpolation - you'll have to find the one that suits your specific needs. This Google search may help:
http://www.google.com/search?num=100&hl=en&lr=lang_en&newwindow=1&safe=off&as_qdr=all&q=%22polynomial+interpolation%22+c%2B%2B
alexh110
16th March 2008, 00:29
Thanks very much for your help: I'll give that a try.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.