Fixed point arithmetic on Photon (libfixmath)

photon
Tags: #<Tag:0x00007fe222c3fa58>

#1

Hey guys,

I am working on an implementation of the modified Goertzel Algorithm (an efficient single point DFT) and am in the process of optimizing the code for the Photon. I am under the impression that since floating point arithmetic is implemented in software for the photon, it would be better if I could use a fixed point implementation. This is also so that I can transmit the data to a server on my computer with 16 bit precision. To be completely honest, I have no idea how to implement this myself, so if anyone has any resources to recommend it would be much appreciated.

I can share the algorithm if that helps.

Cheers.


#2

Okay, I have found something that will probably work for my purposes. It’s a library called libfixmath. It has all of the capabilities that I need and does 16.16 fixed point arithmetic. It is supposedly platform independent, so porting it shouldn’t be an issue. However, I have never set up a library outside of what is included in the standard development environment. So I guess this is where I should start.


#3

What are you using web IDE or workbench?

Very basically you will need to create a .h file and a .cpp file. In the web IDE you just click on the ‘+’ symbol on the right of the top line of tabs. What are you porting the fixed16 library from?


#4

I use both the workbench and the web IDE. I find that visual studio is much more pleasant to work in while I’m coding, but the web IDE complies much faster. So I just copy and paste in between. Edit: I was just being an idiot and not using the workbench properly.

From what I understand, libfixmath is just a standard C/C++ library. Unfortunately, it does not appear to be the best documented, so I am just trying to dig around in order to understand how to best import it into my development environments.


#5

Hey @mindless, I’ve started a Workbench project that implements libfixmath that I hope to release as a library.

Workbench seems to be happy about the code, but I’m getting linker errors when building the project.

EDIT:
I’ve fixed the linker error. The original code used printf() a lot and I had to replace it with Serial.printf()

UPDATE:
I’ve run the project on a photon and all tests pass.

UPDATE:
I’ll make some more demos and release it as a library tomorrow hopefully.

UPDATE:
I have released the libfixmath library. You can now use it in the Web IDE, CLI, or Workbench.


Looking for some advice on porting libfixmath
#6

Hell yeah man! Looks like it was fairly straight forward. Thanks for taking the time to get it running.


#7

No problem. I felt like getting some more practice with porting libraries. Let me know if it works well for your application.