Are there any multichannel talkthrough bandpass fir example code floating around for sharc 21489? I cant seem to find any.

I have no DSP experience, but if someone could walk me through merging/changing existing code that would be helpful too.

Are there any multichannel talkthrough bandpass fir example code floating around for sharc 21489? I cant seem to find any.

I have no DSP experience, but if someone could walk me through merging/changing existing code that would be helpful too.

Hi,

I am not sure if we have such example code already available but may be could comment better if you could please elaborate more about your exact requirements such as :

1) Number of channels

2) A simple signal chain diagram showing various input, output, and processing blocks you require using the EZ-Kit?

Thanks,

Mitesh

Hi,

Unfortunately, I could not find the specific example for FIR. But, I do have a code written for ADSP-21469 (Talk through code is similar to ADSP-21489) where the VDSP++ IIR library filter function is used to perform band pass filtering on the incoming data. You can similarly make use of the FIR library function for multiple channels processing them one after another. I shall try to help you in case you have any specific questions when implementing such an FIR implementation on your own.

Thanks,

Mitesh

Hi,

Not sure if I can comment much here as I am not sure if the issue is because of the FIR library code or with the filter design. Could you please check if the same filter coefficients work well when using another tool (say MATLAB)? If yes, may be you could try to narrow down the problem to the FIR filter code by providing a known input buffer and comparing the output buffer with the MATLAB output.

Thanks,

Mitesh

The roll-off happens with any coefficients I use, which are all from MATLAB's fdatool. Heres a graph showing the roll-off.

Havent found a solution to compensate for the roll-off yet. Any ideas? As for the attenuation in passband, I "fixed" it by multiplying the output by 1.59.Also kind of annoying, if I apply a <=0.4Vpp sinusoid with a frequency in the passband, it outputs a 0.4Vpp sinusoid (also subject to the higher frequency rolloff). What would cause this?

Side question, is there any easy way to find a variable's value when debugging?Hi,

Thanks for the update. But, I am not still clear if you find this problem only with the SHARC FIR library or with MATLAB as well? I think it would be helpful to know if the problem has anything specific to do with the SHARC library code.

To view the local variables, you can go to "View->Debug Windows->Locals". For global variables, you can browse through the VDSP memory window (Memory->Two Column).

Regards,

Mitesh

fdatool: http://i.imgur.com/g8o9K.jpg

fs=192000;t = 0 : ( 1 / fs) : 1000 / fs; % fs = sampling frequency

A = sin(2 * pi * f .* t); % f is sine frequency

plot(t,A);

hold on;

y=filter(Hd,A);

plot(t,y,'red');

Unless I'm doing something wrong, that seems to be correct.

Scope reads: http://i.imgur.com/UgVT0.jpg

(note that the output is being multiplied by 1.59 to fix attenuation problem).void Block_Float_To_Fixed( int * Fixed_Out, float * Float_In_L, float * Float_In_R ) { int i; for (i=0;i<AUDIO_BLOCK_SIZE;i++) { Fixed_Out[2*i] = 1.59 * ((int) (1073741824.0*Float_In_L[i])); Fixed_Out[2*i+1] = 1.59 * ((int) (1073741824.0*Float_In_R[i])); } }

Hi Mitesh!

Thank you very much for attaching this example. I loaded on my ADSP-21469 EZ Kit and I've been studying the code to understand the operation. I just don't know why the sound output is mono. I have stereo input and output, however it is taking the audio from IN-1-R only and outputting at both OUT-1-L and OUT-1-R. Any ideas? That could be the code or the EZ Kit jumper config perhaps?

Thanks!

Hi,

Thanks. I understand your concerns.Sorry, I forgot to mention this earlier. Please note that the code I attached is just for reference and you are correct that for simplicity, it just outputs the same thing to both the left and the right channels. In actual system, you might need to explicitly process them individually.

Hope this helps. Please let me know if you have any further specific questions.

Thanks,

Mitesh

Hi Mitesh,

This sample code has caught my interest recently, and I was wondering what tool was used to calculate the coefficients, and what the filter parameters are (center frequencies, width, etc.).

Also, I would appreciate any info on the .flt file format that is used to store the coefficients.

Thanks!

Hi,

I wrote this code long back just for framework testing purpose (not for actual equalizer function) and I only remember that I used GNU Octave to generate the filter coefficients. Sorry, but I can' t recall the filter parameters I used as I didn't pay much importance to them. Please note that this code or filter coefficients should not be used for any final application requiring equalizer function and should be used only to understand the framework details.

Regarding the format of the .flt file, they are nothing but filter coefficients arranged in a particular format as required by the IIR library function. They have comments embedded for better explanation:

0.21281392E-03 /* overall gain */, -.19955791E+01 /* section 1 coefficient B1 */, 0.10000000E+01 /* section 1 coefficient B2 */, 0.19958063E+01 /* section 1 coefficient -A1*/, -.99582614E+00 /* section 1 coefficient -A2*/, -.19993272E+01 /* section 2 coefficient B1 */, 0.10000000E+01 /* section 2 coefficient B2 */, 0.19973976E+01 /* section 2 coefficient -A1*/, -.99749984E+00 /* section 2 coefficient -A2*/, -.19995940E+01 /* section 3 coefficient B1 */, 0.10000000E+01 /* section 3 coefficient B2 */, 0.19990815E+01 /* section 3 coefficient -A1*/, -.99924708E+00 /* section 3 coefficient -A2*/ Hope this helps.

Thanks,

Mitesh

Hi Mitesh, thanks for your reply.

Yes, I've been putting together my own filter bank, so I wanted to play around with this one and see how it was made. If I do use this equalizer code, it would be with my own filter coefficients, which is why I was asking for some info.

I also use GNU Octave for filter design. What made you decide to use the .flt file format? Also, how did you arrive at that overall gain value?

Ah, thank you! That is very helpful, actually.

I have one more question - so, is the overall gain really just the B0 value you got from the filter design function? Or did you have to divide b1 and b2 by b0? (as per that first equation for H(z))?

Or is the overall gain the H(z) adjustment as shown on the bottom? (Which, if there is only one section, would be just b0 then).

Hi there,

I'm using Matlab's FDATOOL to design the filter, but I sincerely don't know how to translate its output... I designed a simple IIR butterworth bandpass to try to "glue" it into the Equalizer talkthrough code. I am having a hard time trying to

**identify which one is A0, A1, A2 and B0, B1, B2. Also, which one would be the overall gain? Do I have to negate any of these values?**I'm sorry if this is a very obvious question, I'm new to DSP and I would sincerely appreciate if you could help me figure it out.Here is the output:

% Generated by MATLAB(R) 7.12 and the Signal Processing Toolbox 6.15.

%

% Generated on: 14-May-2012 15:24:13

%

% Coefficient Format: Decimal

% Discrete-Time IIR Filter (real)

% -------------------------------

% Filter Structure : Direct-Form II, Second-Order Sections

% Number of Sections : 3

% Stable : Yes

% Linear Phase : No

SOS matrix:

1 0 -1 1 -1.9846465579564758 0.98522638410526819

1 0 -1 1 -1.9957712267103305 0.99581744754928514

1 0 -1 1 -1.9809409810160385 0.98110392037554595

Scale Values:

0.0094925636095889564

0.0094925636095889564

0.0094480398122270791

And this is what I must translate into:

0.21281392E-03 /* overall gain */, -.19955791E+01 /* section 1 coefficient B1 */, 0.10000000E+01 /* section 1 coefficient B2 */, 0.19958063E+01 /* section 1 coefficient -A1*/, -.99582614E+00 /* section 1 coefficient -A2*/, -.19993272E+01 /* section 2 coefficient B1 */, 0.10000000E+01 /* section 2 coefficient B2 */, 0.19973976E+01 /* section 2 coefficient -A1*/, -.99749984E+00 /* section 2 coefficient -A2*/, -.19995940E+01 /* section 3 coefficient B1 */, 0.10000000E+01 /* section 3 coefficient B2 */, 0.19990815E+01 /* section 3 coefficient -A1*/, -.99924708E+00 /* section 3 coefficient -A2*/ Thanks a lot!

Hi Mitesh,

I'm sorry to "flood" here with messages but I forgot to say that I installed the GNU Octave and tried to follow the script provided in the IIR accelerator example but Octave won't recognize the command "butter".

octave:1> N=512;

octave:2> BIQUADS=3;

octave:3> fs=48000;

octave:4> fc=400;

octave:5> fn=fc/fs;

octave:6> [b,a]=butter(2*BIQUADS,fn);

**error: `butter' undefined near line 6 column 7**I am having a hard time trying to generate the coefficients for my filters...

Any help will be highly appreciated!

Hi Nando.One,

I am not too familiar with the output format of the FDATOOL, but following from the guide Mitesh linked me, if you are implementing a filter with only one section, then the B0 coefficient would be the overall gain. You would then need to divide both B1 and B2 by B0 to normalize them for use with the iir_vec function. If there is more than one section, then you would have to follow the formula above to calculate the overall gain with the B0 coefficients of each section.

Also, with GNU Octave, it seems you may not have the signal package installed. The "signal" package includes the "butter" function among others.

Here's the main page of the "signal" package:

http://octave.sourceforge.net/signal/index.html

And here are the details on the included functions (the "butter" function is under IIR Filter Design):

http://octave.sourceforge.net/signal/overview.html

Hope this helps.

Hi SGiav,

Thank you so much for your help.

The filter has 3 sections.

**If I'm not wrong**(unsure), b0 and a0 is 1. Then, dividing b1 and b2 by b0 won't change. The formulawill also result in H(z) * 1 because b0 and a0 are 1 for every section... By the way,

**what would "H(z)" be?**Please accept my apologies if these questions sound foolish, I am new to this matter and I couldn't find other ways to aid my lack of knowledge...Hi Nando.One,

No problems regarding multiple questions. I shall definitely try to help you regarding the same. Your understanding about the coefficient storage looks correct to me. As far as hearing noise is concerned, I am curious to know if we have already checked whether the problem is not somewhere else in the code. So, could you please provide more details about your application with which you see this problem? Do you see this problem on EZ-Kit ? Does the default example code work okay for you? What if you do nothing but just change the coefficients in the working example and check if it works? Is it possible for you to post the simplest code with which you see the problem?

One way to check whether the coefficients storage is okay would be to use a known input buffer and compare the output buffer with the one generated from MATLAB/Octave without using the ADC/DAC part of the code? Do you see any problems there?

Thanks,

Mitesh

Hi Mitesh! Thanks a lot for understanding. I'll try to provide the maximum amount of details here, as I am not an expert and probably I'm missing something basic:

I'm pretty sure that the problem is not somewhere else in the code. Yes, I am using the EZ-Kit (sharc 21469). I am using the Equalizer Talkthrough code that you posted here and it works perfectly fine. I observed that the variables "_EqualBand" control the gain of each EQ band. The bigger the number, the higher the band is attenuated. So here is what I did:

volatile int pm _EqualBand1 = 20;

volatile int pm _EqualBand2 = 20;

volatile int pm _EqualBand3 = 1; //Only band 3 is not attenuated

volatile int pm _EqualBand4 = 20;

volatile int pm _EqualBand5 = 20;

volatile int pm _EqualBand6 = 20;

volatile int pm _EqualBand7 = 20;

volatile int pm _EqualBand8 = 20;

volatile int pm _EqualBand9 = 20;

volatile int pm _EqualBand10 = 20;

Then, I can hear "exclusivelly" band 3. If I set _byPass=1; everything comes back to normal, as well as if I set all _EqualBands to 1. So I assume that the hardware and the software are working fine.

Alright, being able to hear "exclusively" band 3, I thought, "well, if I replace the filter coefficients of this band with a filter that I've designed, I should hear the result of my own filter design". Right?

So I opened FDATOOL to create the "replacement" filter for Band3. My concerns were:

- Keep the filter with 3 sections, so I won't have to change the "NUM_SECTIONS" on the code

- Create a filter with a bandpass frequency that I can hear and say, "yeah, this is obviously my filter working".

- Create an IIR filter so it should work with the iir_vector function already present in the code

So I came up with a Butterworth Bandpass that has -18Db at 120 and 1280Hz and is flat from 240 to 640Hz, as follows:

**The information box says:**- Filter Structure : Direct-Form II, Second-Order Sections
- Number of Sections : 3
- Stable : Yes
- Linear Phase : No
- Design Algorithm : butter
- Scale Norm : no scaling
- Sampling Frequency : N/A (normalized frequency)
- Response : Bandpass
- Specification : Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2

- Number of Multipliers : 9
- Number of Adders : 9
- Number of States : 6
- Multiplications per Input Sample : 9
- Additions per Input Sample : 9

**As for the coefficients:**- Section #1
- Numerator: 1, 0, 1
- Denominator: 1, -1.9846465579564758, 0.98522638410526819
- Gain: 0.0094925636095889564

- Section #2
- Numerator: 1, 0, -1
- Denominator: 1, -1.9957712267103305, 0.99581744754928514
- Gain: 0.0094925636095889564

- Section #3
- Numerator: 1, 0, -1
- Denominator: 1, -1.9809409810160385, 0.98110392037554595
- Gain: 0.0094480398122270791

- Output Gain: 1

Well, I find strange the fact that the numerators are all 1, 0, -1 for all three sections. Anyway,

**I assumed that:**- The "b" values are the numerators and the "a" values are the denominators.

- The "a" values must be negated before being loaded in the coefficients file.

- As the the Gain is the same for the first two sections, and, very close for the third one, I could use the first values as the "overall gain".

So here is how I translated it into the coefficients file:

**coeffs_band3.flt**0.0094925636 /* overall gain (same as section 1 and 2 gains) */, 0 /* section 1 coefficient B1 */, -1 /* section 1 coefficient B2 */, 1.984646558 /* section 1 coefficient -A1*/, -0.985226384 /* section 1 coefficient -A2*/, 0 /* section 2 coefficient B1 */, -1 /* section 2 coefficient B2 */, 1.995771227 /* section 2 coefficient -A1*/, -0.995817448 /* section 2 coefficient -A2*/, 0 /* section 3 coefficient B1 */, -1 /* section 3 coefficient B2 */, 1.980940981 /* section 3 coefficient -A1*/, -0.98110392 /* section 3 coefficient -A2*/ About using MATLAB / Octave to evaluate the filters coefficients, I couldn't do it as I am not familiar with these programs. I worked exclusively with Analog audio processing and PIC microcontrollers, so I never used MATLAB before... Could you please guide me to evaluate the filter using MATLAB?

Thank you so much!

Hi,

Thanks for the details. Your understanding about the coefficient storage is perfectly fine except for the overall gain.

The overall gain should be the product of the gain for all the sections as I mentioned earlier.So, it should indeed be:

0.0094925636095889564*0.0094925636095889564*0.0094480398122270791 =

8.5536317293219512741082652907796e-7

and not 0.0094925636

Please make these changes and let me know if you still see the problem.

Thanks,

Mitesh

Hi Mitesh! How are you?

As I need to calculate the coefficients "on-the-fly", it won't be possible to use fdatool. Being this way, I am calculating the coefficients myself according to RBJ's filters cookbook (attached here). Problem is that it outputs all 6 coefficients (b0, b1, b2, a0, a1, a2).

The help file you posted says that "The fuction assumes that the value of B0 is 1, and so the B1 and B2 coefficients should be

**scaled**accordingly".**By "scaling" he means multiplied? B1 * B0 and B2 * B0 ?**Also, it says that "A0 is also assumed to be 1, and the A1 and A2 coefficients should be

**normalized**".**What does he mean by "normalized"? The same as "scaled"?**Thanks!!

Well, I've got it partially figured out:

For 1 section filter, b1 and b2 must be

**divided**by b0. Then, at the output, you**multiply**the result by b0. They used the term "scale" twice, for both division and multiplication, got me all confused!**Now, what "normalize" a1 and a2 means? What exactly I must do?**Thanks!

Well, after some testing I figured that for the overall gain, instead of multiplying the filter output only by the B0 coefficient, that must be (B0 / A0) instead, when A0 is not 1.

Also, the same manner that B1 and B2 are divided by B0, so is A1 and A2 divided by A0. So far it's working perfectly fine with only one section. Any comments?

Hi Fernando,

Your latest understanding is correct. The over all gain is actually the multiplication of (B0/A0) values for all the sections.

So, the procedure is:

1. Calculate the Ak, Bk coefficients by the tool.

2. Scale/normalize both Ak and Bk coefficients of all the sections by dividing Bk by B0 and Ak by A0.

3. At the end of the IIR processing, multiply the result by (A0/B0) of section0*(A0/B0) of section1*(A0/B0) of section2...(A0/B0) of sectionN.

Hope this helps.

Thanks,

Mitesh

Hi Mitesh! Yep, I figured that, with lots of headaches

Right, that is working perfectly nice. Now, I just need one more thing:

How to implement filters with more than 1 section (higher order)?

For example, MATLAB's fdatool asks you fpass, fstop frequencies and the attenuation level at fstop. Using this data, the program automatically "knows" the slope, thus it can determine the filter order and design it with more than one section if (as usual) necessary. How could I implement something like that? Because come on... IIR filters of only 1 section are pretty much useless!

Any ideas, or, starting points for me to dig in?

Hi Fernando,

I have the same comments for this as mentioned in the other thread:

http://ez.analog.com/message/51376#51376

"Some thoughts regarding your questions: I understand that you are planning to write some sort of C code on the DSP itself to compute the IIR coefficients dynamically. I am not sure which algorithm you are using and what arguments it expects. But, what I did in octave is that I used function "butter" which takes the order of the filter as one of the parameters and generates the coefficients only with that order. I know that by fixing the order, you may not be able to achieve all the filter characteristics perfectly. But, on the other hand, keeping memory and MIPS issues in mind, you might not be able to allow the filter order to go beyond certain limit."

Again, these are just my thoughts as I am not an expert as well. So, probably someone else here might have better comments.

Thanks,Mitesh

Hi there again,

I've been all afternoon trying to figure it out and seems to me that the "b" elements are the "numerator" and the "a" elements are the "denominator". Is that correct?

Based on that, FDATOOLS tells me that for the filter of the image above (see my post above) these are the numbers:

Section 1:

Numerator:

1, 0, -1

Denominator:

1, -1.9846465579564758, 0.98522638410526819

Gain:

0.0094925636095889564

And so on for sections 2 and 3...

So I suppose that b0 and a0 are "1" as they're meant to be.

Then, b1 is 0 and a1 is -1.9846465579564758

Finally b2 is -1 and a2 is 0.98522638410526819

Gains for the sections 1, 2 and 3:

0.0094925636095889564 0.0094925636095889564 0.0094480398122270791

So I got the 4 coefficients and I replaced the values present in the file "coeffs_band3" accordingly,

**negating the A1 and A2 values**as mentioned in the help file posted by Mitesh. As for the "overall gain", the gain value for the three sections are very close, so I replaced with 0.0094925636095889564. Seemed to make sense, but I hear nothing but noise, cannot even hear a musical note.What am I doing wrong?

ps: I am attenuating all the bands and leaving only band 3 with the normal gain, so I can hear exclusively the bandpass of this particular EQ band. The coefficient file for band 3 is attached.

Thank you!

Hi dspink,

Sorry for replying you late on this. I believe, the FIR filter implementation (algorithm) using the library functions for band pass should remain the same. You might need to design your filter and provide the right set of coefficients to the library function.

Thanks,

Mitesh