39. Numerical differentiation

39. Numerical differentiation - Numerical Differentiation...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
©2009 by L. Lagerstrom Numerical Differentiation • For an introduction to the basic concepts, see the associated video clip • The diff function • The backward difference (BD) approximation for a noisy signal • The central difference (CD) approximation for a noisy signal • Finding acceleration using a forward difference (FD) approximation • Difference approximation vs. curvefitting
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Command window display ©2009 by L. Lagerstrom The diff Function %The diff function will calculate %the differences between each %element in a row vector. %Some sample data x = [ 0 5 10 15 20 25] y = [20 30 25 50 80 100] %Calculate differences delta_x = diff(x) delta_y = diff(y) %Do rise/run calculations deriv = delta_y./delta_x %Note that the third value, for %example, in deriv (the value 5) may %be taken as a forward difference %approximation for the third data %point (10,25), or a backward differ- %ence approximation for the fourth %data point (15,50). Either way, %the rise/run = (50-25)/(15-10) = 5. x = 0 5 10 15 20 25 y = 20 30 25 50 80 100 delta_x = 5 5 5 5 5 delta_y = 10 -5 25 30 20 deriv = 2 -1 5 6 4
Background image of page 2
Matlab code Command window display ©2009 by L. Lagerstrom The diff Function, cont. %Redisplay code from previous slide %to make another point x = [ 0 5 10 15 20 25] y = [20 30 25 50 80 100] delta_x = diff(x) delta_y = diff(y) deriv = delta_y./delta_x %These rise/run results may be taken %as either forward difference (FD) %approximations or backward differ- %ence (BD) approximations. If we %choose to do FD approximations, then %the five values in deriv are FD %approximations for the first five %data points in the (x,y) data set. %(The last point, i.e. (25,100), does %not have an FD approx., because %there's no forward point to go to.) %If we choose BD approximations, then %the five values in deriv are BD %approximations for the second %through last point in the (x,y) set. x = 0 5 10 15 20 25 y = 20 30 25 50 80 100 delta_x = 5 5 5 5 5 delta_y = 10 -5 25 30 20 deriv = 2 -1 5 6 4
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Figure window display ©2009 by L. Lagerstrom The BD Approximation for a Noisy Signal %Imagine that we have measured a sinu- %soidal signal with some noise in it. %We'll simulate this with 50 (t,x) %data points, created by adding Gaus- %sian random values with a standard %deviation of 0.025 to a sine function %with a max amplitude of 1: t = linspace(0,2*pi,50); x = sin(t) + 0.025*randn(1,50); %Plot the data to check it out plot(t,x,'.') title('Noisy Sine Signal') xlabel('t') ylabel('x') axis([0 2*pi -2 2]) %We see that though there's a little %noise in the data, it's easy to %identify it as a sinusoidal curve.
Background image of page 4
Matlab code Figure window display ©2009 by L. Lagerstrom The BD Approximation for a Noisy Signal, cont. %Now calculate the 49 rise/run values
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 17

39. Numerical differentiation - Numerical Differentiation...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online