Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How do you detect different sound frequencies and cut off parts in an audio file? Among instruments, how do you pick up the human voice?

share|improve this question
Wasn't this question just posted and migrated to Signal Processing? – s0rce Nov 27 '12 at 3:50
@s0rce could you post the URL ? – Vitaliy Kaurov Nov 27 '12 at 4:19
@VitaliyKaurov This was the original question. I migrated it, but the OP deleted it and reasked it here again... – R. M. Nov 27 '12 at 5:06
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign` – Vitaliy Kaurov Nov 27 '12 at 6:32
Do you know what type of noise has been added, periodic, narrow band, wide band; white, pink etc? – image_doctor Nov 27 '12 at 13:58

2 Answers 2

up vote 21 down vote accepted

A lot depends on your specific data. But if the noise is far from voice in frequency domain there is a simple brute-force trick of cutting off/out "bad" frequencies using wavelets. Let's import some sample recording:

voice = ExampleData[{"Sound", "Apollo11ReturnSafely"}]

enter image description here

WaveletScalogram is great for visualizing voice versus noise features:

cwt = ContinuousWaveletTransform[voice, GaborWavelet[6]];
WaveletScalogram[cwt, ColorFunction -> "AvocadoColors", ColorFunctionScaling -> False]

enter image description here

Voice is more rich and irregular in structure, noise is more monotonic and repetitive. So now based on the visual we can formulate a logical condition to cut out the noisy octaves (numbers on vertical axes):

cwtCUT = WaveletMapIndexed[#1 0.0 &, cwt, {u_ /; u >= 6 && u < 9, _}];
WaveletScalogram[cwtCUT, ColorFunction ->"AvocadoColors", ColorFunctionScaling -> False]

enter image description here

This is pretty brutal, like a surgery that cuts out good stuff too, because in this cases some voice frequencies blend with noise and we lost them. But it roughly works - signal is cleaner. You can hear how many background noises were suppressed (a few still stay though) - use headphones or good speakers. If in your cases noise is even further from voice in frequency domain - it will work much better.


enter image description here

share|improve this answer
How did you make the decision on what was and wasn't noise? – rcollyer Nov 27 '12 at 5:44
@rcollyer I gave some explanation under WaveletScalogram image. Voice has rich irregular structure. Noise is monotonic and repetitive. – Vitaliy Kaurov Nov 27 '12 at 5:47
@NasserM.Abbasi Thanks! I corrected the code, should work now. – Vitaliy Kaurov Nov 27 '12 at 6:20
Maybe I should have read it ... :P – rcollyer Nov 27 '12 at 6:24

What you need is BandpassFilter, which is new in version 9. Assuming your audio is sampled at 22400 Hz, you can do:

BandpassFilter[data, {60 π, 180 π}, SampleRate -> 22400]

to filter it to between 60-180 Hz.

share|improve this answer
This works for SampleSoundList, so for voice above, this would be done: Sound[BandpassFilter[voice[[1]], {60 π, 180 π}, SampleRate -> 22400]]. It did not work as well as the wavelet based denoising by @Vitaliy Kaurov – ubpdqn Dec 2 '12 at 10:03
@ubpdqn You'll have to filter the correct band for the sound sample that Vitaliy used. I was addressing OP's question where they wanted to filter their data (not shared) between 60 and 180 Hz. – R. M. Dec 2 '12 at 15:23
@rm-rf thank you for the clarification – ubpdqn Dec 3 '12 at 8:30
Should that be BandpassFilter[data, {2 π 60, 2 π 180}, SampleRate -> 22400] for radian frequencies? That is, a coefficient of 2 π rather than π. – david Dec 3 '12 at 18:06
@david Maybe... I wrote this answer before version 9 was actually released (going just by the docs which rolled out early). I'll test it with an example edit it later today with some more info. – R. M. Dec 3 '12 at 18:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.