Confusion using diff command in MATLAB

I have differentiated an array of signal using diff command of MATLAB but have a confusion in the result. My input signal is a sinusoidal signal and the differentiated signal is also expected to be sinusoidal. I am getting a sinusoidal signal after differentiating the original. However, the signal is not centered at the origin but is shifted in one side. That is, lets say instead of having amplitudes of 5 and -5, it is like 5.5 and -4.5. Can you give me some reason why it may be happening?
 

 Accepted Answer

This situation may arise in cases where  the sampling time is not small enough. Here is an example that highlights this:
>> x=linspace(0,20*pi,10000);
>> plot(100*diff(sin(100*x)))
Notice that the envelope of the signal is not constant as one would expect. By reducing the sample time, i.e.,
x=linspace(0,20*pi,100000);
The envelope becomes constant as expected. Because "diff" operates by subtracting consecutive numbers, the sampling time of the signal is important so I selecting an appropriate value for this parameter is important.

More Answers (0)

Products

Release

R2016a

Community Treasure Hunt

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

Start Hunting!