8 Replies Latest reply on Aug 17, 2014 8:44 AM by Marki555

    DC offset on microphones and workaround.


      When recording from the on-board DMICs and the microphone on my headset, I have noticed DC offset.
      On my headset microphone, not so much, but on the DMICs there is a lot.
      When recording silence, the signal rests at around -30dB on the positive side.


      The easy way to remove DC offset is to apply a fairly steep high-pass filter with a low cutoff frequency, in post-production.
      E.g. in Audacity you can go to Effects... -> Equalization... and apply the 100Hz Rumble EQ curve.

      But perusing the WM5102 data sheet revealed that it has filters on-chip, so why not use them?

      Here's my modified use case script for recording from the DMICs:


      # Record from onboard DMICs to RPi.
      # Route through High Pass Filter to get rid of DC offset.
      # IN2 --> LHPF --> AIF1TX
      # May want to tune the gain here
      # Need at least -6dB
      amixer -Dhw:0 cset name='IN2L Digital Volume' 128
      amixer -Dhw:0 cset name='IN2R Digital Volume' 128
      # DMICs are incorrectly labeled on the board.
      # DMICL is actually the right channel and vice versa,
      # so we'll swap them here.
      # i.e. IN2R --> LHPF1
      #      IN2L --> LHPF2
      # Route DMICs (IN2) to LHPFs.
      amixer -Dhw:0 cset name='LHPF1 Input 1' IN2R
      amixer -Dhw:0 cset name='LHPF2 Input 1' IN2L
      amixer -Dhw:0 cset name='LHPF1 Mode' High-pass
      amixer -Dhw:0 cset name='LHPF2 Mode' High-pass
      amixer -Dhw:0 cset name='LHPF1 Coefficients' 240,3
      amixer -Dhw:0 cset name='LHPF2 Coefficients' 240,3 
      # Connect outputs of LHPFs to inputs of AIF1 (I2s to RPi)
      amixer -Dhw:0 cset name='AIF1TX1 Input 1' LHPF1
      amixer -Dhw:0 cset name='AIF1TX1 Input 1 Volume' 32
      amixer -Dhw:0 cset name='AIF1TX2 Input 1' LHPF2
      amixer -Dhw:0 cset name='AIF1TX2 Input 1 Volume' 32
      amixer -Dhw:0 cset name='DMIC Switch' on

      As can bee seen in the picture, the difference is obvious.
      The top stereo track was recorded using the supplied Record_from_DMIC.sh use case script
      and the bottom track with my modifications.



      I have no idea about what the cut-off frequency of the filter is or how steep it is. The command

           amixer -Dhw:0 cget name='LHPF1 Coefficients'

      only reveals two values, both of which are zero:

      numid=85,iface=MIXER,name='LHPF1 Coefficients'
             ; type=BYTES,access=rw------,values=2
             : values=0x00,0x00

      I'm guessing they represent frequency and steepness in some way, but the datasheet only has this to say about them:
      "These coefficients are derived using tools provided in Wolfson’s WISCE™ evaluation board control software; please contact your local Wolfson representative for more details."

      My tests show, though, that voice recordings are not affected in any negative way.


      EDIT: Added coefficients to the script as suggested by Scott




        • Re: DC offset on microphones and workaround.

          Hi Ragnar,


          Thanks for posting up your suggestion on how to fix this problem. DC offset is definitely an issue for the on-board mics. We haven't tested yet with any external mics, but will be in the next few days.


          We've had some pretty descent recordings from the on-board mics, applying a Normalize (DC bias adjustment @ 0%) post-process in Adobe Audition. 

          When we tried your suggestion of using the filters on the chip, they clearly make a good difference to the final signal, but the sound quality was poor, due to almost complete loss of bass.  1000 - 5000 Hz is pretty much dead.  Not sure what is different, as we're using the same settings that you posted, although you had no negative change in sound quality.


          Do you know of any other setting that might be able to adjust the DC offset? Maybe we could do with some more details from our 'local Wolfson representative'..


            • Re: DC offset on microphones and workaround.

              Hi Ben!


              I have noticed the loss of bass too, but not that much. My voice loses some of it's manliness, but that's all. I do see a 20 dB notch at 3 kHz, though.

              I'm guessing the filters are set up by default to work for speech in a phone application, i.e. quite a limited frequency bandwidth.

              For a phone, getting rid of the bass is a good way to lose wind noise, traffic rumble in the background etc.

              And for my purposes that is almost OK, since I'm trying out the card for noisy speech applications - outdoor live radio broadcasting.

              But I agree, I would like the filter to be not quite so aggressive.


              As I understand it the filters are adjustable, but as I wrote in my original post, I have no idea how.

              I haven't found anything else on-board that helps. I have tried with the equalizers, but they let DC offset through.

              There is about a gazillion DSPs and stuff on the board, but how to use them? I fully endorse your "Maybe we could do with some more details from our 'local Wolfson representative'"


              There is DC offset on the headset microphone input and on the analog line input too.

              And yes, I'm still using the same script.



                • Re: DC offset on microphones and workaround.

                  Hi Ragnar and avidhills.


                  Thanks for the posts and information on the input dc offset, great work.

                  Everything you have posted to date is correct, however let me give you some additional information on the HPF filter configuration for the WM5102 which should remove the dc offset while preserving lower frequency. This can be applied to any input signal path.


                  The key here as you pointed towards are the LHPFx Coefficients value.


                  When routing and enabling the HPF filter, the default coefficient values result in a cut off frequency (fc) = fs/4. fs is the sample rate so easy to see the default value will be to high for the majority of use cases.


                  The following table provides some example values which can be used. The table provides cut off frequencies for fs=48k, note the cut off frequency will scale linearly with sample rate. Therefore I would recommend using the 240,3 setting as this will provide a low cut off frequency across all sample rates.

                  The following command can be added to specific user scripts


                  amixer -Dhw:0 cset name='LHPF1 Coefficients' abc,xyz (a write for each LHPF filter is required - for stereo 1 and 2)



                  Cut off frequency (fc) Hz














                  fc scales linearly with sample rate.

                    • Re: DC offset on microphones and workaround.

                      Thanks Scott!


                      My manly voice is back

                      I actually found some of the magic numbers the other evening by experimenting with white noise and SpectrumLab. But it wasn't self-evident what they really mean and how to derive them. If it's possible to derive them, that is. I'm getting the feeling that there is a look-up table involved...


                      But this helps tremendously. My work-flow is at 48kHz, 5Hz for DC-block and 100Hz for my microphone work will serve me well!




                      • Re: DC offset on microphones and workaround.

                        Thanks Scott for that info on the filter coefficients. I am interested in recording signals down to around 0.5 Hz (and only extending up to about 100 Hz). My question is, is there any analog highpass filtering on the inputs, in addition to the digital filter? It seems like there isn't (due to the DC offset) but can you just confirm that please?


                        Thanks and regards, Martin

                          • Re: DC offset on microphones and workaround.

                            The audio card is typically designed for audio band use cases, typically 20Hz - 20kHz so if you are looking to use the low frequencies you specify you are in slightly unchartered waters.


                            As you mention analog high pass filtering I assume you mean analogue inputs and not the DMIC (digital interface).

                            For the anlogue inputs internal to the WM5102 there is no specifc high pass filtering.

                            You should however note that the input ac coupling capacitor on board will introduce a high pass filter in conjuction with the input impedance of the anlogue inputs. I would suggest you would need to increase the value of the capacitor if you want to extend lower in frequency.

                    • Re: DC offset on microphones and workaround.

                      You can "guess" the LHPF/EQ coefficients using the WISCE software - more info in this blog post Wolfson audio paths & how to use EQ and LHPF