Audio distortion using IIR filters for an audio equalizer
6 次查看(过去 30 天)
显示 更早的评论
I am building an audio equalizer. I have created my filters using the ellip() function. Unfortunately I am still hearing distortion when I test the equalizer with music. I am currently using the sosfilt() functions to filter the audio. I tried filter() but there was way too much distortion and fitfilt() did not really help. Below is my filter function code for the low pass section. This filter has n = 6 coefficients. Any ideas how to improve my filtering so as to reduce distortion in the audio?
function filtered_audio = lpFilter(input_audio, Fs)
% Desired specifications
% pb_ripple
Rp = 1; % in dB
% stopband_attenuation
Rs = 50; % in dB
% passband frequencies
Wp = 500 / (Fs / 2); % remember to divide by (Fs / 2) to normalize
% stopband frequencies
Ws = 600 / (Fs / 2);
% Get minimum number of poles required
[n, Wn] = ellipord(Wp, Ws, Rp, Rs);
% Get zeros, poles and gain of filter with the specs
[z,p,k] = ellip(n, Rp, Rs, Wp);
% Convert to SOS matrix
[sos, gain] = zp2sos(z,p,k);
filtered_audio = sosfilt(sos, input_audio);
% maxVal = max(abs(filtered_audio));
% if maxVal > 1
% filtered_audio = filtered_audio / maxVal;
% end
end
0 个评论
回答(1 个)
Mathieu NOE
2023-11-13
hello
simple correction
% Convert to SOS matrix
[sos] = zp2sos(z,p,k);
filtered_audio = sosfilt(sos, input_audio);
and you get :
sos = Columns 1 through 5
0.0042342 -0.0029254 0.0042342 1 -1.7705
1 -1.6899 1 1 -1.8021
1 -1.787 1 1 -1.8323
Column 6
0.79926
0.90188
0.97547
when coding your way :
[sos, gain] = zp2sos(z,p,k);
sos = Columns 1 through 3
1 -0.6909 1
1 -1.6899 1
1 -1.787 1
Columns 4 through 6
1 -1.7705 0.79926
1 -1.8021 0.90188
1 -1.8323 0.97547
you get a SOS filter with a gain in the passband frequency range of +46 dB (roughly) instead of 0 dB
and then you get a huge clipping of the filtered output as it will exceed +/-1 range
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!