In the following snippet, I am differentiating a sine wave using the central difference equation, first through misc.derivative and then through convolution with the kernel [1/2, 0, -1/2]
import numpy as np import scipy.misc as misc import scipy.signal as sig ncycles = 5.0 nsamples = 500.0 x = np.linspace(0,ncycles*2*np.pi,nsamples) dydxmisc = misc.derivative(np.sin,x,dx=0.1) dydxconv = sig.convolve(np.sin(x), [0.5,0.0,-0.5], mode='same')
The attenuation changes based on number of cycles and number of samples and is a factor of pi but I cannot figure out what the exact relationship is. Can anyone explain why the attenuation happens and what the relationship is? In other words, how do I have to scale the kernel in order to get a derivative of the correct dimension?