Open Live Script
Measured signals can show overall patterns that are not intrinsic to the data. These trends can sometimes hinder the data analysis and must be removed.
Consider two electrocardiogram (ECG) signals with different trends. ECG signals are sensitive to disturbances such as power source interference. Load the signals and plot them.
load('ecgSignals.mat') t = (1:length(ecgl))';subplot(2,1,1)plot(t,ecgl), gridtitle 'ECG Signals with Trends', ylabel 'Voltage (mV)'subplot(2,1,2)plot(t,ecgnl), gridxlabel Sample, ylabel 'Voltage (mV)'
The signal on the first plot shows a linear trend. The trend on the second signal is nonlinear. To eliminate the linear trend, use the MATLAB® function detrend
.
dt_ecgl = detrend(ecgl);
To eliminate the nonlinear trend, fit a low-order polynomial to the signal and subtract it. In this case, the polynomial is of order 6. Plot the two new signals.
opol = 6;[p,s,mu] = polyfit(t,ecgnl,opol);f_y = polyval(p,t,[],mu);dt_ecgnl = ecgnl - f_y;subplot(2,1,1)plot(t,dt_ecgl), gridtitle 'Detrended ECG Signals', ylabel 'Voltage (mV)'subplot(2,1,2)plot(t,dt_ecgnl), gridxlabel Sample, ylabel 'Voltage (mV)'
The trends have been effectively removed. Observe how the signals do not show a baseline shift anymore. They are ready for further processing.
See Also
Related Topics
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Contact your local office