Peak Analysis

The peaks of a signal are most noticeable and useful features. And for that reason, peak analysis is an important area of signal processing. You may want to find out how many peaks are there in the signal, how far apart they are from each other, or whether they follow some kind of pattern. In this video, I will show you how you can detect, locate, and display peaks of signals using find peaks function. I will concentrate on two typical tasks—determining the period of a signal by measuring the distance between its peaks and finding peaks in a noisy signal.

Let us load some data into MATLAB®. The plot here shows the number of sunspots that have been observed over time for the last 300 years. Sunspots are spots or patches that appear on the surface of the sun.

Their number is known to vary periodically. The signal clearly contains many peaks. Let us use find peaks function to see where they are. The function blocks the signal and displays all the peaks when it is called with no output arguments.

You can limit the number of peaks displayed by using the end peaks option. Here, I have chosen to display the first 15 peaks. You may also want to filter out peaks that are so close to others that they do not provide new information. Use the min peak distance option to ignore those closely spaced peaks. Please refer to the documentation of find peaks for a list of available properties.

We can now calculate the distance between the maximum values to see how often the sunspot activity peaks. Find peaks reveals the amplitude of the peaks and their location. Applying the function to the signal returns a number of sunspots during peak years and the peak years themselves.

I set the min peak distance parameter to 6 to ignore closely spaced peaks. We see that the first peak occurred in the year 1705, the second in the year 1717, et cetera. There was a 12-year interval between the first and second peaks, 10 years between the second and third, and so on. We can use diff function on the peak years and find the average interval. This number turns out to be 10.96 years, which is approximately equal to the actual sunspot cycle of 11 years.

Next, we will see how to detect peaks in a noisy signal. Let us load a fragment of an ECG signal in MATLAB. Despite all the noise, we see a repeating structure in the ECG signal.

The most noticeable up-down pattern is called the QRS complex. Cardiologists use the properties of the QRS complex to diagnose abnormal heart behavior. The up peaks are called R waves. To detect them, set the min peak height option to 0.5 millivolts. There is a chance that some peaks that are not R waves may be higher than the 0.5 threshold because of noise. To filter out the false positives, we can impose a minimum peak-to-peak separation by setting the min peak distance to 200.

The down peaks right after the R waves are the S waves. To find them, we can proceed exactly as before after flipping the signal upside down. The dips right before the R waves are called the Q waves. These are harder to detect because they are much smaller and often buried in the noise. One solution is to eliminate some of the noise by using a smoothing filter. Savitzky-Golay filters are a popular tool to clean up signals.

If we plot the original and the smooth data, we can see that the filtering has made the Q waves stand out more clearly. We can now detect, locate, and display the Q peaks just like we did with the R and S waves. Once we have found and characterized the three sets of peaks, we are ready to study the ECG signal in detail. For more detailed information, please refer to the peak analysis example in the Signal Processing Toolbox documentation.