Simulink Problem: Filter Designer producing noisy output.

2 views (last 30 days)
I'm trying to use the Filter Designer in the DSP System Toolbox in Simulink to create an EQ for an assignment. I've successfully done it in MATLAB and I'm trying to use the same sos filter I created in MATLAB by importing the variable from the MATLAB workspace but the output it creates is really noisy. Any suggestions on why this could be the case?
%% Bass Filter (Low-pass)
% Define filter specifications
Bass_Fpass = 270;
Bass_Fstop = 400;
Bass_Apass = 1;
Bass_Astop = 60;
fs = 44100;
fNyquist = fs/2;
% Calculate normalized frequencies
Bass_Wp = Bass_Fpass/fNyquist;
Bass_Ws = Bass_Fstop/fNyquist;
% Design filter
[Bass_nB, Bass_WnB] = buttord(Bass_Wp, Bass_Ws, Bass_Apass, Bass_Astop);
[Bass_num, Bass_den] = butter(Bass_nB, Bass_WnB);
% Analyze filter
fvtool(Bass_num, Bass_den, 'Fs', fs);
This functionality is not available on remote platforms.
% Load audio signal
signal = audioread('sample.wav');
% Play original signal
soundsc(signal, fs);
% Apply filter
y_bass = filter(Bass_num, Bass_den, signal);
soundsc(y_bass, fs);
% Convert to second-order sections for better numerical stability
[z, p, k] = butter(Bass_nB, Bass_WnB);
[sos_bass, g_bass] = zp2sos(z, p, k);
Bass_filter = dfilt.df2sos(sos_bass, g_bass);
% Compare original and SOS implementation
fvtool(Bass_num, Bass_den, Bass_filter, 'Fs', fs, 'Legend');
% Apply SOS filter and play
y2_bass = filter(Bass_filter, signal);
soundsc(y2_bass, fs);
  1 Comment
Mathieu NOE
Mathieu NOE on 9 May 2025
according to your script, your filter has unitary gain , but when I look at the fvtool Bode plot , the dc gain is "kolossal" (> 600 dB) whereas it should have a max modulus = 0 dB
so your output is probably completely distorted (saturation / clipping)

Sign in to comment.

Answers (1)

Hitesh
Hitesh on 9 May 2025
Edited: Hitesh on 9 May 2025
Hi Lui,
This issue of getting noisy output when importing your SOS filter into Simulink's Filter Designer might be due to following reasons:
  • Data Types Mismatch : MATLAB uses "double" as its default datatype whereas blocks in Simulink can be either single or even fixed-point by default, especially in DSP System Toolbox. You need to ensure that input signal and SOS coefficients are all set to double in Simulink.
  • Gain Application: In MATLAB, you have a separate "g_bass gain" scalar from "zp2sos" whereas in Simulink, you must multiply the output of the SOS filter by this gain if the block doesn't have a gain input. Add a "Gain" block after your filter and set it to "g_bass".
Kindly refer to the revised MATLAB code for better understanding of creating EQ using Filter Designer in the DSP System Toolbox using "tf2sos" which converts digital filter transfer function data to second-order sections form.
% Load audio signal
[signal, fs_signal] = audioread('sample-3s.wav');
signal = double(signal); % Ensure signal is double
if fs_signal ~= fs
error('Sample rate mismatch!');
end
% Play original signal
soundsc(signal, fs);
% Convert to second-order sections for better numerical stability
[sos_bass, g_bass] = tf2sos(Bass_num, Bass_den);
% Apply SOS filter and gain
y_bass = sosfilt(sos_bass, signal) * g_bass;
% Play filtered signal
soundsc(y_bass, fs);
% Compare original and SOS implementation
fvtool(Bass_num, Bass_den, sos_bass, 'Fs', fs, 'Legend');
% Export sos_bass and g_bass to workspace for Simulink use
assignin('base', 'sos_bass', sos_bass);
assignin('base', 'g_bass', g_bass);
For more information regarding "filterDesigner" and "tf2sos", kindly refer to the following MATLAB documentation:
If your issue still persists, kindly share your sample simulink model which results in noisy data.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!