简体   繁体   中英

Best way to program piecewise-linear function on DSP TMS320C5509

There is a Table of pairs , which defines pieces bounds. And we are using straightforward algorithm:

y = f(x)

  1. Calculate index n in Table using x
  2. Get Yn and Yn+1, compute linear interpolation Y

Y is the answer.

So i think, there must be more efficient method, could you please point me?

Depending on the number and distribution of pairs, you might be able to instead store a table T containing only the Y values at regular intervals. Pick the interval to be a power of 2: i=2^c. Then for a given X:

n=X>>c;
Y= T[n]
Y+= ((T[n+1]-T[n])* (X&(i-1))>>c;

This should work as long as you have space for a table with small enough intervals to catch sudden changes in the slope of Y, and enough headroom in Y for the multiply.

Use binary search for step 1.

EDIT: due to the comment you added afterwards, this is not necessary, since your intervals are equally spaced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM