Remove Trends from Data - MATLAB & Simulink (2024)

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)'

Remove Trends from Data- MATLAB & Simulink (2)

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

detrend | polyfit | polyval

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.

Remove Trends from Data- MATLAB & Simulink (3)

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

Europe

Asia Pacific

Contact your local office

Remove Trends from Data
- MATLAB & Simulink (2024)
Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5840

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.