This example shows how to perform basic peak analysis. It will help you answer questions such as: How do I find peaks in my signal? How do I measure distance between peaks? How do I measure the amplitude of peaks of a signal which is affected by a trend? How do I find peaks in a noisy signal? How do I find local minima?
Finding Maxima or Peaks
In this video I demonstrate hwo to set up a CRO (cathode ray oscilloscope,) and I explain how to demonstrate the key quantities in the waves topics. TrueRTA 's audio spectrum analyzer software shows you a detailed picture of what you're hearing in real-time, that is, as it happens. You can create your own professional measurement system starting with TrueRTA software on your PC.
The Zurich sunspot relative number measures both the number and size of sunspots. Use the findpeaks
function to find the locations and the value of the peaks.
The above plot shows sunspot numbers tabulated over 300 years and labels the detected peaks. The next section shows how to measure distance between these peaks.
Measuring Distance Between Peaks
Peaks in the signal seem to appear at regular intervals. However, some of the peaks are very close to each other. The MinPeakProminence
property can be used filter out these peaks. Consider peaks that drop off on both sides by at least 40 relative sunspot numbers before encountering a larger value.
The following histogram shows the distribution of peak intervals in years:
The distribution shows that majority of peak intervals lie between 10 and 12 years indicating the signal has a cyclic nature. Also, the average interval of 10.96 years between the peaks matches the known cyclic sunspot activity of 11 years.
Finding Peaks in Clipped or Saturated Signals
You may want to consider flat peaks as peaks or exclude them. In the latter case, a minimum excursion which is defined as the amplitude difference between a peak and its immediate neighbors is specified using the threshold
property.
The first subplot shows, that in case of a flat peak, the rising edge is detected as the peak. The second subplot shows that specifying a threshold can help to reject flat peaks.
Measuring Amplitudes of Peaks
This example shows peak analysis in an ECG (Electro-cardiogram) signal. ECG is a measure of electrical activity of the heart over time. The signal is measured by electrodes attached to the skin and is sensitive to disturbances such as power source interference and noises due to movement artifacts.
Detrending Data
The above signal shows a baseline shift and therefore does not represent the true amplitude. In order to remove the trend, fit a low order polynomial to the signal and use the polynomial to detrend it.
After detrending, find the QRS complex, which is the most prominent repeating peak in the ECG signal. The QRS complex corresponds to the depolarization of the right and left ventricles of the human heart. It can be used to determine a patient's cardiac rate or predict abnormalities in heart function. The following figure shows the shape of the QRS complex in an ECG signal.
Thresholding to Find Peaks of Interest
The QRS complex consists of three major components: Q wave, R wave, S wave. The R waves can be detected by thresholding peaks above 0.5 mV. Notice that the R waves are separated by more than 200 samples. Use this information to remove unwanted peaks by specifying a 'MinPeakDistance'.
For detection of the S-waves, find the local minima in the signal and apply thresholds appropriately.
Finding Local Minima in Signal
Local minima can be detected by finding peaks on an inverted version of the original signal.
The following plot shows the R waves and S waves detected in the signal.
Next, we try and determine the locations of the Q waves. Thresholding the peaks to locate the Q waves results in detection of unwanted peaks as the Q waves are buried in noise. We filter the signal first and then find the peaks. Savitzky-Golay filtering is used to remove noise in the signal.
We perform peak detection on the smooth signal and use logical indexing to find the locations of the Q waves.
The above figure shows that the QRS complex successfully detected in the noisy ECG signal.
Error Between Noisy and Smooth Signal
Notice the average difference between the QRS complex in the raw and the detrended filtered signal.
This demonstrates that it is essential to detrend a noisy signal for efficient peak analysis.
Peak Properties
Some important peak properties involve rise time, fall time, rise level, and fall level. These properties are computed for each of the QRS complexes in the ECG signal. The average values for these properties are displayed on the figure below.