Using ARM’s CMSIS DSP Library: arm_sqrt_q15

September 27th, 2011 by Eric Cope

I continue the ARM CMSIS DSP series, this time demonstrating arm_sqrt_q15. This function takes the sqrt of a fractional input, and returns the value (by reference) and some error detection. Here is the function definition:

arm_status arm_sqrt_q15(q15_t in, q15_t * pOut)

“in” really is a Q Format of 1.15. 0 is represented as 0×0000. 1 is represented as 0x7FFF. This means that 1/2 is represented as 0×4000. The returned value is a status, ARM_MATH_SUCCESS or ARM_MATH_ARGUMENT_ERROR, self descriptive.  The other returned value by reference is the result of the operation, pOut. This is also a 1.15 formatted number. Note that when taking the square root a fraction, the number should always be larger, but never greater than 1.0.  Here is an example:

arm_sqrt_q15(0x4000,&jj);

1/2 is represented as 0×4000. sqrt(1/2) is approximately 0.707. The function returns 0x5A82 = 23170 / 2^15 = 0.707.

Success!

That concludes this quick example of ARM’s function arm_sqrt_q15. Here is the link to ARM’s library. Also, here is some documentation [pdf] for TI’s processors helpful in understanding their functions which translated to ARM’s.

 

Using ARM’s CMSIS DSP Library: arm_recip_q15

September 27th, 2011 by Eric Cope

I’ve begun using ARM’s free CMSIS DSP library on a project, but the documentation is quite sparse. So, I’ve started documenting how to use these functions as I learn by trial and error. The first function is: arm_recipt_q15.


static __INLINE uint32_t arm_recip_q15(
q15_t in,
q15_t * dst,
q15_t * pRecipTable)
{
uint32_t signBits = 0;
...
return (signBits + 1);
}

This function takes the reciprocal of a fixed point variable, in. The format of the input, in, is in the Q Format 2.14, not 1.15 that the name implies. For example, 0.25 is represented as 0×1000, 0.5 is represented as 0×2000. RecipTable is a Lookup Table within the ARM library. The function returns two values, dst and signBits. although dst is declared a q15_t, it is not. It is a 16bit data type with the number of sign bits designated in the other return value, signBits. Crafty, huh? Here are some examples.

arm_recipt_q15(0.25) returns 3.998.

signBits = arm_recip_q15(0x1000,&out,armRecipTableQ15);
signBits = 0x3
out = 0x7FFE

The sign bits are “011″ and the fraction is “0x1FFE”. That is 3 + (8190 / 8192) = 3.9998 which is approximately 4.

That concludes this quick example of ARM’s function arm_recip_q15. Here is the link to ARM’s library.

UPDATE: I found this documentation [pdf] for TI’s processors helpful in understanding their functions which translated to ARM’s.

 

Eliminating Facebook App Scroll Bars

September 7th, 2011 by Eric Cope

Facebook makes it difficult to remove scroll bars from an App iFrame. Here is how I did it.

<script type="text/javascript">
FB.init({
appId  : '<?php echo $app_id; ?>',
});
function setHeight(height){
var pix_height = height * 55 + 225 + 50;
FB.Canvas.setSize({height: pix_height });
}
</script>

I was posting a table, so I estimated what each row required, 55 pixels, what the header required: 225 pixels, and the 50 pixels of safety. Then, when I was done generating the content (using jquery), I called setHeight(num_of_rows) and away it went.

 

Git Error and File Rename

September 7th, 2011 by Eric Cope

We use Git here to manage all file versioning, mostly because its awesome. However, every once in a while we get an error message that is too cryptic, even for us. We recently got this message while trying to commit a file:

pathspec: 'filename' git did not match any file(s) known to git

It took some googling and some introspection, but we finally figured it out. We had deleted the file, Foursquarelib.php and replaced it with foursquarelib.php. Do you see the subtle difference? When we deleted Foursquarelib.php, we forgot to tell Git about the removal. Using the trusty command line, we:

touch Foursquarelib.php

Then, in our Git client, we “removed” Foursquarelib.php and added/commited foursquarelib.php, and Git was so excited for us, it couldn’t contain itself. All is well. We hope this helps somebody, maybe even ourselves in the future.