Lecture32_Signal_Processing_II_ECG_Processing

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
x=[1:20];
y=polyval(p,x);

Results:
44.1000000000000    -5.20000000000000    -79.3000000000000    -171.600000000000    -275.500000000000    -384.400000000000    -491.700000000000    -590.800000000000    -675.100000000000    -738    -772.900000000000    -773.200000000000    -732.300000000000    -643.600000000000    -500.500000000000    -296.400000000000    -24.6999999999992    321.200000000000    747.900000000001    1262

Definitely, you can do the following to get the same Y values:
x=[1:20];
y=1.1*x.^3 + (-19)*x.^2 + 0*x.^1 + 62*x.^0; % Don't forget the element-wise operation for the exponential values.

Results:
44.1000000000000    -5.20000000000000    -79.3000000000000    -171.600000000000    -275.500000000000    -384.400000000000    -491.700000000000    -590.800000000000    -675.100000000000    -738    -772.900000000000    -773.200000000000    -732.300000000000    -643.600000000000    -500.500000000000    -296.400000000000    -24.6999999999998    321.200000000001    747.900000000001    1262

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 collected.

For example, you sampled the X and the Y data as:
x=[0.9 1.5 3 4 6 8 9.5];
y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3];
plot(x,y,'*')
hold on
p=polyfit(x,y,5)； % the polynomial has a degree of 5
xx=linspace(0,10,30); % create more data points in your fitting curve
y2=polyval(p,xx); % get the corresponding 'Y' values for the fitting curve
plot(xx,y2);

The fitted curve looks like:

You can fit more points among these points to predict a continuous curve. The function to 'fit' more points inside is polyfit().
Change the 'degree' will change the fitted curve dramatically.

1. Load the ECG signal in from Matlab: