Audio distortion using IIR filters for an audio equalizer

11 ビュー (過去 30 日間)
Samuel Witt
Samuel Witt 2023 年 11 月 10 日
コメント済み: Samuel Witt 2023 年 11 月 16 日
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

回答 (1 件)

Mathieu NOE
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
  2 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 11 月 16 日
problem solved ?
Samuel Witt
Samuel Witt 2023 年 11 月 16 日
Yes. Thanks! It was more to do with filter states when I used the filter() function but got it thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by