Showing posts with label fir_filtering. Show all posts
Showing posts with label fir_filtering. Show all posts

Practical FIR

Part 3

As ever so often in engineering, if some new technology is introduced we go into  'nec plus ultra' modus. Suddenly you will find a huge range of applications where all and unique is about that new tech. Same for FIR filtering. 

The first appearance of FIR in (diy) audio was as a means to do room EQ-ing. The idea was to measure a systems response in a room, do quite some averaging and apply an overall EQ that would correct all and everything. First there is of course no such thing as room EQ: the only way to change the acoustics of a room is by changing it's dimensions and/or changing the absorbing/reflecting surfaces. But the solution is better then using only conventional (min. phase) EQ as we have been doing with our 31b. graphics.

Some of the room effects are min. phase and thus one could use a graphic to try to address the problems. The definition of min. phase behaviour dictates that your ideal EQ point will have both the necessary magnitude and phase compensation. 

So for these min. phase phenomena the EQ will NOT introduce 'PHASE ISSUES' (crinch).

However. Loads of stuff you would like to EQ in acoustics is NOT min. phase. Remember playing a festival and during nightfall HF content of your PA changes drastically? And changing your graph. EQ doesn't help in the way you wanted? Well that's a non min.phase phenomena and this would call for a lin. phase EQ, which as we know now is only possible with FIR.

 

Another example would be (conventional) EQ-ing across a line array. Hopefully everybody does understand you can't apply different EQ settings to different elements in your line array, right? The different phase behaviour of the different elements will in that case wreak havoc on the overall dispersion of the array! The only way you can get away with this is by using lin.phase EQ. Something that French manufacturer of brown boxes does understand.

So when and where to apply lin.phase FIR filters as a means of filtering without affecting phase is something that needs thought!

It is not the miracle solution for everything, it is just another tool and it does have pro's and con's like any other tool.

So yes, as has been explained on million places: FIR filters can be computational heavy, but why should that be mentioned over and over as a problem? 

A more interesting difference, if you really would like to set IIR versus FIR, is the way the precision of the calculations work out sonically. Fixed point vs floating point. Internal bit depth. The way rounding errors work in your algorithm. Audibility of the pre-rings (or not?) That sort of thing. In the MCU/DSP part of this blog I will write a bit about this.

If all this is cleared, one big topic still is to be debated:

IS PHASE AUDIBLE?

(or more precise does applying an allpass filter change the way (stereo) audio is percieved?)

One will understand that I (and my peers) do have an opinion contrary to that of the big names in our industry. This is the internet: I can't demonstrate, but I encourage you to find out for yourself!



Filtering by IIR or FIR

Part 1

Before we dive into the depths of FIR or IIR filtering, let's talk about audio in general.

We have this custom in Audio engineering of analysing everything in the frequency domain. Apparently something we inherited from Electrical engineering. It does seem quite logical though, after all music is all about sine waves, right? 

Wrong! 

Look at some recording you made with your favourite DAW (audacity f.e.)

The signal (in stereo) can look something like this. It is the equivalent in voltage to the air pressure or eventually the position of your eardrum of the stuff we call sound. No sine wave insight is there?

Another argument against the preoccupation by analysis in the frequency domain could be: tell me the frequency of a handclap or the whistling wind or all the consonants we use...

Should we stop talking about sound in the frequency domain? No! But do realize we are using a model of reality when we do.

Years ago by work of Helmholtz and Fourier the method of decomposing a chunk of a recording like in the picture above into it's sinusoidal components has been worked out. (in fact Helmholtz has written a paper on what happens after this decomposition, look for 'auditory roughness' ) 

And we now all have the computational power of using this analysis by FFT. If you are totally compelled by any mathematics whatsoever, think about FFT as follows: Imagine a prism. It decomposes a light beam into the different waves it is build up with into these well known rainbows. The FFT engine works a similar way in that it decomposes a chunk of audio into it's sinusoidal components.

Now on to the topic at hand.

In some other parts in this blog you can read about the use of a (dual) FFT analyser in how to get a frequency domain analyses of your device under test. In diy loudspeaker circles a more common use will be Room EQ Wizard, REW to obtain what they call frequency response (commonly abbreviated to FR). Mostly they forget about the 'phase' part of the bode plot. 

That isn't really a bad thing. As for the most part a loudspeaker (and filtering) behave as minimum phase systems. Minimum phase (not minimal!) means that the phase response is dictated by the frequency (magnitude) response and vice versa.

So a FR measurement also holds the information to derive the associated phase response. No magic here, just plain laws of physics.  So every deviation you see from the frequency response must have a corresponding phase deviation from that so desired 0 phase line. (all under the premise of 'minimum phase' or LTI) 

 There is 1 big exception: All pass filters! All pass filters will have a typical phase response WITHOUT anything reflected in the frequency response. And vice versa. If you think about it: an ideally crossed multi speaker system will have a flat FR and a overall All Pass phase behaviour. (as long as conventional,IIR filters are used) Maybe something like this for a 2-way system:

 

If you are still uncomfortable with the concept of phase, don't worry to much. Just don't confuse phase and delay. Like defined elsewhere in this blog: we use the word phase (-difference) for that part of the overall frequency dependent time difference between two components where plain, simple 'excess delay' is stripped away. So:

Time alignment does not equal Phase alignment !!

('time' alignment as a scientific term is a bit Einstein-esque , it is signal alignment..but hey..)

...onto FIR filtering part2


Filtering by FIR

 Part 2

At different places in this blog you can find information on how to setup your sound system in such way that it behaves as an overall All pass filter.
Using conventional IIR filters or even plain old analogue filters if the components don't have a delay offset that needs to be dealt with.

Now: long, long time ago when I got my first DSP (somewhere beginning '90) I had to do system setup just by ear. Measurement systems did exist (Meyer SIM) but where simply not affordable. In those days  I ran components full range and set delay by ear. It is simple. Just use common sense to get the ball park and tweak till audio nirvana.
Next you set the X-over as dictated by the text books and there goes your audio nirvana out of the window.
Quickly we did realise you need to find a way of phase alignment too, to get your filtering correct.
All rather common these days, but that sense of audio nirvana as in above never really happened in these filtered systems.
And phase by itself is inaudible, so all the big names say...

Stubborn as we are we kept on searching, using weak filter slopes (6 dB) and using coaxial sources. Till at some point that "new thing" FIR filtering entered our industry in the form of these brick wall filters in the Dolby Lake processor (2004).
Now that was eye opening, most certainly after we did realise that you could also develop your own filters and not use those dreaded brick wall filters because they sound horrible. Unfortunately my business was way to small to get the access to load custom FIR in a Dolby Lake. So the the quest for a platform with custom FIR started.
 
But first let's explain how FIR filtering works. 
In fact it is a very simple operation once you are in the digital domain.  Imagine a chunk of sampled data over time, maybe from some temperature sensor. Now if you would like to know the average over a certain period you could add say 10 samples and divide by 10. Or in other words multiply those 10 samples by 0,1 and add the results to the total averaging output value. And keep on doing this over and over again.This is called a moving average filter and in fact is a very crude high cut FIR filter.
The number of 'taps' in the above filter is 10 and the filter 'kernel' is an array with 10 (the number of taps) positions with a value each of 0,1.

You could imagine those filter kernels to be more elaborate, right? 
Now with the same mathematics as has been used with the measuring setup described in an other post you can derive those filter kernels: Fourier Transform!

Just use a iFFT to calculate the Impulse Response from a desired Frequency Response. 
The process of using an Impulse Response as a filter kernel is also called Convolution, which you will have heard of as being used in reverbs, cabinet emulations etc.
 
    The ImpulseResponse of your desired FreqResponse will be used as the filter kernel!

Rephase
Now how can we do that without getting familiar with Matlab (like I had to do 20 years ago) 
Well: thank Thomas Drugeon for REphase.  It's a very nifty little program, around for some 10 years now, to help you develop your filterkernels. For free! (but do donate some if you like it!!)
 
 
 
So to round it up: FIR filtering is about using a Impulse Response derived from your desired Frequency Response. That by itself doesn't mean all FIR filters are linear phase.  A lot of people in our industry use FIR as a synonym for lin. phase (meaning not having any impact on the phase) and start talking about 'latency' of these filters. This concept is both limited and wrong.
 
Let me explain in simple terms.
To make a lin.phase filter you start of by taking the IR of a conventional filter as in described above. It will have its associated phase response. Next make a copy, reverse all coefficients and glue this to the original IR. The filter kernel is now totally symmetric around the middle coefficient and as such will not have any impact on the phase (uhmm, well just believe me, there's heavy math behind this)
But it will also be twice as long as would be needed for a non-linear phase filter.
So it takes some time for the signal to pass through such a filter. In fact half the length of the filter kernel (as expressed in number of taps).
This will not get any faster if processors would run faster so the expression "latency" as we use when we are talking about using a PC and audio processing is not correct. 
 
Let's call it filter processing delay and do understand this is depended only on both the sample freq. and the number of taps used for the filter. 
 
Which is something we would have to discuss too, but you can find the background at different places. For now do understand that both sample freq. and the number of available taps determine the resolution of your FIR: the lower the freq. and the higher the Q of the filters: the more taps you will need. 
 
In a real world live situation there is a limit to the time difference between the moment a sound is produced and the moment that sound comes out of the speakers. (from there on it's acoustic path length differences, but we do understand this intuitively, right?) So you have to determine what for your situation is acceptable.

Examples?
Maybe the sound coming from your mainsystem shouldn't arrive after the backline/drumkit? In a club situation that is, where indeed the levels of backline/ acoustic drums are in the same order as the levels of your PA. So say something like 3 mtrs (or 10mS) in this situation?.
But what about that little, processed wedge next to that grand piano? (I ended up putting it on a little riser to overcome the timing issues).
 
 
...Maybe best to keep on using your ears!