I need to design a smooting filter for computing the envelope of a signal. My specs in Matlab are
fs = 44100; % Sampling frequency of 44100 Hz
fpass = 2; % Passband edge frequency of 2 Hz
Wp = fpass / (fs/2); % Calculate normalized passband frequency
fstop = 5; % Stopband edge frequency of 5 Hz
Ws = fstop / (fs/2); % Calculate normalized stopband frequency
Rp_lin = 0.0001; % Max. passband ripple of 0.0001
Rp = 20 * log10(1+Rp_lin); % Calculate stopband ripple in dB
Rs = 10; % Min. stopband attenuation of 10dB
%% Design the elliptic lowpass filter
% Calculate the order of the elliptic lowpass filter
[N, W] = ellipord(Wp, Ws, Rp, Rs);
% Calculate the coefficients of the elliptic lowpass filter via Bilinear Transformation
[b_ellip_lp, a_ellip_lp] = ellip(N, Rp, Rs, W, 'low');
% Convert the filter coefficients to second-order sections
[sos_ellip_lp, g_ellip_lp] = tf2sos(b_ellip_lp, a_ellip_lp);
%% Distribute the gain equally over the sections
[N_sos, ~] = size(sos_ellip_lp);
sos_ellip_lp(:,1:3) = sos_ellip_lp(:,1:3) * (g_ellip_lp^(1/N_sos));
%% Normalize the coefficients
sos_ellip_lp = sos_ellip_lp / max(max(abs(sos_ellip_lp)));
%% Plot the 16-bit coefficients of the Elliptic low pass
% Quantize the coefficients for plotting
sos_ellip_lp_16bit = round(sos_ellip_lp * 2^(16-1));
figure(1)
freqz(sos_ellip_lp_16bit);
title('16-bit Elliptic low-pass filter');
I am designing an Elliptic filter with ellip. At first the gain is massive
After gain distribution over all biquads, it looks better.
After quantizing to 16 bit, I get a 10 dB gain!
I mean, I can just apply gain correction by trial and error. The filter is not adaptive and thus I can work with it. I would nevertheless like to not have these gain jumps. Filters for higher frequencies did not seem to have this issue.



@to notify users when you're replying to them (use<TAB>to cycle between names). – a concerned citizen Mar 04 '21 at 10:54