Convert stepped signal to a continuous signal
5 views (last 30 days)
Show older comments
Hi, I'm recording a voltage output at a sampling frequency of 1000Hz from a device that measures liquid flow. The refresh rate of the output is 125Hz. The result is a stepped curve as shown below.

In the end, I'm interested in the steepest slope of the curve. What should I do to construct the original curve from the recorded data? I've had a look at decimate(data, 8), and y=movmean(data, 8) followed by downsample(y, 8). Both ways result in better looking graphs, but which one would be the most accurate? I'm new to the field, so maybe there's a better way of doing things.
0 Comments
Accepted Answer
Star Strider
on 26 Dec 2016
There are two ways I would consider.
The easiest is to use the Signal Processing Toolbox Savitzky-Golay filter function sgolayfilt. It creates what is essentially a low-pass filter from your data.
A somewhat more involved but more general approach is to take the Fourier transform of your signal (with the fft (link) function), visually determine signal frequency and the noise frequencies, and create a lowpass filter (or bandpass filter if you also want to remove baseline offset and low-frequency baseline variations). It is easiest to use the Signal Processing Toolbox designfilt function for this. Then filter your signal using the filtfilt function.
10 Comments
Star Strider
on 15 Jan 2017
Edited: Star Strider
on 16 Jan 2017
I’m not certain what the problem could be with the derivative itself. I doubt the filter itself is the problem. I would use the gradient function rather than diff, since it uses a much more sophisticated algorithm than simply the element-wise differences such as diff returns.
Note that taking the derivative of any ‘real world’ signal will amplify the noise. If you want to use the derivative, you may have to re-filter the the derivative of the signal — with the same filter — to get rid of the noise. The spectra of the original signal and the derivative should be the same, so the same filter should work well.
EDIT — I posted my last Comment before your plot posted. My Comment remains unchanged. You have high-frequency noise that my original filter will eliminate.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


