standalone make of 'build_biquad_coefficients'

Technical questions regarding the XTC tools and programming with XMOS.
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

standalone make of 'build_biquad_coefficients'

Post by rlim »

Hi,
Can someone show me how to execute the following to get the response curves and coefficients without the added weight of including it in 'app_usb_aud_l1'?

make -f ../build_biquad_coefficients/Makefile \
FILTER='-min -20 -max 20 -step 1 -bits 27 -low 250 -high 2000
-peaking 500 1 -peaking 1000 1' \
INCLUDEFILE=src/coeffs.h \
XCFILE=src/coeffs.xc \
CSVFILE=bin/response.csv

I assume it can be done somewhere in xtime composer, but I'm lost at the moment....

Thanks,
Richard


henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi,

You will need to run that tool from the command line on your machine.

On a Mac or Linux, go straight to the build_biquad_coefficients directory and run (x)make; I am not sure how to do that on Windows, somebody else may be able to tell you if you use Windows.

If memory serves me right, it is written in Java - so you will need that installed.

You can edit the settings; again from memory, running the java file without parameters gives you a list of options.

Cheers,
Henk
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

So in the AN01008 on adding DSP to the L1 design, it says
[quote]
The following section should be added, with "coefficients" also added to the "all" build targets:
coefficients:
make -f ../build_biquad_coefficients/Makefile \
FILTER='-min -20 -max 20 -step 1 -bits 27 -low 250 -high 2000
-peaking 500 1 -peaking 1000 1' \
INCLUDEFILE=src/coeffs.h \
XCFILE=src/coeffs.xc \
CSVFILE=bin/response.csv
all: coefficients $(BIN_DIR)/usb_audio.xe
[quote]

So I added this to the Makefile and proceeded to build. It appears to build cleanly. But when I try to run it, it gave me these errors:
C:/Users/rlim/Google Drive/xmos/sc_dsp_filters-master/build_biquad_coefficients/src/makeCoeffs.c:173:23: error: use of undeclared identifier 'FILTER'
char *argString = FILTER;
^
C:/Users/rlim/Google Drive/xmos/sc_dsp_filters-master/build_biquad_coefficients/src/makeCoeffs.c:198:13: warning: implicitly declaring library function 'strncmp' with type 'int (const char *, const char *, unsigned int)'
if (strncmp(argString, "-low", 4) == 0) {
^
C:/Users/rlim/Google Drive/xmos/sc_dsp_filters-master/build_biquad_coefficients/src/makeCoeffs.c:198:13: note: include the header <string.h> or explicitly provide a declaration for 'strncmp'
1 warning and 1 error generated.
xmake[1]: *** [.build_1xoxs/build_biquad_coefficients/src//makeCoeffs.c.pca.xml] Error 1
xmake: *** [analyze] Error 2

What should I do next?
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi,

I just had a look - and something is broken; my guess is that AN01008 uses the old sc_lib_dsp_filters biquad generator; but that has moved on.

As a work-around until this is fixed, first download MakeCoeffs.java and put it in a file MakeCoeffs.java

Then:

Code: Select all

javac MakeCoeffs.java
java MakeCoeffs -min -20 -max 20 -step 1 -bits 27 -low 250 -high 2000 -peaking 500 1 -peaking 1000 1 -h /tmp/coeffs.h -xc /tmp/coeffs.xc -csv /tmp/response.csv
Now have a look at the response file, and if you are happy, move the coeffs files into the source directory. If not happy, run the last line with different settings until it all looks good.

Let me know how you get on,
Henk
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

Thanks Henk, finally got it to work.
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

Henk,
I need some help in interpreting the coefficients. For example,
{ //Db: -80.0
{16848, -26064, 10650, 267814242, -133597948},

I understand that 16848=b0/a0. So if it's 2.30 fixed point, then
dec2bin(16848)=100000111010000
which means the MSB here is 2^-16, so the 16848 representation equates to ~153-6?

If my understanding above is incorrect, can you give an example calculation for a value of b0/a0=0.7966 (from matlab), that will play nice with the .xc code?

Thanks in advance,
Richard
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

So if I have
struct coeff biquads[DBS][BANKS] = {
{ //Db: 40.0
{1146772322, -2126116946, 990761741, 2131768419, -1058140766},
},
};

And assigning in matlab
num=[1146772322 -2126116946 990761741];
den=[1 2131768419 -1058140766];

and doing freqz(num,den), I'm not getting the same response as response.csv. The csv file shows a 40db passband gain, having a shelving low-pass down to zero, whereas matlab shows a highpass starting at around -45db. Any clues?
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

Never mind. Figured it out.