1
votes

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?

1
What are the values of f & fNorm prior to the call to butter()? What is the result of all(isfinite(funky))? - Max
f has value 44100 fNorm has value 0.0091 all(isfinite(funky)) has value [1, 1] - user1661303
I received a downvote. Anybody care to explain what I did wrong so that I can avoid doing it next time? I thought the question was clearly stated but maybe I was wrong. It's also not overly simplistic. I tried googling the answer for half an hour before posting. Please feel free to point out what I did wrong. - user1661303
I think you got a very good answer on meta. If you remove the last part (it's a different question) I'll vote to reopen this. - Stewie Griffin

1 Answers

1
votes

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.