Need explanation for the lines of code in the filter function

Status
Not open for further replies.

patan.gova

Full Member level 3
Joined
Dec 19, 2011
Messages
172
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,776
Hi,
I am planning to implement the digital filters with MSP430 microcontroller and want to use this fir_filter function but I don't exactly know how it works

Code:
int16_t ir_filter(int16_t sample)  
{     static int16_t buf[32];    
static int offset = 0;   
int32_t z;   
int i;   
buf[offset] = sample;   
z = mul16(coeffs[11], buf[(offset - 11) & 0x1F]);   
for (i = 0;  i < 11;  i++)       
z += mul16(coeffs[i], buf[(offset - i) & 0x1F] + buf[(offset - 22 + i) & 0x1F]);   
offset = (offset + 1) & 0x1F;   
return  z >> 15; 
}

Here the static const int16_t coeffs[12] = {contains 12 cofficient values };
Can someo explain me
1)In z = mul16(coeffs[11], buf[(offset - 11) & 0x1F]); if offset=0; what the value of (offset - 11) & 0x1F will be ?
2)For first iteration(if i=0) what the value of this will be (offset - 22 + i) & 0x1F]?
3)Isn't the (offset - i)='zero' in buf[(offset - i) & 0x1F] for every iteration?
Thanks.
 

Hello!

The post is old, but since there is no reply...
Judging by your questions, I guess you didn't write this code. Why not writing your own code?
If you can't do it, then read some documentation, some books
Here is a good one:
Digital processing of signals
By Maurice Bellanger

Dora.

NB: I can't solve this problem. Negative index has no meaning.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…