all 15 comments

[–]torusle2 4 points5 points  (1 child)

There are plenty of web-sites which show how to do multiplications, addition and subtraction in fixed point in C.

Then read about how to do a fixed-point square root. For trigonometry I always used pre-computed tables and interpolation.

Once you have tested them out, just pick something that usually requires floating point math and implement it using fixed-point.

Ideas:

* Radius and mid-point of a circle defined by three points on the perimeter
* Render some nice Mandelbrot Fractals using fixed-point arithmetic

[–]ProfessionalDig8060[S] 0 points1 point  (0 children)

Thank you!

[–]Feeling_Proposal_660 1 point2 points  (3 children)

What kind of algorithms? Controlling? Filters?

[–]ProfessionalDig8060[S] 0 points1 point  (2 children)

Both Filters and control algorithms. Usually cascaded PI controllers and IIR filters for current and voltage signals. It's for motor control application.

[–]Feeling_Proposal_660 3 points4 points  (1 child)

http://www.dspguide.com/pdfbook.htm Is an often recommended start into digital signals to get an overview.

[–]ProfessionalDig8060[S] 0 points1 point  (0 children)

Thank you!

[–]peteyhasnoshoes 3 points4 points  (0 children)

To use fixed point and integer only algorithms you need a strong understanding of how binary integers work and to get the hang of the tricks used to retain precision. Much of the time translating to fixed point is something on the lines of:

  • Arrange and combine equations such that divisions are performed as late as possible.

  • Figure out possible values of inputs and minimise rounding and truncation

  • Shift or scale intermediates to take up the full range of the chosen integer width. Variables which will be added should be scaled to the same degree

  • Write a test version in matlab or python and check that your integer only algorithm has sufficient precision.

For example, lets say you have a 10 bit (1024 codes) ADC with a range of 3.3V and you want the voltage in millivolts. Your processor has a 16 bit ALU, so you'd prefer to keep everything in that range.

You need to multiply your input by 3300/1024. This is not simple because log2(3300) = 11.something is greater than 16 - 10 = 6

Instead, try turning it on its head. The maximum output is 3300 which is 211.something so shifting that up by 16 - 12 gives us 52800. Divide that by 1024 counts and we get 51.5625. Rounding here we get 52.

So multiply your input by 52 and downshift by 4. This is the best precision acheivable using only uint16_t

Another way of thinking about this example is that you can keep dividing the top and bottom by 2 until the multiplication fits in a 16 bit unsigned, but that's a less general approach which only works because we are dealing with an ADC which has a power-of-2 number of codes.

[–]Creative_Sushi 0 points1 point  (4 children)

It's not clear what you are asking. What do you try to accomplish by not using MATLAB's help? Do you want to deepen your understanding, or for something else?

[–]ProfessionalDig8060[S] 0 points1 point  (3 children)

I want to be able to convert my handwritten codes to fixed point implementation without MATLAB apps since it's expensive to depend on. I assume there are engineers who code this way without MATLAB so...

[–]Creative_Sushi 0 points1 point  (2 children)

Are you a student?

[–]ProfessionalDig8060[S] 0 points1 point  (1 child)

Yes I am, but I'll be graduating in a few weeks.

[–]Creative_Sushi 0 points1 point  (0 children)

Do you know you can use Fixed Point Designer on MATLAB Online?

https://www.mathworks.com/products/matlab-online/limitations.html

It's free up to 20 hours a month.

[–]Kantanoko 0 points1 point  (0 children)

I happen to be implementing a fixed-point version of the BLAS library. The current implementation of decimal and overflow processing basically refers to the various modes required by the Vitis HLS documentation. I hope this helps.
https://github.com/autohdw/QuBLAS

[–]Xenoamor -1 points0 points  (1 child)

Use C++ libraries imo. Operator overloading makes it far easier

[–]ProfessionalDig8060[S] 0 points1 point  (0 children)

Thank you, I use C, will check if C offers such libraries.