I'm trying to numerically differentiate a signal. As a test, I created a y=sin(x) signal. When I use diff(y), the output amplitude is scaled down to 0.1 instead of 1. The analytical solution is cos(x), therefore I'd expect the output to have an amplitude of 1 as well. What am I missing?

 採用された回答

Mischa Kim
Mischa Kim 2014 年 5 月 15 日
編集済み: Mischa Kim 2014 年 5 月 15 日

0 投票

Jonas, diff only calculates the differences between adjacent elements, the dy. To get the derivative you need to devide by dx, e.g.
x = 0:0.1:10;
y = sin(x);
dydx = diff(y)/(x(2)-x(1)); % assuming dx to be constant
plot(x(1:end-1),dydx)

1 件のコメント

Jonas Frei
Jonas Frei 2014 年 5 月 15 日
doh.. how obvious, thanks! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

質問済み:

2014 年 5 月 15 日

コメント済み:

2014 年 5 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by