DSPRelated.com
Forums

simple FIR on fixed point ADSP2191

Started by Jacek P December 12, 2003
Hi,

I have a problem with implementing filter on my Ez-kit. There is AD1885
codec. I don't know, how to convert samples form codec to filtering them. I
have a function:

void process_samples(void)
{
    //filtering algorithm
}

and filter coeffincients in array:

float coff[SIZE]

which is called from interrupt routine. I have to mulpitply samples (16 bit
from codec)  by filter coefficients (float type) but I don't know how to
convert input sample.
I had similar problem with floating point ADSP21160 but found soulution. 16
bit fixed foint samples were shifted 16 bits and scaled. After it there were
conversion to float type. How to do it on fixed point 2191? I know that this
is not best solution of filtering but I would like to know, how to do it.

I will be gratefull for help

Jacek


Jacek P wrote:
> Hi, > > I have a problem with implementing filter on my Ez-kit. There is AD1885 > codec. I don't know, how to convert samples form codec to filtering them. I > have a function: > > void process_samples(void) > { > //filtering algorithm > } > > and filter coeffincients in array: > > float coff[SIZE] > > which is called from interrupt routine. I have to mulpitply samples (16 bit > from codec) by filter coefficients (float type) but I don't know how to > convert input sample.
Since you're working with a fixed-point DSP, you'd be much better off converting your coefficients to fixed-point than converting your input samples to floating-point. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (703) 779-7770 The secret to enjoying your job is to have a hobby that's even worse - Calvin's Dad
> Since you're working with a fixed-point DSP, you'd be much better off > converting your coefficients to fixed-point than converting your input > samples to floating-point. >
Thanks for your answer. I based on talk through example. In this example int interrupt I tryed to copy samples from codec to variable int Left for example. Then I called c function Process_Samples. I obtained filter coefficient from Matlab and I exported to signed16bit format. I have two arrays. The first one is int array[ARRAY_SIZE] of filter coefficient for example {-10,-20,0,20,0,-20,-10}and the second is int buffer[SIZE_BUFFER] of signal samples. I thought that I did everything correctly but I was hearing only noise. Could you suggest me how to filter it in c function or which data types should I use? Should I convert data from codec? I tryed to find example how to do it but I couldn't. regards Jacek
Jacek P wrote:
 > Jim wrote:
>>Since you're working with a fixed-point DSP, you'd be much better off >>converting your coefficients to fixed-point than converting your input >>samples to floating-point. >>
...
> Could you suggest me how to filter it in c function or which data types > should I use?
Jacek, did you even read Jim's answer? I think everything you need to do is all there ...
> Jacek, did you even read Jim's answer? I think everything you need to do > is all there ...
Yes of cource.I tryed to implement filter with fixed point coefficient. I based on Echo_Cancel example. This is my filtering function: int samples[15]; int B[15] = {0xFE25,0x01B6,0x0415,0x079C,0x0BA9,0x0F6F, 0x121d,0x1315,0x121D,0x0F6F,0x0BA9,0x079C, 0x0415,0x01B6,0xFE25, }; int ActSInd=BL-1; int coff_ind=0; int i; int out; void Process_Samples(void) { /*the first par*/ i=ActSInd; out=0; samples[i]=Left_Channel_In; for (coff_ind=0;coff_ind<BL;coff_ind++){ out+=B[coff_ind]*samples[i++]; if (i>(BL-1)) i=0; } if ((--ActSInd)<0) ActSInd=BL-1; Left_Channel_Out = out; Right_Channel_Out = out; /*the second part*/ /* Left_Channel_Out=Left_Channel_In; Right_Channel_Out=Right_Channel_In;*/ } When I copy input samples to output samples (only second part working) everything is OK but when only the second part works there is only noise. I can't find reeason of this. Instead of c function tryed to call much simpler assembly function from example and everything was OK. This is source of assemblu function: fir2: cntr = n-1; mr = 0, mx0 = dm(i2,m1), my0 = pm(i7,m5); do sop2 until ce; sop2: mr = mr + mx0 * my0 (ss), mx0 = dm(i2,m1), my0 = pm(i7,m5); mr = mr + mx0 * my0(rnd); sat mr; rts;I will be gratefull for any suggestions. Compiler produce code not so effective and in there are not SAT instruction in assembly listing of function ProcessSample. I will be gratefull for any suggestion. I tryed to find some example of filtering samples from codec in C but I couldn't find. I will be gratefull for any suggestion. regards Jacek
Jacek P wrote:
>>Jacek, did you even read Jim's answer? I think everything you need to do >>is all there ... > > > Yes of cource.I tryed to implement filter with fixed point coefficient. I > based on Echo_Cancel example. This is my filtering function:
[deletia]
> I will be gratefull for any suggestion.
Hi Jacek, I haven't worked with an ADI fixed-point device in years, and I never worked with them in C. Most of the people on this newsgroup who currently use ADI fixed-point DSPs do not use C. There are two reasons for this: 1) It's easy to write assembly for these devices. 2) It's hard to make C work well on these devices. With those disclaimers out of the way, I can provide you with a few suggestions. Look into the documentaiton that comes with the compiler - especially look for an ADI-specific C type called "fract". In the old days, ADI added the fract type to their implementation of the C language. I don't know if they still support that, but I'm guessing they do. It's really the ONLY way to get half-decent performance out of those devices using a C compiler. But you'd be much better off if you learned to program this beast in assembly instead of using C. If you look into the interface between C and assembly, you can write C-callable assembly functions. That way you can do the management stuff in C, and the sample-crunching in assembly. You'll find that you can write 80% of the code in C, and 20% in assembly, but 80% of the CPU-time will be spent executing the assembly code. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (703) 779-7770 The secret to enjoying your job is to have a hobby that's even worse - Calvin's Dad
Jim Thomas <jthomas@bittware.com> wrote in
news:vtrneoi0h9ced8@corp.supernews.com: 

> Jacek P wrote: >>>Jacek, did you even read Jim's answer? I think everything you need to >>>do is all there ... >> >> >> Yes of cource.I tryed to implement filter with fixed point >> coefficient. I based on Echo_Cancel example. This is my filtering >> function: > > [deletia] > >> I will be gratefull for any suggestion. > > Hi Jacek, > > I haven't worked with an ADI fixed-point device in years, and I never > worked with them in C. Most of the people on this newsgroup who > currently use ADI fixed-point DSPs do not use C. There are two > reasons for this: 1) It's easy to write assembly for these devices. 2) > It's hard to make C work well on these devices. > > With those disclaimers out of the way, I can provide you with a few > suggestions. Look into the documentaiton that comes with the compiler > - especially look for an ADI-specific C type called "fract". In the > old days, ADI added the fract type to their implementation of the C > language. I don't know if they still support that, but I'm guessing > they do. It's really the ONLY way to get half-decent performance out > of those devices using a C compiler. > > But you'd be much better off if you learned to program this beast in > assembly instead of using C. If you look into the interface between C > and assembly, you can write C-callable assembly functions. That way > you can do the management stuff in C, and the sample-crunching in > assembly. You'll find that you can write 80% of the code in C, and 20% > in assembly, but 80% of the CPU-time will be spent executing the > assembly code. > >
As someone who has written literally tons of 21xx code including the 2191 (I kill a lot of trees), I would strongly echo most of Jim's comments with the exception that I would never use C with the 218x or 219x DSPs. C is certainly reasonable with the Sharc or Blackfin DSPs, but the 218x and 219x parts are very C unfriendly. You really need lots of pointers (index registers) and a more orthogonal instruction set than these processors have available. The good news is that the assembly language is readable and easy to learn. About the only thing I miss are C Switch statements. I use jump tables instead. -- Al Clark Danville Signal Processing, Inc. -------------------------------------------------------------------- Purveyors of Fine DSP Hardware and other Cool Stuff Available at http://www.danvillesignal.com
Hi,

Thank you for suggestion. I founded solution of my problem. There are some
functions which allowed work with fractional representation. Those function
for 2191 processor are declared in "ETSI_fract_arith.h" . I run program with
those function step by step there were the same results.

Jacek