Let's review the slides about the polynomials:
To summarize the two functions, polyval and polyfit:
1. Given a series of X values and the coefficients (an, an-1, ..., a0),
polyval is a function to calculate the 'Y' values in:
It is a very simple
function, as the example followed:
p=[1.1 -19 0
62]; % the coefficient vector
can do the following to get the same Y values:
(-19)*x.^2 + 0*x.^1 + 62*x.^0; % Don't forget the element-wise
operation for the exponential values.
The two results
are the same.
2. polyfit() is
a function that can create
a series of 'coefficients'
of a polynomial which allows you to adjust the 'degree' of the
polynomial to fit the a continuous curve to the discrete data you
For example, you
sampled the X and the Y data as:
x=[0.9 1.5 3 4 6
y=[0.9 1.5 2.5
5.1 4.5 4.9 6.3];
% the polynomial has a degree of 5
% create more data points in your fitting curve
% get the corresponding 'Y' values for the fitting curve
The fitted curve
can fit more points among these points to predict a continuous curve.
The function to 'fit' more points inside is polyfit().
'degree' will change the fitted curve dramatically.
1. Load the ECG
signal in from Matlab:
Then treat all
the points in the data as your collected data points, create a
corresponding 'X' series for these Y values.
Use polyfit(x,y,degree) to get the coefficients of the fitted curves.
Use different degree values: 1, 10, 20, 30, 40, 50, 60 to plot 7
different fitted curves. Have these figures in your report and describe
Use the original ECG signal subtract the pionts in each of the fitted
curve, then plot the results (7 different results). Have these figures
in your report and describe the differences. Discuss in your report
about your findings.
The 1-3 tasks are called 'De-trend' the ECG signal, which removes the noisy offset of the signal. Now, let's detrend
one more ECG signal using your script (try to not copy the code but
just type it from scratch). Use the peak detection method to count how
many heart beats are in this signal. The data can be found here:
Submit an electronic version of your report to the email. Again, have
figures, captions, title, explanations, and your code as the appendix.