-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample8.m
86 lines (75 loc) · 2.78 KB
/
example8.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
% A matlab script used to compare the lossy wavenumber Gamma and
% characteristic impedance Zc for different bore radii. Useful to see range
% of validity for different approximations
%
% by Champ Darabundit, McGill University, 2023
clear all; close all; clc; warning('off')
% Evaluation frequencies
N = 2^11; % Number of evaluation points
fs = 48e3; % Sampling frequency, evaluate up to Nyquist
f = (0:N/2)*(fs/N);
T = 20; % temperature (C)
% Include path needed to script
addpath('../')
% Get physical constants based on temperature
[c, rho, gamma, lv, Pr] = thermoConstants( T );
k = (2*pi*f)./c; % Compute the wavenumber
% Radii to compare and initial characteristic impedance
ra = [5e-3, 5e-4, 5e-5, 5e-6];
Zc = rho.*c./(pi.*ra.^2);
% Linestyle for plot
ls = {'--', ':', '-'};
for n = 1:4
% Keep track of viscous boundary-layer ratio to see range of validity
% for different approximations
rv = ra(n)*sqrt(abs(k/lv));
figure()
for lossType = 3:-1:1
% Do loss calculations
[G, Zc] = sectionLosses( ra(n), ra(n), 0, f, T, lossType);
% If Zc is scalar, multiply by ones for the plot
if numel(Zc) == 1
Zc = ones(size(f)).*Zc;
end
% Plot and compare different loss approximations
subplot(221)
plot(f, real(G), LineStyle=ls{lossType}, LineWidth=2)
hold on
legend('3: Bessel.', '2: ZK Approx.', '1: TMM Approx.', Location='best')
grid on
xlim([0, fs/2])
xlabel('Frequency (Hz)')
ylabel('\Re\{\Gamma\}')
title('Lossy Wavenumer \Gamma')
subplot(223)
plot(f, imag(G), LineStyle=ls{lossType}, LineWidth=2)
hold on
legend('3: Bessel.', '2: ZK Approx.', '1: TMM Approx.', Location='best')
grid on
xlim([0, fs/2])
xlabel('Frequency (Hz)')
ylabel('\Im\{\Gamma\}')
title('Lossy Wavenumer \Gamma')
subplot(222)
plot(f, real(Zc), LineStyle=ls{lossType}, LineWidth=2)
hold on
legend('3: Bessel.', '2: ZK Approx.', '1: TMM Approx.', Location='best')
grid on
xlim([0, fs/2])
xlabel('Frequency (Hz)')
ylabel('\Re\{Z_c\}')
title('Char. Impedance Z_c')
subplot(224)
plot(f, imag(Zc), LineStyle=ls{lossType}, LineWidth=2)
hold on
legend('3: Bessel.', '2: ZK Approx.', '1: TMM Approx.', Location='best')
grid on
xlim([0, fs/2])
xlabel('Frequency (Hz)')
ylabel('\Im\{Z_c\}')
title('Char. Impedance Z_c')
end
% Title for each radii comparison
sgtitle("Loss Comparison: " + sprintf("R = 5e{-%i} m", n+2) + ", r_v \in " + sprintf("[%.2f, %.2f]", min(rv(rv > 0)), max(rv)))
%saveas(gcf, sprintf("5e-%i.png", n+2))
end