DSPRelated.com
Forums

fir function for ADSP 21161N EZ-Kit

Started by datu...@gmail.com April 8, 2008
Hi all,
I try to use fir function incorporate with C based Talk-through example provided by Visual DSP++ software. In the interrupt server routine Process_Samples( int sig_int), it receives sample and transmit sample.

If I want to use built-in fir function:
float *fir (const float dm input[],
float dm output[],
const float pm coeffs[],
float dm state[],
int samples,
int taps);

it seems based on processing batch of sample all together. Can I use this to only process one sample each time to fit into C based Talk-through example? for example I use this way

float input, output;
float pm coeffs[10];
float state[TAPS+1];
......
fir (input, output, coeffs, state, 1, TAPS);
......

So I define the sample length as 1. Can I use this function in this way, or I must buffer samples first? I know some people in this forum has done this before. So any suggestions will be appreciated.

Many thank

Datu
On Tue, 8 Apr 2008 d...@gmail.com wrote:

> Hi all,
> I try to use fir function incorporate with C based Talk-through example provided by Visual DSP++ software. In the interrupt server routine Process_Samples( int sig_int), it receives sample and transmit sample.
>
> If I want to use built-in fir function:
> float *fir (const float dm input[],
> float dm output[],
> const float pm coeffs[],
> float dm state[],
> int samples,
> int taps);
>
> it seems based on processing batch of sample all together. Can I use this to only process one sample each time to fit into C based Talk-through example? for example I use this way
>
> float input, output;
> float pm coeffs[10];
> float state[TAPS+1];
> ......
> fir (input, output, coeffs, state, 1, TAPS);
> ......
>
> So I define the sample length as 1. Can I use this function in this
>way, or I must buffer samples first? I know some people in this forum has
>done this before. So any suggestions will be appreciated.

I have not used that function, but I suspect you will need to hold the
input and coefficient buffers which are of the same lenghth as TAPS. You
can output one sample at a time, and change your input one sample at a
time though. It's probably not as efficient as doing a batch of data, but
you will have less delay.

You might want to see if there is any further documentation on the
function and read up on all the details.

Patience, persistence, truth,
Dr. mike
Hi AK,

Many thanks, Yes I have researched the documents and manual in

"VisualDSP++ 4.0 C/C++ Compiler and Library Manual for SHARC Processors"
There are two sections with different fir( ) implementations

In Section of "DSP Library for ADSP-2106x and ADSP-21020 Processors"
the fir( ) is one sample based as you mentioned below.

In Section of "DSP Library for ADSP-2116x/2126x/2136x Processors"
the fir( ) is batch samples based as in my first post.

Because I use ADSP-21161N EZ-kit, so I think I should use the batched one
since it is defined for my processor. When I have time I will setup lab to
test it and report back.

Regards

Datu
On 09/04/2008, Krieger,A.W. wrote:
>
> Hello,
>
> it seems there are more than just one version of the various filter
> functions, depending on which header file you include. From the online
> help, I notice that there is Filter.H and Filter*s*.H, with two different
> fir() functions. I get the impression you want the latter one, which
> processes one input signal sample at a time; see the excerpt below. All the
> best.
>
> AK
> finite impulse response (FIR) filter
>
> Synopsis
>
> #include float fir (float sample,
>
> const float pm coeffs[],
>
> float dm state[],
>
> int taps);
>
> Description
>
> The fir function implements a finite impulse response (FIR) filter defined
> by the coefficients and delay line that are supplied in the call of fir.
> The function produces the filtered response of its input data. This FIR
> filter is structured as a sum of products. The characteristics of the
> filter (passband, stop band, etc.) are dependent on the coefficient values
> and the number of taps supplied by the calling program.
>
> The floating-point input to the filter is sample. The integer tapsindicates the length of the
> filter, which is also the length of the array coeffs. The coeffs array
> holds one FIR filter coefficient per element. The coefficients should be
> stored in reverse order with coeffs[0] containing the last (taps-1)coefficient and
> coeffs[taps-1] containing the first coefficient. The coeffs array must be
> located in program memory data space so that the single-cycle dual-memory
> fetch of the processor can be used.
>
> The state array contains a pointer to the delay line as its first element,
> followed by the delay line values. The length of the state array is
> therefore one greater than the number of taps. Each filter has its own
> state array, which should not be modified by the calling program, only by
> the fir function. The state array should be initialized to zeros before
> the fir function is called for the first time.
>
> Error Conditions
>
> The fir function does not return an error condition.
>
> Example
>
> #include #define TAPS 10
>
> float y;
>
> float pm coeffs[TAPS]; /* coeffs array must be initialized */
>
> /* and in PM memory */
>
> float state[TAPS+1];
>
> int i;
>
> for (i = 0; i < TAPS+1; i++)
>
> state[i] = 0; /* initialize state array */
>
> y = fir (0.775, coeffs, state, TAPS);
>
> /* y holds the filtered output */
> ------------------------------
> *From:* a... [mailto:a...] *On Behalf Of *Mike
> Rosing
> *Sent:* April 8, 2008 8:28 AM
> *To:* d...@gmail.com
> *Cc:* a...
> *Subject:* Re: [adsp] fir function for ADSP 21161N EZ-Kit
>
> On Tue, 8 Apr 2008 d...@gmail.com wrote:
>
> > Hi all,
> > I try to use fir function incorporate with C based Talk-through example
> provided by Visual DSP++ software. In the interrupt server routine
> Process_Samples( int sig_int), it receives sample and transmit sample.
> >
> > If I want to use built-in fir function:
> > float *fir (const float dm input[],
> > float dm output[],
> > const float pm coeffs[],
> > float dm state[],
> > int samples,
> > int taps);
> >
> > it seems based on processing batch of sample all together. Can I use
> this to only process one sample each time to fit into C based Talk-through
> example? for example I use this way
> >
> > float input, output;
> > float pm coeffs[10];
> > float state[TAPS+1];
> > ......
> > fir (input, output, coeffs, state, 1, TAPS);
> > ......
> >
> > So I define the sample length as 1. Can I use this function in this
> >way, or I must buffer samples first? I know some people in this forum has
> >done this before. So any suggestions will be appreciated.
>
> I have not used that function, but I suspect you will need to hold the
> input and coefficient buffers which are of the same lenghth as TAPS. You
> can output one sample at a time, and change your input one sample at a
> time though. It's probably not as efficient as doing a batch of data, but
> you will have less delay.
>
> You might want to see if there is any further documentation on the
> function and read up on all the details.
>
> Patience, persistence, truth,
> Dr. mike
Hi Alex, Thanks

Just report back to group, I have set up lab and tested both fir()
functions. They all work for single sample based C -talk through example on
ADSP-21161N EZ-KIT board. For batch processing version fir (), what I did is
just defining array with 1 length for example inputsam[1] and outputsam[1].
and only process inputsam[0]. I test signal on oscilloscope and it works.

Regards

datu
On 09/04/2008, Krieger,A.W. wrote:
>
> Hello again,
>
> I also have a ADSP-21161 Ez Kit, and VDSP++ 4.0, and I found that
> information in the on-line help, not in the printed literature.
> Furthermore, although I haven't actually thought it necessary to check in
> detail, I would expect that both fir() functions should work OK with the
> 21161, being upward compatible with the earlier 2106x floating point DSP.
> Good luck.
>
> Alex
>
> ------------------------------
> *From:* Datu [mailto:d...@googlemail.com]
> *Sent:* Wed 4/9/2008 5:08 AM
> *To:* Krieger,A.W.
> *Cc:* Mike Rosing; d...@gmail.com; a...
> *Subject:* Re: [adsp] fir function for ADSP 21161N EZ-Kit
>
> Hi AK,
>
> Many thanks, Yes I have researched the documents and manual in
>
> "VisualDSP++ 4.0 C/C++ Compiler and Library Manual for SHARC Processors"
> There are two sections with different fir( ) implementations
>
> In Section of "DSP Library for ADSP-2106x and ADSP-21020 Processors"
> the fir( ) is one sample based as you mentioned below.
>
> In Section of "DSP Library for ADSP-2116x/2126x/2136x Processors"
> the fir( ) is batch samples based as in my first post.
>
> Because I use ADSP-21161N EZ-kit, so I think I should use the batched one
> since it is defined for my processor. When I have time I will setup lab to
> test it and report back.
>
> Regards
>
> Datu
> On 09/04/2008, Krieger,A.W. wrote:
> >
> > Hello,
> >
> > it seems there are more than just one version of the various filter
> > functions, depending on which header file you include. From the online
> > help, I notice that there is Filter.H and Filter*s*.H, with two
> > different fir() functions. I get the impression you want the latter one,
> > which processes one input signal sample at a time; see the excerpt
> > below. All the best.
> >
> > AK
> >
> >
> > finite impulse response (FIR) filter
> >
> > Synopsis
> >
> > #include
> >
> > float fir (float sample,
> >
> > const float pm coeffs[],
> >
> > float dm state[],
> >
> > int taps);
> >
> > Description
> >
> > The fir function implements a finite impulse response (FIR) filterdefined by the coefficients and delay line that are supplied in the call of
> > fir. The function produces the filtered response of its input data. This
> > FIR filter is structured as a sum of products. The characteristics of
> > the filter (passband, stop band, etc.) are dependent on the coefficient
> > values and the number of taps supplied by the calling program.
> >
> > The floating-point input to the filter is sample. The integer tapsindicates the length of the
> > filter, which is also the length of the array coeffs. The coeffs array
> > holds one FIR filter coefficient per element. The coefficients should be
> > stored in reverse order with coeffs[0] containing the last (taps-1)coefficient and
> > coeffs[taps-1] containing the first coefficient. The coeffs array must
> > be located in program memory data space so that the single-cycle dual-memory
> > fetch of the processor can be used.
> >
> > The state array contains a pointer to the delay line as its first
> > element, followed by the delay line values. The length of the statearray is therefore one greater than the number of taps. Each
> > filter has its own state array, which should not be modified by the
> > calling program, only by the fir function. The state array should be
> > initialized to zeros before the fir function is called for the first
> > time.
> >
> > Error Conditions
> >
> > The fir function does not return an error condition.
> >
> > Example
> >
> > #include
> >
> > #define TAPS 10
> >
> > float y;
> >
> > float pm coeffs[TAPS]; /* coeffs array must be initialized */
> >
> > /* and in PM memory */
> >
> > float state[TAPS+1];
> >
> > int i;
> >
> > for (i = 0; i < TAPS+1; i++)
> >
> > state[i] = 0; /* initialize state array */
> >
> > y = fir (0.775, coeffs, state, TAPS);
> >
> > /* y holds the filtered output */
> >
> >
> >
> >
> > ------------------------------
> > *From:* a... [mailto:a...] *On Behalf Of
> > *Mike Rosing
> > *Sent:* April 8, 2008 8:28 AM
> > *To:* d...@gmail.com
> > *Cc:* a...
> > *Subject:* Re: [adsp] fir function for ADSP 21161N EZ-Kit
> >
> > On Tue, 8 Apr 2008 d...@gmail.com wrote:
> >
> > > Hi all,
> > > I try to use fir function incorporate with C based Talk-through
> > example provided by Visual DSP++ software. In the interrupt server routine
> > Process_Samples( int sig_int), it receives sample and transmit sample.
> > >
> > > If I want to use built-in fir function:
> > > float *fir (const float dm input[],
> > > float dm output[],
> > > const float pm coeffs[],
> > > float dm state[],
> > > int samples,
> > > int taps);
> > >
> > > it seems based on processing batch of sample all together. Can I use
> > this to only process one sample each time to fit into C based Talk-through
> > example? for example I use this way
> > >
> > > float input, output;
> > > float pm coeffs[10];
> > > float state[TAPS+1];
> > > ......
> > > fir (input, output, coeffs, state, 1, TAPS);
> > > ......
> > >
> > > So I define the sample length as 1. Can I use this function in this
> > >way, or I must buffer samples first? I know some people in this forum
> > has
> > >done this before. So any suggestions will be appreciated.
> >
> > I have not used that function, but I suspect you will need to hold the
> > input and coefficient buffers which are of the same lenghth as TAPS. You
> > can output one sample at a time, and change your input one sample at a
> > time though. It's probably not as efficient as doing a batch of data,
> > but
> > you will have less delay.
> >
> > You might want to see if there is any further documentation on the
> > function and read up on all the details.
> >
> > Patience, persistence, truth,
> > Dr. mike
> >
> >
> >
>
Thanks Gary,

I just begin to learn dsp and programming with ADSP-21161N ez-kit
platform. So I don't know much about assemble for SHARC. I knew a
little bit C. so I think if I program in c at moment the compiler will
take care of optimisation etc.

As my previous email, I now tested fir() function is working for
single sample (ADC interrupt driven ). I will try to do next step
using buffer. So far my work is based on compiler built in example
code C-talk through. and the C-talk through received sample by using
interrupt. So I don't know how to receive sample without using
interrupt. The code example is documented in:
http://www.analog.com/UploadedFiles/Application_Notes/504555030370765719AN_AD1836_21161.pdf
this application note as far as I understand.

If you mean I can still use ADC interrupt driven to receive audio
samples ,but keep them in buffer and batch process them. I will try
that and see I can update input sample buffer by using ring buffer
technique in C.

Thanks.
datu
On 10/04/2008, gary_r_moore wrote:
> --- In a..., daturaster@... wrote:
> >
> > Hi all,
> > I try to use fir function incorporate with C based Talk-through
> example provided by Visual DSP++ software. In the interrupt server
> routine Process_Samples( int sig_int), it receives sample and
> transmit sample.
> >
> > If I want to use built-in fir function:
> > float *fir (const float dm input[],
> > float dm output[],
> > const float pm coeffs[],
> > float dm state[],
> > int samples,
> > int taps);
> >
> > it seems based on processing batch of sample all together. Can I
> use this to only process one sample each time to fit into C based
> Talk-through example? for example I use this way
> >
> > float input, output;
> > float pm coeffs[10];
> > float state[TAPS+1];
> > ......
> > fir (input, output, coeffs, state, 1, TAPS);
> > ......
> >
> > So I define the sample length as 1. Can I use this function in this
> way, or I must buffer samples first? I know some people in this forum
> has done this before. So any suggestions will be appreciated.
> >
> > Many thank
> >
> > Datu
> > Hi Datu,
>
> If you process the data one sample at a time it will be extremely
> inefficient due primarily to the interrupt dispatcher overhead. If
> you must do it use the super-fast dispatcher "interrupts" - or write
> in assembler which is easy on a SHARC.
>
> But why do you want to do one sample at a time? the only valid reason
> is to minimise latency - but is it really that important? It will be
> MUCH more efficient to use chained DMAs and work on alternate buffers
> and do the filtering in blocks. Then if your application requires
> real time output (to a DAC for example) then DMA out the result. The
> only downside is that the output will be delyaed with respect to the
> input by a time equal to the filter length divided by the sample rate.
>
> It's also worth considering doing your fltering in the frequency
> domain using overlap and save FFTs - this is much faster but the
> latency will be longer still as the FFT length needs to be long
> compared to the filter length for best efficiency.
>
> Hope this helps,
> Gary
>