Question

I'm doing some audio processing. I've been able to load some audiofiles into MATLAB, play them, mix them and synthesize signals.

Now, however, I want to extract the base similar to an equalizer or a low-pass filter in an audio editing program. I know MATLAB has a lot of filters and built-in filter design tools; I just want to add a simple low-pass filter, though. I found this guide: http://www.aquaphoenix.com/lecture/matlab10/page4.html

f = 44100;
n = [1:f];
note_a = 440;
note_csharp = 554.365;
note_e = 659.255;
chord_a = sin(2*pi*(note_a/f)*n)+sin(2*pi*(note_csharp/f)*n)+sin(2*pi*(note_e/f)*n);
fNorm = 200 / (f/2);
[b,a] = butter(10, fNorm, 'low');
chords_low = filtfilt(b, a, chord_a);

I get no error, but all the values in the output of the filter is NaN. Why is that? The song is in stereo, could that be it?

Was it helpful?

Solution

The order of your filter is too high for the design type with a cutoff frequency that low, so you get numerical problems. To make a quick fix, reduce the order of your Butterworth filter to something a little lower than 10. An 8th order filer works for your design, or raising the cutoff frequency also results in real valued output.

If you want a filter with the frequency response specified by your design, you need to cascade lower order sections. See a detailed old answer I made for information on how to go about this. The tf2sos function is your friend here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top