- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
imean (X1-X2)*mod
where mod properly scales the value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for the Signu, depending on the data type you could just check the sign bit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Zeta
That's not enough, remember the Zero which should return 0
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
my ad, but you just need to add a comparison for the special case of zero
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
my bad*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not too bad (Smile)
Bob