Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

filter realization help

maduba12001

Banned
Joined
May 12, 2020
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
I need a help with filter realization. I dont understand how this works. This is a multiply and accumulate filter, I dont understand why cof[0] constant is multiplied, here is the code cof is the filter coefficients and sample is the samples. Any help with this very appreciated. Thank you

Code:
long long mac(int len, int *sample, int *cof, int item)

{

   int i, io;

   static long long y;


   io = 0;

   y = 0;

   item /= 4;

   for ( i = 0; i < len; i++ )

      {

      y += (long long)sample[io] * (long long)cof[0];

      cof +=item;

      io++;

      if ( io >= len )

         io = 0;

      }

   return y;

}
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,471
Helped
3,947
Reputation
7,892
Reaction score
3,816
Trophy points
113
Activity points
115,832
Hi,

it seems to be a standard FIR filter function of varaible length.

Some questions arise:
* Do you know how a FIR filter works?
* Do you know how to find the filter coefficients?
* Where is the code from?
* Isn´t there a documentation for the code?

I dont understand why cof[0] constant is multiplied
Because this is how a FIR filter works.

But the index should move as well as the index for the sample.

Klaus

added:
Now I realize it is some kind of special FIR filter. It seems to work interleaved somehow. So the above 4 questions are still valid.
..
A again I reviewed the code. I don´t think it is correct. "i" and "io" have the same value, thus "io" is redundant. Without further informations I think sample[] and cof[] should have the same index.
 

maduba12001

Banned
Joined
May 12, 2020
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Hi ,

Thank you for the reply. Very much appreciated.

Some questions arise:
* Do you know how a FIR filter works?
* Do you know how to find the filter coefficients?
* Where is the code from?
* Isn´t there a documentation for the code?
I understand the FIR filter works. Also I understand how to find the filter coefficients.I am working on a university project so I found this code through friends. There is no documentation for the code. Yes thats right index should also move for the coefficients but I dont understand why cof[0] just multiplied. Is it not going to be just a constant multiplication everytime it go through the loop.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,471
Helped
3,947
Reputation
7,892
Reaction score
3,816
Trophy points
113
Activity points
115,832
Hi,

code without documentation, maybe somewhere found in the internet....

My recommendation: throw it away .. and write the couple lines of code on your own -- since you already know how it should work.

Klaus
 

_Eduardo_

Full Member level 5
Joined
Aug 31, 2009
Messages
290
Helped
118
Reputation
236
Reaction score
102
Trophy points
1,323
Location
Argentina
Activity points
2,693
... but I dont understand why cof[0] just multiplied. Is it not going to be just a constant multiplication everytime it go through the loop.
'cof[0]' is not a constant, 'cof' is incremented by 'item' each iteration.

(long)cof[0] equiv *(long*)cof
 

maduba12001

Banned
Joined
May 12, 2020
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Digital Filter help need to understand

I need a help to understand this filter. I understand how the FIR filter works. But I dont understand why mac function called twice. Any help with this very appreciated. Thank you

Code:
struct __attribute__ ((aligned (32)))
{ int *samplebuf[chan];
  int *fcs[chan];                           // Filter Coefficient Start
  int  len[chan];
  int  offset[chan];
  int  dec[chan];
  int  decount[chan];
  int  item[chan];                             // Skip coefficient Items 
}f;



int get_sa(int chan)
{
   static long long y;                                           
   int  l1;
   int *sample;
   int *cof;
   int  len;
   int  item,item4;
   int *samplebuf;

   samplebuf = f.samplebuf[chan];
   if ( f.dec[chan] == 0 )                                   
      return samplebuf[0];                                     
   len = f.len[chan];
   item = f.item[chan];
   item4 = item << 2;
   cof = f.fcs[chan];
   sample = samplebuf + f.Offset[chan];
   l1 = len - f.Offset[chan];
   y = mac(l1,sample,cof,item);   //multiply and accumulate filter
   cof += (l1 * item);
   sample = samplebuf;
   l1 = len - l1;
   y += mac(l1,sample,cof,item4);
   y *= item;
   y >>= 32;
   return (int)y;

}
  mac function shown below, 


long long mac(int len, int *sample, int *cof, int item) 
 {
   int i, io;

   static long long y;


   io = 0;

   y = 0;

   item /= 4;

   for ( i = 0; i < len; i++ )

      {

      y += (long long)sample[io] * (long long)cof[0];

      cof +=item;

      io++;

      if ( io >= len )

         io = 0;

      }

   return y;

}
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,471
Helped
3,947
Reputation
7,892
Reaction score
3,816
Trophy points
113
Activity points
115,832
Hi,

you cross post the same question on several other forums.
All ask for more information: where is it from, where is the documentation, what you want to do with it, what are the input data....

But almost no information from your side.

How can we help?

Klaus
 

maduba12001

Banned
Joined
May 12, 2020
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Hi,

Thank you for the reply. This is a decimation filter
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top