Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Bidirectional IIR filter

Post any examples or modules that you want to share here

Bidirectional IIR filter

Postby KG_is_back » Thu Jan 16, 2014 9:19 pm

An update to older project posted on SM forum. The reverse filter is optimized now in a single assembly block. The sound gets loaded to second half of input buffer, once the half is full it is passed through filters and saved to one of the output buffers. the two output buffers are then read (with 50% offset) and summed to output. I had to sacrifice double precision math within the filter, but that shouldn't matter at all - actually the performance should be even better now. only disadvantage is, that the filters can not be turned off - they are running even if set to off. That can easily be fixed though...

for those who didn't saw it on SM forum, it is a linear phase filter - it filters segments of sound forward and backward to achieve double amplitude response with zero phase response (so the filters are basically 4th-order filters).

Frequency slider is horizontal and logaritmic scaled and you can type in the frequency by double click. Q and gain sliders are vertical and also can be typed in by doubleclicking. all of them can be reset by double-right-click and draging while holding shift is fine tuning.

hope you enjoy it and let me know what you think.
Attachments
bidir-IIR 5.fsm
(21.89 KiB) Downloaded 1602 times
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Bidirectional IIR filter

Postby RJHollins » Fri Jan 17, 2014 12:00 am

only had a moment to take a peek at this ...

WOW ... this is some seriously good work ! :shock:

Hope to get some time to listen with it ... but man, what a nice GUI interface !

Thanks for letting us see this !

8-)
RJHollins
 
Posts: 1568
Joined: Thu Mar 08, 2012 7:58 pm

Re: Bidirectional IIR filter

Postby Tronic » Fri Jan 17, 2014 12:03 am

There seems to be a problem, if you analyze it with a square wave,
set the filter with only a low pass at 35Hz, you will see that the result is not what you hoped for.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Bidirectional IIR filter

Postby KG_is_back » Fri Jan 17, 2014 1:32 pm

Tronic wrote:There seems to be a problem, if you analyze it with a square wave,
set the filter with only a low pass at 35Hz, you will see that the result is not what you hoped for.


Oh, I forgot to mention this! ...the total length of impulse response of the filter must be less then half the buffersize. Avoid using low cutoffs and high Qs ass they result in longer IR. Or Increase Buffer (bottom right corner), however that will also increase the latency.
Second half of the buffer is filled with signal and when its full it is filtered in backwards. If your IR is longer than the half of the buffersize the part that would be beyond the start of the buffer will simply not be computed. Result is that two following buffers will not joint together and clicks occur.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Bidirectional IIR filter

Postby martinvicanek » Sat Jan 18, 2014 2:23 pm

Impressive! :!:
User avatar
martinvicanek
 
Posts: 1319
Joined: Sat Jun 22, 2013 8:28 pm

Re: Bidirectional IIR filter

Postby KG_is_back » Sat Jan 18, 2014 10:06 pm

I'm planing to add another feature - IR checking module. It will use one of the mono4 channels and will send impulses periodically. then it will record the IR in sync with those impulses. The impulse will show up on the GUI, will be savable as a wav file and will be colored red, if the length exceeds allowed buffer boundaries - noticing you to increase buffer or use different settings.

One problem of this EQ is that it is not automatible. When the cieficients are changing they are adjusting the forward filter smoothly, but the backward filter is computed periodically at buffer boundaries - not sample by sample. One way to fix this would be to record the coefficients for each sample and then call them up in backwards for the reverse filtering - so the order will be right. Another is to create two parallel streams. Every time the coefficients change they will change only on one stream and they will crossfade one to each other, so the transition will be smooth. That would be much simpler to implement and much CPU-friendly.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Bidirectional IIR filter

Postby steph_tsf » Sun Jan 26, 2014 1:13 pm

Hello, I went googling about Bidirectional IIR Filters. I found http://www.analog.com/static/imported-f ... k_Ch19.pdf. This is from Steven W. Smith "The Scientist and Engineer's Guide to Digital Signal Processing" chapter 19. A Linear Phase response results from IIR filtering the signal in the forward direction and then IIR filtering again in the reverse direction. In fact, any recursive filter can be converted to zero phase with this bidirectional filtering technique.

From my understanding, in principle, Bidirectional IIR Filtering only applies to offline processing.

Let me illustrate this. Say you want to filter a MP3 song, using the Bidirectional IIR technique. First of all, you will convert the whole MP3 song into linear PCM data. When the whole linear PCM data gets available, you need to IIR filter the signal in the forward direction and then IIR filter again in the reverse direction. In other words, you only can start playing the filtered song, after having done all this. The whole file needs to be delivered and filtered, before you can play the filtered version. This is offline processing. You can't do this online, like on streamed audio.

Now, tell me, do you "chop" the audio in "buffers", applying Bidirectional IIR Filtering on consecutive "buffers"? What about boundary effects? Are there audible differences, or audible artifacts when changing the "buffer" size?

Say the IIR filter exhibits an impulse response decaying to -96 dB after 100 ms. We''ll be tempted to say there should be no audible boundary effects or artifacts when opting for a 100 ms buffer.

Still, I'm worried by the IIR initial conditions. Whatever the buffer size, I feel there will always remain an artifact when starting the IIR filtering, because of the IIR storage cells containing zeros on that particular position.

In order to avoid this, I would calculate the Bidirectional IIR, using a "A" process, and a "B" process.
The "A" process would use 100 ms buffers.
The "B" process would use 100 ms buffers, shifted by 50 ms.
This way, when process "A" comes to a boundary, possibly delivering an artifact, process "B" is there, delivering a more reliable output.
Having process "A" and process "B" outputs at my disposition, carefully time-aligned, I would blend the "A" output with the "B" output using complementary triangular windows. This way, process "A" is at 100% while process "B" at 0%, when process "B" is facing the boundary. This way, process "A" is at 0% while process "B" is at 100%, when process "A" is facing the boundary. Hope you visualize this.

Any opinion?
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Bidirectional IIR filter

Postby KG_is_back » Sun Jan 26, 2014 6:14 pm

steph_tsf wrote:
Now, tell me, do you "chop" the audio in "buffers", applying Bidirectional IIR Filtering on consecutive "buffers"? What about boundary effects? Are there audible differences, or audible artifacts when changing the "buffer" size?


Boundary effects cancel out. We might say the stream is split into two: fist is multiplied by a square wave 1,1,1,1,1,0,0,0,0,0,1,1... and the second by 0,0,0,0,0,1,1,1,1,1,0,0,... when you sum these two you've got the original signal, so we might say, the artifacts cancel out. They cancel out even after any filtering in any direction. (Actually the Froward filtering happens on the stream before the split)
However, individual sections ( the [0,0,0,0,1,1,1,1] parts) are filtered separately in backward. They rely on fact, that the filter "ringed out" form the previous (the next - we are filtering form end to the beginning) buffer so the filter is reset ti it's initial state. In praxis that means the IR must be sorter than half of the buffer. If it is longer the filter is not reset to initial state and there is no way to foretell the state without knowing the beginning of the file.

Say the IIR filter exhibits an impulse response decaying to -96 dB after 100 ms. We''ll be tempted to say there should be no audible boundary effects or artifacts when opting for a 100 ms buffer.

steph_tsf wrote:Say the IIR filter exhibits an impulse response decaying to -96 dB after 100 ms. We''ll be tempted to say there should be no audible boundary effects or artifacts when opting for a 100 ms buffer.

THat is the point I'm relying on! ;)
If you use Filter Settings that have short IR (despite the name IIR filters do not have infinite impulse response in praxis - IIR always decays to zero never really reaching it, but in digital it is rounded to zero once it gets close, in analog it is lost in the noise, which is just analog version of "rounding" ) like using only single filter with low Q and high cutoff frequency, the boundary effects will be hardly measurable (or not present at all). However if you use high-Q and low cutoff the filter will delay very long and might not ring out completely before the buffer boundaries. In that case You may hear the boundary effects and should increase the buffer-size so the IR "fits within it".

I'm planing to add a feature that will record and check the IR automatically and will notice you if you exceed buffer boundaries (probably by color alarm that will indicate how much "chopping" occurs). You will even be able to save the IRs.

steph_tsf wrote:In order to avoid this, I would calculate the Bidirectional IIR, using a "A" process, and a "B" process.
The "A" process would use 100 ms buffers.
The "B" process would use 100 ms buffers, shifted by 50 ms.
This way, when process "A" comes to a boundary, possibly delivering an artifact, process "B" is there, delivering a more reliable output.
Having process "A" and process "B" outputs at my disposition, carefully time-aligned, I would blend the "A" output with the "B" output using complementary triangular windows. This way, process "A" is at 100% while process "B" at 0%, when process "B" is facing the boundary. This way, process "A" is at 0% while process "B" is at 100%, when process "A" is facing the boundary. Hope you visualize this.


I've used this exact concept in early versions of this project. Later I've found out that if you apply rectangular windows before the the filtering their effects will cancel out even after the filtering.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Bidirectional IIR filter

Postby steph_tsf » Mon Jan 27, 2014 1:34 am

We need to be careful about the concept, practical implementations and practical limitations, before adding bells and whistles.

Let's focus on that boundary artifact cancellation effect you have noticed.
Say Fs = 44100 Hz
Say the IIR coefficients are set for a 2nd order lowpass at 1 kHz with Q=0.707 (Butterworth).
Say we calculate the FFT on 16384 samples for graphing the filtered signal spectrum, using a rectangular window (no window), and no averaging. The FFT time window is thus 371.519 ms. The FFT frequency resolution is thus 2.69 Hz.
Say we input a signal at 2691.65 Hz at -10 dB. The period of such signal is 371.519 µs.
Such 2691.65 Hz frequency got chosen, for ensuring that the FFT gets calculated on 1000 signal cycles, exactly. There is thus no need for windowing the FFT.

Say we apply the bidirectional IIR filtering like you have implemented. What's the filtered signal spectrum when using increasing buffer sizes of 5 ms, 10 ms, 20 ms, 50 ms, 100 ms inside the bidirectional IIR filter routine?

Say the IIR coefficients are set for a 2nd order highpass at 1 kHz with Q=0.707 (Butterworth).
Let's execute the same sanity checks.

If all results are compliant with HiFi (say a 90 dB signal / noise ratio), I recommend that you send an email to Siegfried Linkwitz, showing him how bidirectional IIR filters can now produce linear phase Linkwitz-Riley crossovers. There is already a digital crossover section on Siegfried Linkwitz website.
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Bidirectional IIR filter

Postby KG_is_back » Mon Jan 27, 2014 12:57 pm

steph_tsf wrote:We need to be careful about the concept, practical implementations and practical limitations, before adding bells and whistles.

Let's focus on that boundary artifact cancellation effect you have noticed.
Say Fs = 44100 Hz
Say the IIR coefficients are set for a 2nd order lowpass at 1 kHz with Q=0.707 (Butterworth).
Say we calculate the FFT on 16384 samples for graphing the filtered signal spectrum, using a rectangular window (no window), and no averaging. The FFT time window is thus 371.519 ms. The FFT frequency resolution is thus 2.69 Hz.
Say we input a signal at 2691.65 Hz at -10 dB. The period of such signal is 371.519 µs.
Such 2691.65 Hz frequency got chosen, for ensuring that the FFT gets calculated on 1000 signal cycles, exactly. There is thus no need for windowing the FFT.

Say we apply the bidirectional IIR filtering like you have implemented. What's the filtered signal spectrum when using increasing buffer sizes of 5 ms, 10 ms, 20 ms, 50 ms, 100 ms inside the bidirectional IIR filter routine?

Say the IIR coefficients are set for a 2nd order highpass at 1 kHz with Q=0.707 (Butterworth).
Let's execute the same sanity checks.

If all results are compliant with HiFi (say a 90 dB signal / noise ratio), I recommend that you send an email to Siegfried Linkwitz, showing him how bidirectional IIR filters can now produce linear phase Linkwitz-Riley crossovers. There is already a digital crossover section on Siegfried Linkwitz website.


go ahead :-D feel free to do any tests you want. Tests I've done so far:
1. Captured impulse response by inputing an impulse. Also I've checked it by time shifting the impulse to make it out of sync with buffers. As long as the IR width was smaller than Buffersize the result was always the same no matter the time shift and no boundary effects were present (well, maybe some noise below 80dB). FFT shows the filter truly is linear phase and has the same amplitude response as two identical filters (the same biquad sections from the forwad-time version) in succession.
2. I've inputted a sine wave, set my settings and tried different buffer sizes. with low buffer there were harmonics present in the signal (and in the oscilloscope boundary effects were clearly observable), but after I've increased the buffer over certain limit they were gone and oscilloscope showed that the sinus line was perfectly jointing. I've done the same test with fixed buffersize and changing the settings of the filter, results were the same.

Here is an image I've made - an testing of the backward filter (the forward filter is bypassed). The first graph shows the output of odd buffers and second of the even buffers. The actual buffer boundaries are marked with red "T". The third graph is the sum of the two, which is actual backward filter output.
Here you can see, that the "tail" perfectly fits to the artifact at the start of next buffer.
Attachments
filter buffering.png
filter buffering.png (83.42 KiB) Viewed 38852 times
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Next

Return to User Examples

Who is online

Users browsing this forum: No registered users and 23 guests