1clc; clear; close all;
2
3pkg load signal;
4pkg load control;
5
6sampleRate      = 48000;
7faustDSPtarget  = fullfile(                             ...
8                            '..',                       ...
9                            '..',                       ...
10                            'Faust',                    ...
11                            'testBeds',                 ...
12                            'wienerHammerstein2.dsp'     ...
13                            );
14dataTarget      = fullfile(                             ...
15                            '..',                       ...
16                            '..',                       ...
17                            'Faust',                    ...
18                            'testBeds',                 ...
19                            'wienerHammerstein2.mat'     ...
20                            );
21permission      = 'w';
22precision       = '%.18f';
23antialFIRTaps   = 16;
24windowFcn       = @chebwin;
25finalFrequency  = 23000;
26nBranches       = 20;
27
28[z, p, k]   = butter(2, 2 * 27.5 / sampleRate, 'high');
29[b, a]      = zp2tf(z, p, k);
30[SOS, G]    = zp2sos(z, p, k);
31
32antiAl      = zeros(nBranches, antialFIRTaps);
33
34for n = 1:nBranches
35
36    antiAl(n, :) = fir1(                                     ...
37                antialFIRTaps - 1,                           ...
38                (2.0 * finalFrequency) / (n * sampleRate),   ...
39                'lowpass',                                   ...
40                windowFcn(antialFIRTaps)                     ...
41                );
42
43endfor
44
45fileID = fopen(faustDSPtarget, permission);
46
47fprintf(fileID, ...
48            'fi = library("filters.lib");\nba = library("basics.lib");\n\n' ...
49            );
50
51for n = 1:nBranches
52
53    fprintf(fileID, ...
54            ['br' num2str(n) ' = fi.fir(('] ...
55            );
56
57    for t = 1:size(antiAl, 2)
58
59        fprintf(fileID, num2str(antiAl(n, t), precision));
60
61        if isequal(t, size(antiAl, 2))
62            fprintf(fileID, ')');
63        else
64            fprintf(fileID, ', ');
65         endif
66
67    endfor
68
69    fprintf(fileID, ...
70        [') : ^(_, ' num2str(n) ') : fi.tf22t(' ...
71        num2str(SOS(1), precision) ', ' ...
72        num2str(SOS(2), precision) ', ' ...
73        num2str(SOS(3), precision) ', ' ...
74        num2str(SOS(5), precision) ', ' ...
75        num2str(SOS(6), precision) ') : ' ...
76        ' *(_, ' num2str(G, precision) ') : ' ...
77        '*(_, brG)\n'
78        ] ...
79        );
80
81    fprintf(fileID,                                                         ...
82            ['with{\n'                                                   ...
83            '    brG= hslider(' ...
84            '"[' num2str(n - 1) ']Gain Adjust Branch ' num2str(n) ...
85            '[unit:dB][style:knob]",'   ...
86            '0, -120, 120, 0.1) : ba.db2linear;\n'                      ...
87            '};\n\n'                                                    ...
88            ]                                                           ...
89            );
90
91
92
93endfor
94
95fprintf(fileID, 'process = _ <: ');
96
97for n = 1:nBranches
98
99    fprintf(fileID, ['br' num2str(n)]);
100
101    if isequal(n, nBranches)
102        fprintf(fileID, ' :> _;\n');
103    else
104        fprintf(fileID, ', ');
105    endif
106
107endfor
108
109fclose(fileID);
110
111save(dataTarget, 'b', 'a', 'antialFIRTaps');