Forum Discussion
Altera_Forum
Honored Contributor
12 years agosignal power estimation
Hello guys..
I'm trying to implement a block that evaluates the signal rms value along n samples. So, using the std definition one must do (x_k is a complex number so I have to take in account |x_k|): http://upload.wikimedia.org/math/0/1/4/014a453df92ed77eca97b228f0624d9f.png The simplier way I have in mind is to use an accumulator. By the way it will indroduce some overflow issues. There is a good way in doing this ?? Thank you !17 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- Hello guys.. I'm trying to implement a block that evaluates the signal rms value along n samples. So, using the std definition one must do (x_k is a complex number so I have to take in account |x_k|): http://upload.wikimedia.org/math/0/1/4/014a453df92ed77eca97b228f0624d9f.png The simplier way I have in mind is to use an accumulator. By the way it will indroduce some overflow issues. There is a good way in doing this ?? Thank you ! --- Quote End --- since your input is complex then square Re(Re*Re) + square Im(Im*Im) then accumulate this result over say 2^20 samples. The accumulator will need 20 bits extra(over that of adder result) to avoid overflow. For 1/n Discard 20 LSBs when you read final result before clearing it to restart. for square root, avoid it if you don't need it else use LUT or ip - Altera_Forum
Honored Contributor
--- Quote Start --- since your input is complex then square Re(Re*Re) + square Im(Im*Im) then accumulate this result over say 2^20 samples. The accumulator will need 20 bits extra(over that of adder result) to avoid overflow. For 1/n Discard 20 LSBs when you read final result before clearing it to restart. for square root, avoid it if you don't need it else use LUT or ip --- Quote End --- Dear Kaz, Please correct me if I'm wrong.. I think that in the worst case, at each addition I should need an extra bit. In that case if I add 2^20 samples I will need 2^20 extra bits... Or not ?? Probably I've only to try and find the correct value of bit needed to take 2^20 samples without overflow.. - Altera_Forum
Honored Contributor
--- Quote Start --- Dear Kaz, Please correct me if I'm wrong.. I think that in the worst case, at each addition I should need an extra bit. In that case if I add 2^20 samples I will need 2^20 extra bits... Or not ?? Probably I've only to try and find the correct value of bit needed to take 2^20 samples without overflow.. --- Quote End --- No that sort of bits is enough to count all cosmic stars or even my cash. for each pair of adds you need one bit so for 2^20 samples addition you need 20 bits more.(power of 2 maths) - Altera_Forum
Honored Contributor
imagine your input is just 1 (one bit), you add up 2^20 samples of 1, what you get?
1*2^20 = 2^20 which needs 20 bits(+1 bit) - Altera_Forum
Honored Contributor
--- Quote Start --- imagine your input is just 1 (one bit), you add up 2^20 samples of 1, what you get? 1*2^20 = 2^20 which needs 20 bits(+1 bit) --- Quote End --- Dear kaz It's ok. But what about working with 16 bits words ? If you add up 2^20 samples of 4 you will get 4*2^20 that needs more than 21 bits.. or not ? My problem is not the overflow of the counter but the one of the sum. - Altera_Forum
Honored Contributor
--- Quote Start --- Dear kaz It's ok. But what about working with 16 bits words ? If you add up 2^20 samples of 4 you will get 4*2^20 that needs more than 21 bits.. or not ? --- Quote End --- 4*2^20 requires 3 bits + 20 bits = 23 bits. in your case you have to multiply say 8 bits * 8bits => 16 bits +16bits => 17 bits + 20bits => 37 bits You can imagine that by cascading pairs of additions: sample1(17bits) + sample2(17 bits) needs 18 bits (res1) sample3(17bits) + sample4(17 bits) needs 18 bits (res2) res1(18bits) + res2(18 bits) needs 19 bits ... thus you imagine 20 cascaded stages of addition needed for 2^20 samples - Altera_Forum
Honored Contributor
Dear Kaz
I've got the point. That seems a nice solution ! But if i want to implement the adder in a cascaded stages style I have to do it by hand.. I was thinking about something recursive: https://www.alteraforum.com/forum/attachment.php?attachmentid=8569 - Altera_Forum
Honored Contributor
--- Quote Start --- Dear Kaz I've got the point. That seems a nice solution ! But if i want to implement the adder in a cascaded stages style I have to do it by hand.. I was thinking about something recursive: --- Quote End --- using parallel adders wastes massive number of adders (2^10 for just first stage). One accumulator will do equivalent job but needs reset to start and it is slow i.e. result will be available after 2^20 samples gone through but for rms it should do. - Altera_Forum
Honored Contributor
Thank you kaz.
How can I implement such accumulator ?Is there a precompiled standard block or has to be written by hand ? - Altera_Forum
Honored Contributor
--- Quote Start --- Thank you kaz. How can I implement such accumulator ?Is there a precompiled standard block or has to be written by hand ? --- Quote End --- just a feedback register on clocke edge sum <= sum + din; --din is I*I + Q*Q you need to read final result, apply reset etc. at the end you carefully get the mean of squares: sum_trunc <= sum(n downto 20); Then you decide for the square rooting issue