getDocNode.m 3.67 KB
Newer Older
Jan-Gerrit Richter's avatar
Jan-Gerrit Richter committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function docNode = getDocNode(transFunc, inputImp, bsName)

xml = getXMLStrings();

docNode = com.mathworks.xml.XMLUtils.createDocument(xml.DocType);
docRootNode = docNode.getDocumentElement;
% docRootNode.setAttribute('attr_name','attr_value');

versionNode = docNode.createElement(xml.Version);
versionNode.appendChild...
    (docNode.createTextNode(xml.ActualVersion));
docRootNode.appendChild(versionNode);

mainNode = docNode.createElement(xml.SaveTypeQuadripole);
docRootNode.appendChild(mainNode);


quadMSNode = getQuadripoleMSNode(docNode, transFunc, inputImp, bsName);
mainNode.appendChild(quadMSNode);



function quadMSNode = getQuadripoleMSNode(docNode, transFunc, inputImp, bsName)

xml = getXMLStrings();

quadMSNode = docNode.createElement(xml.QuadripoleMeasured);

optionsNode = getOptionsNode(docNode, bsName);
[freqVecNode, transferFunctionNode, inputImpedanceNode] = lsData2DomNodes(docNode, transFunc, inputImp);

quadMSNode.appendChild(optionsNode);
quadMSNode.appendChild(freqVecNode);
quadMSNode.appendChild(transferFunctionNode);
quadMSNode.appendChild(inputImpedanceNode);


function optionsNode = getOptionsNode(docNode, bsName)

xml = getXMLStrings();

optionsNode = docNode.createElement(xml.Options);
nameNode = docNode.createElement(xml.Name);
nameNode.appendChild(docNode.createTextNode(bsName));
optionsNode.appendChild(nameNode);


function [freqVecNode, transferFunctionNode, inputImpedanceNode] = lsData2DomNodes(docNode, transFunc, inputImp)

fVec = transFunc.freqVector;
fVec2 = inputImp.freqVector;

Robert Henzel's avatar
Robert Henzel committed
53
54
55
56
57
58
59
60
61
62
if ~areIdenticalFreqVecs(fVec, fVec2)
    if(length(fVec) < length(fVec2))
        transFunc = ita_interpolate_spk(transFunc,inputImp.fftDegree);
    else 
        inputImp = ita_interpolate_spk(inputImp,transFunc.fftDegree);
    end
end

fVec = transFunc.freqVector;
fVec2 = inputImp.freqVector;
Jan-Gerrit Richter's avatar
Jan-Gerrit Richter committed
63
64
65
66
if ~areIdenticalFreqVecs(fVec, fVec2)
    error('Data files have no identical frequency vectors!')
end

Robert Henzel's avatar
Robert Henzel committed
67

Jan-Gerrit Richter's avatar
Jan-Gerrit Richter committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
transFunc = transFunc.freqData;
inputImp = inputImp.freqData;

freqVecNode = getFreqVecNode(docNode, fVec);
transferFunctionNode = getTransferFunctionNode(docNode, transFunc);
inputImpedanceNode = getInputImpedanceNode(docNode, inputImp);

function str = realArray2str(array)
str = mat2str(array);
str = strrep(str, '[', '');
str = strrep(str, ']', '');
str = strrep(str, ' ', ',');
str = strrep(str, ';', ',');

function [strReal, strImag] = cmplxArray2str(cmplxArray)

strReal = realArray2str(real(cmplxArray));
strImag = realArray2str(imag(cmplxArray));

function bool = areIdenticalFreqVecs(fVec1, fVec2)
bool = isequal(fVec1, fVec2);

function freqVecNode = getFreqVecNode(docNode, freqVec)
xml = getXMLStrings();

freqVecNode = docNode.createElement(xml.FrequencyList);
strFreqVec = realArray2str(freqVec);
freqVecNode.appendChild(docNode.createTextNode(strFreqVec));


function transferFunctionNode = getTransferFunctionNode(docNode, transFunc)
xml = getXMLStrings();
transferFunctionNode = docNode.createElement(xml.TransferFunction);

[realNode, imagNode] = getRealAndImagNode(docNode, transFunc);
transferFunctionNode.appendChild(realNode);
transferFunctionNode.appendChild(imagNode);

function inputImpNode = getInputImpedanceNode(docNode, inputImp)
xml = getXMLStrings();
inputImpNode = docNode.createElement(xml.InputImpedance);

[realNode, imagNode] = getRealAndImagNode(docNode, inputImp);
inputImpNode.appendChild(realNode);
inputImpNode.appendChild(imagNode);

function [realNode, imagNode] = getRealAndImagNode(docNode, cmplxArray)
xml = getXMLStrings();

realNode = docNode.createElement(xml.Real);
imagNode = docNode.createElement(xml.Imag);

[strReal, strImag] = cmplxArray2str(cmplxArray);

realNode.appendChild(docNode.createTextNode(strReal));
imagNode.appendChild(docNode.createTextNode(strImag));