How to add/remove echo/noise for a given wave file - echo

Without knowing about noise and echo, I am asking this question. How to remove/add noise /echo for a given WAV file? Please provide suggestions/guidance.

In order to "remove" noise from a signal, you must have or recreate the noise you want to remove and substract that from your audio. So it depends on whether you can isolate or replicate the problem signal.
To a certain extent "noise" (hiss or other constant sound) can be cleaned from an audio signal and there are various applications/plugins that attempt to do this - success depends on the consistency and amplitude of the noise vs signal.
Removing "echo" (not sure what you mean by this, but I assume you mean "reverb", or acoustic properties of the space the sound was recorded in) is extremely complex since it is not consistent and in most cases would be impossible to replicate.

Removing noise I believe, removing the background noise, also be known as ambient noise.
Usually there are two step to remove noise from audio.
Create a background noise_profile
Audio - noise_profile = Clean Audio
There are two ways we can do the above.
Audacity:
Steps
install audacity desktop app
open and go to the file menu and select the audio for noise removal
if you listen to the file, you can realize the silence clear noise and the frequency of that portion is small. That need to be removed from the call.
Select the noise portion from the audio
Go to effect menu >> then select noise reduction >> click on Get Noise Profile
Then ctrl + a to select the complete audio to apply noise profile to reduce noise
from effect menu >> noise reduction >> click on ok to apply noise profile into the audio. You can adjust the parameter and test which one is best. If you set this high you may lose few words.
Now you can see the noise from the silence portion has gone. You can validate by listening to those.
SOX: Steps
Install SOX
Create background noise profile using the audio file
/usr/bin/sox noise.wav -n noiseprof noise.prof
Remove noise from mp3 using profile
/usr/bin/sox noise.wav clean.wav noisered noise.prof 0.20

Related

Matlab:How to LOWER signal to noise of audio

I have some code that block processes the xcorr command with parallel computing too. I want to test how robust cross correlation is with data that has lower S/N.
The only problem is I don't quite know how to apply this. I have an audio file with animal calls. It is mostly noise with intermittent calls. all the calls have different S/N. If you look at the Short Term Fourier Transform spectrogram of the animal call, you will see a blob with a distribution of different intensities.
I want to lower the S/N of these calls so that the shape of the distribution of intensities is still the same, it's just that they are smaller in intensity.
To successfully lower the S/N of the audio, I'm assuming I don't want to change the background noise values either, so only the calls themselves are lowering in amplitude but not the noise.
I don't quite know how I can program this, can I get some help please?
I think you can safely just add extra noise to the whole sample, this is common when testing robustness: if your original sample has say 50 units** of signal and 50 units of noise (SNR of 50/50) then adding say 100 units of noise will lead to a SNR or 50/150, which is lower.
**subject to discussion of what constitutes a unit - power vs voltage, dBs or whatever, it's just for the sake of an example.
If it's important what type of noise you add then perhaps you could copy some from the sections without samples in - doing this manually is usually efficient enough when creating test cases. Alternatively rand will give you random numbers and rng will let you control the distribution.
An alternative method might be to apply a compression function to the spectrograph and then apply the inverse transform to bring it back to the time domain. Beware of using modified versions of your training data to test the algorithm, if you have sufficient data you'd be best to reserve some for testing.
To do this with a sound file editor (plus a file full of noise of your desired distribution and type), first turn down the level of the original file until the signal is at your desired lower level, then mix in the noise file to bring the noise back up to the original level (by setting the appropriate mixer parameters). The resulting mix will have a lower S/N.

Why isn't there a simple function to reduce background noise of an audio signal in Matlab?

Is this because it's a complex problem ? I mean to wide and therefore it does not exist a simple / generic solution ?
Because every (almost) software making signal processing (Avisoft, GoldWave, Audacity…) have this function that reduce background noise of a signal. Usually it uses FFT. But I can't find a function (already implemented) in Matlab that allows us to do the same ? Is the right way to make it manually then ?
Thanks.
The common audio noise reduction approaches built-in to things like Audacity are based around spectral subtraction, which estimates the level of steady background noise in the Fourier transform magnitude domain, then removes that much energy from every frame, leaving energy only where the signal "pokes above" this noise floor.
You can find many implementations of spectral subtraction for Matlab; this one is highly rated on Matlab File Exchange:
http://www.mathworks.com/matlabcentral/fileexchange/7675-boll-spectral-subtraction
The question is, what kind of noise reduction are you looking for? There is no one solution that fits all needs. Here are a few approaches:
Low-pass filtering the signal reduces noise but also removes the high-frequency components of the signal. For some applications this is perfectly acceptable. There are lots of low-pass filter functions and Matlab helps you apply plenty of them. Some knowledge of how digital filters work is required. I'm not going into it here; if you want more details consider asking a more focused question.
An approach suitable for many situations is using a noise gate: simply attenuate the signal whenever its RMS level goes below a certain threshold, for instance. In other words, this kills quiet parts of the audio dead. You'll retain the noise in the more active parts of the signal, though, and if you have a lot of dynamics in the actual signal you'll get rid of some signal, too. This tends to work well for, say, slightly noisy speech samples, but not so well for very noisy recordings of classical music. I don't know whether Matlab has a function for this.
Some approaches involve making a "fingerprint" of the noise and then removing that throughout the signal. It tends to make the result sound strange, though, and in any case this is probably sufficiently complex and domain-specific that it belongs in an audio-specific tool and not in a rather general math/DSP system.
Reducing noise requires making some assumptions about the type of noise and the type of signal, and how they are different. Audio processors typically assume (correctly or incorrectly) something like that the audio is speech or music, and that the noise is typical recording session background hiss, A/C power hum, or vinyl record pops.
Matlab is for general use (microwave radio, data comm, subsonic earthquakes, heartbeats, etc.), and thus can make no such assumptions.
matlab is no exactly an audio processor. you have to implement your own filter. you will have to design your filter correctly, according to what you want.

MATLAB filtering having little effect

I'm hoping someone will be able to tell me why no filtering is helping in my application.
I have a MEMS microphone monitoring the pressure of a small chamber, which has a membrane stretched over the far end. This device is placed on a human muscle and when I flex said muscle the membrane is disturbed, producing a pressure difference in the chamber, which the microphone picks up. Therefore, by flexing a muscle I can see nice spikes of activity. However, this method is very susceptible to noise, both motion artefacts and other undesirable artefacts.
The muscle activity I'm interested in is above 10Hz and below 100Hz, so I'm trying to bandpass (or at the very least, highpass) the noise. If I tap the device, or if I have the device on my upper forearm and tap my wrist, I'm to understand that this is a very low frequency noise, somewhere in the region of 1Hz/2Hz, but I can't get rid of this noise!
I'm using MATLAB to process. Generally I sample this microphone at 1KHz, but I currently have it hooked up to a DAQ at 5KHz sampling rate. I desperately want to get rid of this low frequency noise but nothing I try seems to make any difference, it's very hard to see what the filter is doing at all. It's definitely attenuating the signal, but not getting rid of the noise I want. I don't expect perfect results, but certainly better than what I'm seeing.
I've used lots of methods to create filters in MATLAB (manually and fdatool), along with different types of filters (Butterworth, Chebyshev, Elliptic) all not helping. I'm worried that my desired frequency of 10Hz is perhaps too close to the noise I'm trying to filter out, and it's not able to attenuate the noise enough.
Any ideas, code samples, or recommendations would be very helpful.
Tapping or percussive sounds are broad spectrum, producing frequency content well above the repeat rate of 1 Hz or so. So any linear band pass or high pass filter will not be able to completely remove this broad spectrum noise.

Notch filters and harmonic noise in matlab

So basically, my problem is that I have a speech signal in .wav format that is corrupted by a harmonic noise source at some frequency. My goal is to identify the frequency at which this noise occurs, and use a notch filter to remove said noise. So far, I have read the speech signal into matlab using:
[data, Fs] = wavread('signal.wav');
My question is how can I identify the frequency at which the harmonic noise is occurring, and once I've done that, how can I go about implementing a notch filter at that frequency?
NOTE: I do not have access to the iirnotch() command or fdesign.notch() due to the version of MATLAB I am currently using (2010).
The general procedure would be to analyse the spectrum, to identify the frequency in question, then design a filter around that frequency. For most real applications it's all a bit woolly: the frequencies move around and there's no easy way to distinguish noise from signal, so you have to use clever techniques and a bit of guesswork. However if you know you have a monotonic corruption then, yes, an FFT and a notch filter will probably do the trick.
You can analyse the signal with fft and design a filter with, among others, fir1, which I believe is part of the signal processing toolbox. If you don't have the signal processing toolbox you can do it 'by hand', as in transform to the frequency domain, remove the frequency(ies) you don't want (by zeroing the relevant elements of the frequency vector) and transform back to time domain. There's a tutorial on exactly that here.
The fft and fir1 functions are well documented: search the Mathworks site to get code examples to get you up and running.
To add to/ammend xenoclast's answer, filtering in the frequency domain may or may not work for you. There are many thorny issues with filtering in the frequency domain, some of which are covered here: http://blog.bjornroche.com/2012/08/why-eq-is-done-in-time-domain.html
One additional issue is that if you try to process your entire file at once, the "width" or Q of the filters will depend on the length of your file. This might work out for you, or it might not. If you have many files of different lengths, don't expect similar results this way.
To design your own IIR notch filter, you could use the RBJ audio filter cookbook. If you need help, I wrote up a tutorial here:
http://blog.bjornroche.com/2012/08/basic-audio-eqs.html
My tutorial uses bell/peaking filter, but it's easy to follow that and then replace it with a notch filter from RBJ.
One final note: assuming this is actually an audio signal in your .wav file, you can also use your ears to find and fix the problem frequencies:
Open the file in an audio editing program that lets you adjust filter settings in real-time (I am not sure if audacity lets you do this, but probably).
Use a "boost" or "parametric" filter set to a high gain and sweep the frequency setting until you hear the noise accentuated the most.
replace the boost filter with a notch filter of the same frequency. You may need to tweak the width to trade off noise elimination vs. signal preservation.
repete as needed (due to the many harmonics).
save the resulting file.
Of course, some audio editing apps have built-in harmonic noise reduction features that work especially well for 50/60 Hz noise.

Removing noise from wave audio file in MATLAB

I have two wave files, one is normal version, another one is distorted version. In distorted version, I hear a long beep like sound. Here are the frequency domain plots of normal and distorted version sounds. First one is normal, second one is distorted. notice the scales.
How do I go about this?
It's a bit hard to tell without using a marker or zooming in, but it seems you have a sinusoid inserted to your signal, which would explain the continuous beep you hear and the delta like function you have in the spectrum. Try to locate the noise frequency using the marker and filtering it using the filter design tool (type "fdatool" in the command line). I would go for a notch filter at the frequency of the noise, and if this doesn't work a high (~1000) order high pass FIR filter.
Good luck
Since you have the signal in frequency domain, you can also remove the noise there (with a simple threshold) and then you take inverse Fourier transform and you get the noise free signal in time domain.