OpenCores
URL https://opencores.org/ocsvn/viirf/viirf/trunk

Subversion Repositories viirf

[/] [viirf/] [trunk/] [src/] [config/] [export_sos_python_lists.m] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Muraer
% MIT License
2
%
3
% Copyright (c) 2017 Mario Mauerer
4
%
5
% Permission is hereby granted, free of charge, to any person obtaining a copy
6
% of this software and associated documentation files (the "Software"), to deal
7
% in the Software without restriction, including without limitation the rights
8
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
% copies of the Software, and to permit persons to whom the Software is
10
% furnished to do so, subject to the following conditions:
11
%
12
% The above copyright notice and this permission notice shall be included in all
13
% copies or substantial portions of the Software.
14
%
15
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
% SOFTWARE.
22
%
23
% VIIRF - Versatile IIR Filter
24
%
25
% This function writes matlab-generated SOS/G matrices into a file as python lists,
26
% Such that it can be utilized for the configuration-script IIR_Config.py.
27
%
28
% filename:
29
%   String of desired output-file. Don't forget ".txt"
30
% sos:
31
%   Matrix containing the SOS-coefficients. Size: [numsec 6]
32
% g:
33
%   Vector containing the section-gains and/or the final filter gain.
34
%   If the filter does not use any gains, this can be an empty vector.
35
% Example-usage:
36
%   export_sos_python_lists('LPFilt.txt', SOSDat, GDat);
37
 
38
function [] = export_sos_python_lists(filename, sos, g)
39
 
40
l = size(sos);
41
numsec = l(1);
42
 
43
fid = fopen(filename,'w'); % Create the file or overwrite an existing file
44
 
45
% First, the SOS-coefficients:
46
fprintf(fid, 'SOS = [');
47
for sec = 1:numsec
48
    fprintf(fid, '[');
49
    for c = 1:6
50
        fprintf(fid, '%.18f', sos(sec, c));
51
        if c < 6
52
            fprintf(fid, ', ');
53
        end
54
    end
55
    fprintf(fid, ']');
56
    if sec < numsec
57
        fprintf(fid, ',\n\t\t');
58
    end
59
end
60
fprintf(fid, ']');
61
 
62
% The G-Vector:
63
fprintf(fid, '\n\n');
64
fprintf(fid, 'G = [');
65
for sec = 1:length(g)
66
    fprintf(fid, '%.18f', g(sec));
67
    if sec < length(g)
68
        fprintf(fid, ', ');
69
    end
70
end
71
fprintf(fid, ']');
72
fclose(fid); % We're done
73
 
74
end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.