function showEQcoefficients(options) % Show filter coefficients as stem plots. % Only the provided coefficient arrays (n1, n2, n3) are shown, % each in its own subplot. The y-axis is scaled to [-1, 1]. arguments options.n1 = []; options.n2 = []; options.n3 = []; options.fignum (1,1) double = NaN; % Default: create new figure if NaN options.displayname (1,:) char = ''; % Default: empty string options.color = [0.2157, 0.4941, 0.7216]; options.clf = 0; % Clear figure before plotting if set to 1 end % Determine the figure number to use or create a new one. if isnan(options.fignum) fig = figure; else fig = figure(options.fignum); end if options.clf clf(fig); end hold on ax = gca; N = numel(ax.Children); % Set up a colormap for consistent coloring. cmap = linspecer(8); options.color = cmap(mod(N, size(cmap, 1)) + 1, :); % Build cell arrays for coefficients and their corresponding titles. coeffs = {}; titles = {}; if ~isempty(options.n1) coeffs{end+1} = options.n1; titles{end+1} = sprintf('1st order Filter Coefficients: %d', numel(options.n1)); end if ~isempty(options.n2) coeffs{end+1} = options.n2; titles{end+1} = sprintf('2nd order Filter Coefficients: %d', numel(options.n2)); end if ~isempty(options.n3) coeffs{end+1} = options.n3; titles{end+1} = sprintf('3rd order Filter Coefficients: %d', numel(options.n3)); end numSubplots = numel(coeffs); for i = 1:numSubplots subplot(1, numSubplots, i); stem(coeffs{i}, 'Color', options.color, 'LineWidth', 0.1, ... 'Marker', '.', 'MarkerSize', 1); title(titles{i}); ylim([-1, 1]); % Set y-axis limits to [-1, 1] grid on; grid minor; xlabel('Coefficient Index'); ylabel('Amplitude'); end sgtitle('Filter Coefficients'); % Overall title for the figure end