# Digital filtering

Discussion in 'Programmer's Corner' started by Cerkit, Jan 19, 2009.

1. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
Hi. I have been given some audio files and need to make filters in MATLAB to remove some intentionally added noise. I know how to make filters but not sure how to determine what to let through and what to block how can I identify this from the audio files??

2. ### mik3 Senior Member

Feb 4, 2008
4,846
63
I don't know how audio files work but set the filter cut off frequency at 20 kHz.

3. ### Dave Retired Moderator

Nov 17, 2003
6,960
144
Assuming you know how to characterise the noise, i.e. frequency components, and have an appropriate filter characterised in the frequency-domain, then you need to read in your audio file to Matlab (this will, depending on function, likely be the time-domain representation). Then you need to convert the time-domain representation to a frequency-domain representation via the Fourier Transform (function fft), and then apply your filter via simple multiplication ([fd_sig].*[filter]).

That is a basic model, however you specific case may be more involved.

Dave

4. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,546
835
Why would someone intentionally add noise to a digital audio file?

John

5. ### Dave Retired Moderator

Nov 17, 2003
6,960
144
John,

Aside from the example here of doing it for the purposes of creating an academic exercise to simulate a real audio filtering application, the most obvious real world example I can think of is audio watermarking which can be used in DRM, where the watermark is the embedded "noise".

Dave

6. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
Hi. I've made a butterworth IIR filter in matlab using fdatool. How can I apply it to a .wav audio file???

7. ### KL7AJ Senior Member

Nov 4, 2008
2,013
273
You need to convert the wav file to a flat data file. I think there's a matlab tool for doing just that.

eric

8. ### Dave Retired Moderator

Nov 17, 2003
6,960
144
Cerkit, I have merged this thread with your previous one as they are fundamentally asking the same question, and the advice I gave last time is applicable here.

Firstly, I am vaguely familiar with the fdatool function, can you tell us what the output from it is? For a Butterworth filter you want an [n x 1] matrix defining the magnitude Vs Frequency characteristic of the filter - in fact each element in the matrix will describe the magnitude at discrete frequencies so I imagine it will also give you a frequency resolution (i.e. the difference in frequency between adjacent elements in the matrix).

You then need to read in the wav-file using the wavread function, which will give you a time-domain description of the wav-file. Then you need to apply the Fourier Transform, function fft, to get the wav-file in the frequency-domain. You will need to ensure that the frequency elements in the frequency-domain representation of the wav-file correspond to the appropriate frequency elements in the Butterworth filter matrix. It is then a simple process of multiplying these two matrices, which performs the filtering process. Then apply the Inverse Fourier Transform, function ifft, to the multiplied matrix to get the filtered wav-file back in the time domain. Finally, use wavwrite to write the filtered time-domain representation of the wav-file into an actual Microsoft wav-file that you can listen to.

Dave

9. ### KL7AJ Senior Member

Nov 4, 2008
2,013
273

The addition of noise to digitized audio "dithering" is actually fairly standard practice. It adds some randomness the the least significant bit during the sampling process, which actually decreases "sampling distortion" in one of the great paradoxes of nature.

http://www.earlevel.com/Digital%20Audio/Dither.html

This is from my brother-in-law's web site, EarLevel Engineering. He's one of the co-creators of MIDI, by the way.

eric

eric

10. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
Hi. Ok so I have the Xk = fft(wxn) so Xk is my wav file in frequency domain. My filter is made of three butterworth filters cascaded and when I export the coefficients it creates a variable which is of type 1x3cell. I try multiplyng the XK and coeff but its not working. Do i have to change the coeffiecients somehow before multiplying??

11. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
Or rather I can export them individually as the SOS and scaling factor but dont know how to cascade them using code or apply the filter for that matter??