Dear all I have sampled some data using a 16bit ADC the data is in short(16-bit int) format, now I want to use the Cortex CMSIS DSP library to do some calculations like calculating rms values.I have used the arm_rms_q15 function, but the input to this function is in q15 format. How can I convert the short and other int types to the data that has been used in this library? Any ideas are welcome.
Well after the first post I read the wiki, but I did not get their point on type conversion. You mean I should divide all the adc data by 32768? Would you answer one simple question to me? Suppose I have one short variable(min=-32768 max=32767). Now I want to convert it to q15 and after some calculations convert it back to int again. Would you write a simple demo code.I’m totally confused!
You mean I should divide all the adc data by 32768?
No.
Suppose I have one short variable(min=-32768 max=32767)
I'm reasonably certain your ADC doesn't actually produce values in that range, now does it?
So what's the actual data range? How do you think that should be mapped into the actual range of the q15_t type?
The ADC is AD7606 and it can produce data in that range!
Haven't it hit you yet, that you could see the ADC as a magic device that returns measurements within the range [-1 to 1) but with lots of fractional data?
Then my numbers represent values in q15 format like this 1 equals 1/32768 or 3.051758E-06 2 equals 2/32768 or 6.10352E-06 3 equals 3/32768 or 9.15527E-06 4 equals 4/32768 or 1.2207E-05 5 equals 5/32768 or 1.52588E-05 6 equals 6/32768 or 1.83105E-05 7 equals 7/32768 or 2.13623E-05 8 equals 8/32768 or 2.44141E-05
But why I’m still getting zero from running the rms function? Please do not answer me by another question!? Char temp[100]; q15_t qdata[8]={1,2,3,4,5,6,7,8}; q15_t qres; arm_rms_q15(qdata,8,&qres);
and if I convert the result to float I still get zero
arm_q15_to_float(&qres,&res,1); sprintf(temp,"rms=%d f=%lf",qres,res);
Your input numbers are too few/small. The function arm_rms_q15 underflows when computing the RMS. After having computed the sum of the squares, it divides the result with 32768 before computing the square root.
But why I’m still getting zero from running the rms function?
You're not --- because you did not get zero before.
And why exactly do you think you have to printf() a float (not even a double) with %lf?
I realize this is 10 years later but jesus christ you guys are some insufferable egos who really seem to enjoy flexing your big brains while being completely useless to someone trying to figure out this subject and how to practically approach this problem. Have you ever considered to apply some of your massive intelligence trying to understand what someone is asking even though they may not have to vocabulary or insight to know what questions to ask. And if you don't feel it's worth your energy (which is totally fine btw) no one is forcing you.
/end rant
Hi jobl
I see you have joined this community today to leave this comment. We have community guidelines in place to remind people of our expectations when interacting in the community. If you see something in the community that you feel is not acceptable then please report the content under the Actions menu.
Thanks
Oli from the Community team
Hi Oliver. Thanks, should probably have read that. Admittedly I got pretty triggered by the condescending atmosphere in this thread (and I think rightfully so) but I understand that you want to avoid flame wars in your community, apologies.
No worries, thanks for replying :). I think we have pretty supportive community today compared to this conversation from 10+ years, but we do have measures in place to respond to inappropriate interactions. Thanks again for the reply, I appreciate it.