8 Replies Latest reply on May 11, 2013 8:09 AM by JoMe_264151

# How to get derivative and signum function in PSoC 5

Hi, I want to develop an algorithm my project ( for a control systems design). For the same I need to take derivative of functions. So can someone help me to get the derivative of a function in PSoC5 (code in main.c)

I am also trying to implement the signum function in the 'main.c' but i am getting many errors. Please help me to get the derivative and signum function,.

• ###### 1. Re: How to get derivative and signum function in PSoC 5

if you have the values of the function in an array it is just a matter of doing simple X1-X0*mod and storing it in another array

• ###### 2. Re: How to get derivative and signum function in PSoC 5

imean (X1-X2)*mod

where mod properly scales the value

• ###### 3. Re: How to get derivative and signum function in PSoC 5

Signum is defined as 0 if x==0; 1 if x >0 and -1 if x<0. Nothing we can tell more without a bit more insight into what runs and what not.

To calculate the derivate of a given function you have the choice to calculate it as a math solution and implement the function in C as usual or calculate an approximation based on the hints of the previous post calculating dY/dX as discrete (Y1-Y0)/(X1-X0) and keeping an eye on (X1-X0) getting near zero.

It sounds a bit like programming a control-loop (PID) . there are examples in the web for C subroutines.

Bob

• ###### 4. Re: How to get derivative and signum function in PSoC 5

for the Signu, depending on the data type you could just check the sign bit.

• ###### 5. Re: How to get derivative and signum function in PSoC 5

@Zeta

That's not enough, remember the Zero which should return 0

Bob

• ###### 6. Re: How to get derivative and signum function in PSoC 5

my ad, but you just need to add a comparison for the special case of zero