Smoothing can cause problems with the measurements if used incorrectly. You need to conduct some initial testing to determine the optimum width. This means you need to determine the number of data points that will remove a sufficient amount of noise without removing significant features of the original signal. However, since you cannot explicitly see the smoothed data, it is difficult to determine the optimum width through visual verification.
In most cases, it is preferable to smooth or process the data before applying the peak detection function. In that case, use a width of three, which tells the peak detection function to process exactly the signal you passed to it, without any smoothing. This method gives you more control over the smoothing and processing of the original signal. The peak detection function then processes only the signal that you pass to it.
Figures 8a, b, and c illustrate this situation. Figure 8a shows a noisy signal and the peaks detected after running the peak detection function using width = 3. Many spurious peaks are detected, and true, de-noised peaks are difficult to locate.
Figure 8b shows the same signal analyzed by the peak detection function using width = 29, a relatively large value. The function detects only three peaks in this case. These peaks may be correct, but it is difficult to determine whether this peak information is really useful.
Figure 8c shows the signal, smoothed by using the same method as the peak detection algorithm, and then passed to the peak detection function. Now the peaks are clear; the results are reasonable and verifiable.
Figure 8a. A noisy waveform after being passed through the peak detection function using width =
The black dots mark the detected peaks; most of the marked peaks are not really of interest, but are due to the noise.
Figure 8b. The same signal as in Fig. 8a using width = 29
The three large black dots are the peak locations returned by the function. It is difficult to tell whether the dots represent accurate amplitudes or locations.
Figure 8c. The same signal as in Figure 8a, using width =
, after being smoothed and then analyzed with the peak detection function
The locations of the peaks are clear and the points selected by the algorithm are reasonable.
Since the goal is to obtain accurate locations of peaks and valleys, make sure that any preprocessing of the signal does not shift the signal in time. Such a shift offsets all of the peak location numbers relative to their true locations in the original signal.
Another way to get accurate results from the peak detection functions is interpolation. Interpolation resamples the signal at a higher sampling rate and returns better results.
There are several common methods of interpolating discrete-time signals. A simple method is linear interpolation. If you have an interpolating factor of q, then q-1 points are inserted between each original data point. With linear interpolation, the added points lie on the line through the original data points on either side. While these results are not an accurate representation of the original analog signal, they can help the peak detection algorithm to detect all of the valid peaks.
Another method of interpolation is to interleave q-1 zeros between each of the original data points, then execute a lowpass filter. The theory behind this method is beyond the scope of this document; however, many texts on discrete-time signal processing contain an explanation of this method. For more information on this method, refer to the References section at the end of this document.
A certain trade-off comes with interpolation. Interpolating the digitized signal tends to place the found peaks closer to actual points in the interpolated signal. However, depending on the nature of the analog signal, these may or may not be closer to the real peaks than those detected using the uninterpolated digital signal. So the trade-off is between finding all valid peaks and getting more accurate data for the peak locations and amplitudes.