From e7816e9e63fc809c22b2a8cc8e239829dafb75d8 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Tue, 29 Aug 2023 18:50:53 +0300 Subject: [PATCH] Tools: Tune: dcblock: Fixes for Matlab compatibility The script can be run in both Matlab and Octave with these changes. Signed-off-by: Seppo Ingalsuo --- tools/tune/dcblock/dcblock_build_blob.m | 9 ++++----- tools/tune/dcblock/dcblock_plot_stepfn.m | 4 ++-- tools/tune/dcblock/dcblock_plot_transferfn.m | 4 ++-- tools/tune/dcblock/example_dcblock.m | 18 +++++++++--------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tools/tune/dcblock/dcblock_build_blob.m b/tools/tune/dcblock/dcblock_build_blob.m index 5abbfa80c53b..0b4293054f57 100644 --- a/tools/tune/dcblock/dcblock_build_blob.m +++ b/tools/tune/dcblock/dcblock_build_blob.m @@ -1,16 +1,15 @@ function blob8 = dcblock_build_blob(R_coeffs, endian, ipc_ver) %% Settings -bits_R = 32; %Q2.30 qy_R = 30; if nargin < 2 - endian = 'little' -endif + endian = 'little'; +end if nargin < 3 ipc_ver = 3; -endif +end %% Shift values for little/big endian switch lower(endian) @@ -44,7 +43,7 @@ j=j+4; end -endfunction +end function bytes = word2byte(word, sh) bytes = uint8(zeros(1,4)); diff --git a/tools/tune/dcblock/dcblock_plot_stepfn.m b/tools/tune/dcblock/dcblock_plot_stepfn.m index 724b4bcfcf40..e0c7c3d14db3 100644 --- a/tools/tune/dcblock/dcblock_plot_stepfn.m +++ b/tools/tune/dcblock/dcblock_plot_stepfn.m @@ -1,4 +1,4 @@ -function dcblock_plot_stepfn(R, fs); +function dcblock_plot_stepfn(R, fs) % Plot the step response of a DC Blocking Filter % For a DC Blocking filter: H(z) = (1-1/z)/(1 - R/z) % Therefore the coefficients are b = [1 -1], a = [1 -R] @@ -13,4 +13,4 @@ tstr = sprintf("DC Blocking Filter Step Response, R = %i", R); title(tstr); -endfunction +end diff --git a/tools/tune/dcblock/dcblock_plot_transferfn.m b/tools/tune/dcblock/dcblock_plot_transferfn.m index 85ef7c079d5e..513a291f666b 100644 --- a/tools/tune/dcblock/dcblock_plot_transferfn.m +++ b/tools/tune/dcblock/dcblock_plot_transferfn.m @@ -1,4 +1,4 @@ -function dcblock_plot_transferfn(R, fs); +function dcblock_plot_transferfn(R, fs) % Plot the transfer function. % For a DC Blocking filter: H(z) = (1-1/z)/(1 - R/z) % Therefore the coefficients are b = [1 -1], a = [1 -R] @@ -14,4 +14,4 @@ tstr = sprintf("DC Blocking Filter Frequency Response, R = %i", R); title(tstr); -endfunction +end diff --git a/tools/tune/dcblock/example_dcblock.m b/tools/tune/dcblock/example_dcblock.m index ff3d79e75a1b..df8500473369 100644 --- a/tools/tune/dcblock/example_dcblock.m +++ b/tools/tune/dcblock/example_dcblock.m @@ -1,13 +1,13 @@ -function example_dcblock(); +function example_dcblock() % Set the parameters here -tplg1_fn = "../../topology/topology1/m4/dcblock_coef_default.m4" % Control Bytes File -tplg2_fn = "../../topology/topology2/include/components/dcblock/default.conf" +tplg1_fn = "../../topology/topology1/m4/dcblock_coef_default.m4"; % Control Bytes File +tplg2_fn = "../../topology/topology2/include/components/dcblock/default.conf"; % Use those files with sof-ctl to update the component's configuration -blob3_fn = "../../ctl/ipc3/dcblock_coef.blob" % Blob binary file -alsa3_fn = "../../ctl/ipc3/dcblock_coef.txt" % ALSA CSV format file -blob4_fn = "../../ctl/ipc4/dcblock_coef.blob" % Blob binary file -alsa4_fn = "../../ctl/ipc4/dcblock_coef.txt" % ALSA CSV format file +blob3_fn = "../../ctl/ipc3/dcblock_coef.blob"; % Blob binary file +alsa3_fn = "../../ctl/ipc3/dcblock_coef.txt"; % ALSA CSV format file +blob4_fn = "../../ctl/ipc4/dcblock_coef.blob"; % Blob binary file +alsa4_fn = "../../ctl/ipc4/dcblock_coef.txt"; % ALSA CSV format file endian = "little"; R_coeffs = [0.98, 0.98, 0.98, 0.98, 0.98, 0.98, 0.98, 0.98]; @@ -28,11 +28,11 @@ % Plot Filter's Transfer Function and Step Response % As an example, plot the graphs of the first coefficient -fs = 48e3 +fs = 48e3; dcblock_plot_transferfn(R_coeffs(1), fs); figure dcblock_plot_stepfn(R_coeffs(1), fs); rmpath ./../common -endfunction +end