-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
calculationsTwoMicISO105342.m
executable file
·154 lines (127 loc) · 4.87 KB
/
calculationsTwoMicISO105342.m
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function calculationsTwoMicISO105342(~,~,app)
% This function performs the calculations indicated in the standard BS EN ISO 10534-2:2001
%
% Copyright (C) Jose M. Requena Plens
% joreple@upv.es - jmrplens.github.io
% ===================================================================
% General parameters
% Sound speed (m/s)
c = app.c;
% Air density (kg/m3)
rho = app.rho;
% ===================================================================
% If calibrate data available
Calibrated = 0;
if app.ExtVar.ImpedanceTubeTwoMic.Calibrated && app.ExtVar.ImpedanceTubeTwoMic.NumMics==2
msg = 'Use calibration data?';
title = 'Calibration';
selection = uiconfirm(app.ALabUIFigure,msg,title,...
'Options',{'Yes, calibrate','No, without calibration'},...
'DefaultOption',1,'CancelOption',2);
if strcmp(selection,'Yes, calibrate')
Calibrated = 1;
end
end
% ===================================================================
% Signal data
% Calibration signals
if Calibrated
fscal = app.ExtVar.ImpedanceTubeTwoMic.Calibration.SampleRate;
S1I = app.ExtVar.ImpedanceTubeTwoMic.Calibration.S1I; % Measurement with configuration (I)
S2I = app.ExtVar.ImpedanceTubeTwoMic.Calibration.S2I;
excitationI = app.ExtVar.ImpedanceTubeTwoMic.Calibration.excitationI;
S1II = app.ExtVar.ImpedanceTubeTwoMic.Calibration.S1II; % Measurement with configuration (II)
S2II = app.ExtVar.ImpedanceTubeTwoMic.Calibration.S2II;
excitationII = app.ExtVar.ImpedanceTubeTwoMic.Calibration.excitationII;
end
% Measure signals (configuration (I))
fs = app.ExtVar.ImpedanceTubeTwoMic.SampleRate;
S1 = app.ExtVar.ImpedanceTubeTwoMic.Mic1;
S2 = app.ExtVar.ImpedanceTubeTwoMic.Mic2;
excitation = app.ExtVar.ImpedanceTubeTwoMic.Output;
% ===================================================================
% Geometry parameters
d = app.ExtVar.ImpedanceTubeTwoMic.d;
x1 = app.ExtVar.ImpedanceTubeTwoMic.x1;
s = app.ExtVar.ImpedanceTubeTwoMic.s;
% Frequency limits
[freqMin,freqMax] = TwoMicCalculateTubeLimits(app);
% ===================================================================
% Calculate the necessary transfer functions
nfft = app.ExtVar.ImpedanceTubeTwoMic.FFTRes;
% ========================
% From calibrate data
if Calibrated
% Impulse response
irS1I = impzest(excitationI,S1I);
irS2I = impzest(excitationI,S2I);
irS1II = impzest(excitationII,S1II);
irS2II = impzest(excitationII,S2II);
% Frequency response
H1I = freqz(irS1I,1,nfft,fscal);
H2I = freqz(irS2I,1,nfft,fscal);
H1II = freqz(irS1II,1,nfft,fscal);
H2II = freqz(irS2II,1,nfft,fscal);
% Transfer functions
H12I = H1I ./ H2I;
H12II = H1II ./ H2II;
% Calibration transfer function (ISO 10534-2:2001, equation (10), page 11)
Hc = (H12I .* H12II).^0.5;
end
% ========================
% From measure
% Impulse response
irS1 = impzest(excitation,S1);
irS2 = impzest(excitation,S2);
% Frequency response
[H1,freq] = freqz(irS1,1,nfft,fs);
H2 = freqz(irS2,1,nfft,fs);
% Transfer function (ISO 10534-2:2001, equation (14), page 12)
H12 = H2 ./ H1;
% Transfer function corrected (ISO 10534-2:2001, equation (13), page 11)
if Calibrated
H12 = H12 ./ Hc;
end
% Correction for tube attenuation (ISO 10534-2:2001, A.2.1.1, page 14)
if (x1-s) > 3*d
% Attenuation constant (ISO 10534-2:2001, equation (A.18), page 17)
switch app.ExtVar.ImpedanceTubeTwoMic.Shape
case 'Circular'
katen = 1.94*10^-2 * sqrt(freq) / (c*d);
case 'Square'
d_sq = 4*d^2;
katen = 1.94*10^-2 * sqrt(freq) / (c*d_sq);
end
else
katen = 0;
end
% Complex wave number (ISO 10534-2:2001, equation (A.1), page 14)
k = (2*pi*freq/c);
k0 = k - 1j*katen;
% Transfer function for the incident wave alone (ISO 10534-2:2001, equation (D.5), page 21)
HI = exp(-1j*k0*s);
% Transfer function for the reflected wave alone (ISO 10534-2:2001, equation (D.6), page 21)
HR = exp(1j*k0*s);
% ===================================================================
% Calculate acoustic parameters
% Reflection factor (ISO 10534-2:2001, equation (17), page 12)
r = (H12 - HI) ./ (HR - H12) .* exp(2*1j*k0*x1);
% Smoothing result
%r = smooth(freq,r);
% Sound absorption coefficient (ISO 10534-2:2001, equation (18), page 12)
alpha = 1 - abs(r).^2;
% Specific acoustic impedance (ISO 10534-2:2001, equation (19), page 12)
Z = ((1+r)./(1-r)) * rho*c;
% Store data
app.ExtVar.ImpedanceTubeTwoMic.Reflection = r;
app.ExtVar.ImpedanceTubeTwoMic.Absorption = alpha;
app.ExtVar.ImpedanceTubeTwoMic.Impedance = Z;
app.ExtVar.ImpedanceTubeTwoMic.FreqArray = freq;
app.ExtVar.ImpedanceTubeTwoMic.FreqMin = freqMin;
app.ExtVar.ImpedanceTubeTwoMic.FreqMax = freqMax;
app.ExtVar.ImpedanceTubeTwoMic.FR1 = H1;
app.ExtVar.ImpedanceTubeTwoMic.FR2 = H2;
app.ExtVar.ImpedanceTubeTwoMic.IR1 = irS1;
app.ExtVar.ImpedanceTubeTwoMic.IR2 = irS2;
% Create plots
CreateCenterPanelResultsTwoMic(app)