element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum DC offset on microphones and workaround.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 8 replies
  • Subscribers 663 subscribers
  • Views 2981 views
  • Users 0 members are here
  • wolfson
  • dmic
  • audio_card
  • raspberry_pi
  • raspeberry_pi_accessories
  • dc
  • offset
Related

DC offset on microphones and workaround.

Former Member
Former Member over 11 years ago

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:

 

#!/bin/bash
# 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.

image

 


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 WISCETm 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

 

--

Ragnar

  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 11 years ago

    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'..


    B

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    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.

    --

    Ragnar

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    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)

     

    abc,xyz

    Cut off frequency (fc) Hz

    fs=48k

    240,3

    5

    240,53

    100

    240,158

    300

    241,4

    500

    241,152

    800

    241,248

    1000

    fc scales linearly with sample rate.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    Thanks Scott!

     

    My manly voice is back image

    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!

     

    --

    Ragnar

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    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.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    Thanks for the info Scott, much appreciated. I'll  make sure to test with some low freq input signals and see what kind of attenuation I get. For the moment I'm still working with signals in the audio range, but low freq work will be one of the next steps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Marki555
    Marki555 over 10 years ago

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube