Could you give me a simple explanation of how to smooth a signal?
2 views (last 30 days)
Show older comments
Okay, so I've loaded, plotted my ECG signal and a graph has appeared.. But how can I make it smooth now? I don't understand the examples that are written in your website. Please help?
1 Comment
Star Strider
on 14 Oct 2017
You posted no details, so I am not posting this as an Answer.
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1.0 100]/Fn; % Passband Frequency (Normalised)
Ws = [0.5 101]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sosbp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(sosbp, gbp, original_signal); % Filter Signal
Note — The ‘original_signal’ here is your EKG. Make the appropriate changes (specifically the correct value for ‘Fs’, that must be at least 250 Hz for this filter to work) to get the result you want.
See the documentation on the various functions to understand how my code works.
Answers (1)
John D'Errico
on 14 Oct 2017
This is not a question about MATLAB, but a request for someone to write a small book. Ok, a large book if done well. So I should leave it alone. And I won't give you code. You need to do some reading.
There are literally dozens of ways to do smoothing of a curve. A few...
1. An exponentially weighted moving average. Simple, a geometric decreasing weight for old points as you move along the curve. Of course, that brings to mind the entire field of ARIMA methods, and signal processing in general, so entire toolboxes.
2. Smoothing splines. NOT spline. A smoothing spline, which penalizes the problem with integral of the square of the second derivative. Noise has large second derivatives. So kill that off, and your curve is smoother. Note that this can introduce a variety of new problems, such as ringing, or over-smoothing of a sharp transition in the curve.
3. Savitsky-Golay methods, which are just local low order polynomial regression models, implemented using convolutional methods. They can be used to extract a local estimate of the function value at each point in the curve, or a derivative.
4. Convolution with a blur kernel. Assuming the noise is additive with zero mean and the signal well behaved, a Gaussian blur blurs the noise, decreasing the noise variance, but won't harm the signal much.
5. Kalman filter methods. Again, extract a local estimate of the signal, based on what came before.
6. Fourier transform - thus take the fft, decreasing the high frequencies. Then take the inverse fft. Since noise is purely high frequency, this kills off the bad stuff, while leaving the signal alone. You hope. As with all smoothing methods, there is a tradeoff, because many signals do have some high frequency behavior.
The list can go on for a long time, and I know I forgot to list a few that I was going to mention. To some extent it depends on which tools you understand, as they can all be made to work. All of these methods essentially use the concept that noise is high frequency with high derivatives, while your signal is well behaved and essentially smooth.
Any kind of smoothing that looks at the curve and tries to remove the noise while leaving the signal behind will have problems in that it can easily harm the signal itself. Understanding the methods and the artifacts they can create are as important as knowing how to implement the method, or knowing what tool can be used to do the dirty work.
0 Comments
See Also
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!