2

I have a time-series of voltage values recorded in mV every 0.02 ms, stored as a numpy array.

If I do this,

dv_dt = np.gradient(v),

what will the units of dv_dt be? Will it be some multiple of V/s; e.g. mV/s, mV/(0.02 ms), etc?

My understanding is that gradient returns the derivative of the argument passed to it. Is that right?

See this related question.

1 Answer 1

2

Watch out for the unit spacing of dt. As noted in the documentation gradient assumes unit spacing of 1 unless you provide the sample distance by the vararg argument. Your case is only correct, if dt = 1 for all datapoints.

You have to define your units by yourself. It is fine to use milliseconds but unless you do not have a good reason for it, I would use SI units (in this case seconds and Volts; which is the same as mV and ms). The gradient will have units of mV/ms or V/s.

In your case np.gradient(v,0.02) will give you the first order difference of the voltage signal corrected with your spacing of the time axis.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer. dt is the same for all my datapoints -- it's 0.02 ms, like i said in the question statement -- unless i'm misunderstanding you. with the assumption that dt = 1, is that referring to the spacing in the array, as in, every step of one element in the array represents one dt? i'm still not clear on what the units are of the derivative in my case.
dv/dt means that you first take the derivative of v and divide it by the derivative of t. It makes a huge difference if your signal changes 1 mV in 1 millisecond or in 0.02 milliseconds. In the first case the gradient is 1 mV/ms, in the second case it is 50 mV/ms
ok, so i worked it out by hand, and coming back to this i have a better understanding of what you were trying to say. the right call for me to make is np.gradient(v, 0.02), assuming i want to keep the input array itself as it is. the returned array -- the derivative -- is in units of V / s (not mV / s or anything else, which i guess should've been obvious, considering i submitted a dt in ms and a voltage in mV). if you reword your answer to incorporate this, i'll accept it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.