Audio distortion using IIR filters for an audio equalizer

조회 수: 6 (최근 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 CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by