Tuesday, September 7, 2010

Question about filtering program

The following question came to me in e-mail.

"With regards to the FIR filter class that we are writing: Are we expected to design the class so that it polls a real-time value and produces a filtered signal "On the fly", or is it sufficient for the class to accept a pre-made input signal in the form of a large buffer and return the filtered form of that signal in another buffer?"

I want to respond to several points raised in the question above.
  • There is no requirement to write a class for this assignment.  You can you whatever data structure you like.  However, the assignment was to write two functions: one that implements convolution using a shift buffer and one that implements convolution using a circularly indexed buffer.
  • As far as what gets passed into and out of the function, that depends on the data structure you use.  For example, if you use a class structure and the class has member arrays for the filter coefficients and data buffer, then you do not need to pass these into the member functions that perform convolution.  On the other hand, if you are using straight C, then you may need to pass the filter coefficient and data arrays into the function.  Other alternatives are also possible.  Examples are given below.
=========================
// C++ class example
class fir {
private:
   float *h; // coefficients
   float *b; // buffer
public:
   void conv1(float *inbuff, float *outbuff, int len);
   void conv2(float *iobuff, int len);
};
// The conv1 function passes an array of values in and
// receives an array of values out of the function.
// The length of the input and output arrays is "len".
// The conv2 function passes a single array.  The values
// on the way in are the inputs and the values coming
// out are the outputs with the inputs being overwritten.

==========================
// C example
float *h; // coefficients
float *b; // coefficients

void conv1(float* inbuff, float *outbuff, int len, float *h, float *b, int num);

// In this example, the filter coefficients and the
// data buffer have to be passed into the function.
// The length of these two arrays is "num".

==========================
// As a third example, you could use a C structure
// to hold all the information associated with a filter:
// the filter coefficients, the buffer, and the length.
// Then the structure could be passed into the function
// as a single entity instead of passing in all the elements
// separately.

2 comments:

  1. Dr. Gunther,

    The assignment description explicitly states that we are to write a class. Is this no longer a requirement then?

    ReplyDelete
  2. No need to write a class. Writing two functions is sufficient. Of course you still have to write the code for evaluating the frequency response.

    ReplyDelete