02-16-2017 04:57 AM
Is there a way to reinterpret a FXP number with a control? So that I can choose the number of positions I want the decimal point to move without increasing the number of bits used, nor losing precision.
02-16-2017 05:39 AM - edited 02-16-2017 05:44 AM
Hi gerard,
what about the ToFXP function? It's available in the FPGA…
So that I can choose the number of positions I want the decimal point to move without increasing the number of bits used, nor losing precision.
How do you want to change the number? Could you provide an example?
When you use the same amount of bits and the same resolution then where do you want to "move the decimal point"? (Btw. FXP numbers use a binary point as they are coded using base 2! :D)
02-16-2017 09:08 AM
Can you explain more about the use case you have in mind for such functionality?
02-16-2017 09:24 AM
Yes, I should have said binary point. In any case: the application is real time signal processing with an FPGA. There is a signal that I may want to, internally, amplify by multiplying it by 2^n (where n can be negative). I'm not multiplying by an arbitrary constant because execution time and number of DSPs used are crucial. For this, I would just need to change the "binary point" position (aka reinterpret the number) dynamically, meaning that I would like to change this prefactor arbitrarily, but without truncating the variable, as to FXP seems to do. Just move the point up and down to whatever position I want without changing the number of bits.
I'm not sure that is possible though. It's a pity I can't work with floating point variables.
02-16-2017 10:31 AM - edited 02-16-2017 10:37 AM
If you're just wanting to scale by a power of 2, that's not really a problem. Scaling by a power of 2 is supported on LabVIEW FPGA:
http://zone.ni.com/reference/en-XX/help/371361J-01/glang/scale_by_power_of_2/
Alternatively, you can also use a Shift function to perform the same operation but you have to be careful about your sign bit (which makes the Scale by Power of 2 safer if your FXP type is signed):
http://zone.ni.com/reference/en-XX/help/371361J-01/glang/logical_shift/
Also, you actually can work with floating point numbers on FPGA -SGLs are a supported data type but your operations become more "expensive" because of having to deal with the mathematical operations to deal with moving the decimal point around. I'd most likely recommend sticking with FXP and keeping enough bits to handle your desired precision.
02-16-2017 12:27 PM
Hi Gerard,
Since the FXP precision and generally the types are configured at compile time then they have to be fixed. I think you have a couple of options though:
I'm not sure I fully understand your entire structure but hopefully that helps give some ideas.
Cheers,
James