Why is the derivative of a function or signal one sample shorter that the orignal?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
farzad
el 11 de Abr. de 2020
Comentada: Star Strider
el 11 de Abr. de 2020
Hi All
taking the derivative of y=x.^2 using diff(y) , between 0 and 100 gives a signal with one less Sample, meaning instead of length of 101, it is 100 samples. so every derivative, it will get one sample shorter and if I have to integrate again, it will need those samples again maybe ? what should I do ?
0 comentarios
Respuesta aceptada
Star Strider
el 11 de Abr. de 2020
Use the gradient function to calculate the numerical derivatives. The output will be the same length as the input. (It is also more accurate in that respect.) The function assumes regularly-sampled data, however if the sampling intervals are not constant, a work-around for that is:
dydx = gradient(y) ./ gradient(x);
.
2 comentarios
Más respuestas (1)
Cris LaPierre
el 11 de Abr. de 2020
diff is taking the difference between adjacent data points. Because the difference is between two points, this causes the result to be one data point shorter.
For a simple array x=[3 4 5], diff(x)=[4-3 5-4] = [1 1].
2 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!