oversampling coefficient specification, lib_dsp

Technical questions regarding the XTC tools and programming with XMOS.
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

oversampling coefficient specification, lib_dsp

Post by woodsb »

Hello,

I'd like to use the oversample-by-3 from lib_dsp with 144 coefficients that I have designed. Looking at the current format of the coefficient file, however, I am not quite sure how to pack my coefficients in the existing format.

Can someone please let me know how to convert a vector of 144 filter coefficients in time-ordered format (i.e., h[0], h[1], ..., h[143]) into the format of the coefficient file in the library (which I believe is firos3_b_144.dat)?

Thanks,
Bill


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

The .dat files are lists of Q1.31 coefficients. They are scaled such that the gain of the FIR is a little less than unity. This is done such that inputting a square wave (which results in some ringing due to the low pass nature of the filter) is accommodated without clipping. The FIR inner loop does use saturation so it will clip rather than overflow.

If you look you can see the scope fir plus files (.sfp). You can download a free copy of that and inspect the project used to generate it.
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

Post by woodsb »

Hello,

Thanks for the quick response. I'm not sure how to use it to answer my question, though. I probably wasn't specific enough.

I have all the coefficients designed, scaled, and in Q1.31, and the order I have them in is from time t=0 to time t=143 samples. When I look in the library's coefficient file, however, the order there is clearly not t=0 to t=143 samples. I thought that the order was maybe the three phases of the polyphase representation (for oversampling by 3), but that, too, did not exactly match my expectations.

So, I need to know what order to have the coefficients in the file.

Does that make sense?

Thanks,
Bill
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Yep that makes sense. The filter is a 3 phase polyphase filter and the coefficients are grouped into 3 phases to make the pointer arithmetic easier for the asm inner loop.
So the first 48 entries are h[0], h[3], h[6] etc. And the next 48 are h[1], h[4] etc. Etc. Reorder them accordingly and plot them to get the original impulse response.
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

Post by woodsb »

Ah, I thought that might be the case, but when I plot the frequency response I do not get a lowpass filter at 8 kHz.

I've attached a pdf with a figure showing the impulse response and frequency response as I understand it. Does the figure make sense to you?

cheers,
Bill
InterpFilResp.pdf
(48.39 KiB) Downloaded 282 times
InterpFilResp.pdf
(48.39 KiB) Downloaded 282 times
User avatar
andrew
Experienced Member
Posts: 114
Joined: Fri Dec 11, 2009 10:22 am

Post by andrew »

That filter impulse response looks as if the centre peaks have wrapped around. If you scale the whole thing down the sum i think you would see something more like what you expect to see.
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

Post by woodsb »

That might work, but does that mean I do not have the file format correct? (Recall that I'd like to use a different filter so need to get the file format correct.)

cheers,
Bill
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

the centre peaks have wrapped around
Yep, I'll agree with that. You have overflowed beyond INT_MAX (2147483647) and your peak has wrapped. Scale all coeffs down so that the impulse response peak is within the range of a 32b signed int and it should behave better.
That might work, but does that mean I do not have the file format correct? (Recall that I'd like to use a different filter so need to get the file format correct.)
File format looks OK. The way the source code works is that it includes the filter file inside the array declaration. So as long as the file containing your Q1.31 coeffs is ordered so that it is split into phases {{0,3,6,9..45},{1,4,7,10...46},{2,5,8,11...47}} and gain is a little below unity, then it should work. If the gain is too high then it will clip..
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

Post by woodsb »

Sorry, I must still be missing something.

The attachment I produced was not based on my work but based on the filter coefficient file that comes with lib_dsp.

Both ".dat" files there (/lib_dsp/src/os3/FilterData/firos3_144.dat and firos3_b_144.dat) produce the effect seen.

Perhaps I'm looking in the wrong directory or file? (using version 3.0.0 of lib_dsp)
woodsb
Experienced Member
Posts: 79
Joined: Thu Nov 17, 2016 11:24 pm

Post by woodsb »

Hello,

Has anyone checked on this? I've been able to make a coefficient file work, but in doing so am led to believe that something is wrong with the library data files. Would be helpful to have a conclusion on this.

cheers,
Bill
Post Reply