-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwgex5.m
60 lines (50 loc) · 2.08 KB
/
dwgex5.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
% Matlab script to test the digital waveguide class implementation.
%
% Gary Scavone, McGill University, 2022-2024.
clear; clf
N = 4000; % number of samples to compute
fs = 48000; % sample rate
T = 24; % temperature
% Include path to needed scripts
addpath( '../', '../geometries/' );
% Load a geometry file
fingering = 0;
[ boreData, holeData ] = keefeFlute();
% Create the digital waveguide class instance and add cylindrical segment
mydwg = dwg( fs, T );
mydwg.setDefaults(struct('fracType', 'lagrange', 'fracOrder', 5, 'lossType', 'shelf', ...
'lossOrder', 5, 'toneholeType', 'twoport'));
mydwg.setGeometry( boreData, holeData );
mydwg.setLossFlag( 1 ); % 0 = no losses, 1 = loss filtering
mydwg.setFracDelayFlag( 1 ); % 0 = no fractional delay, 1 = fractional delay
% Specify an unflanged open end modeled by a 2-zero, 1-pole digital filter
mydwg.setOutputEnd( 2, 2, 1 ); % 0 = closed; 1 = ideally open; 2 = open unflanged, 3 = open flanged
mydwg.setInputEnd( 1 ); % 0 = closed input; 1 = anechoic input (reflectance)
%mydwg.drawShape(); % draw a 3D representation of the geometry
%disp('paused ... hit key to continue'); pause
x = [1, zeros(1, N-1)]; % pressure traveling-wave impulse
r = mydwg.processInput(x); % reflection function (anechoic input)
clear mydwg;
t = (0:N-1) * 1000 / fs;
subplot(2, 1, 1)
plot(t, r, 'b');
xlim([0 15]);
% Compute reflectance and then input impedance
R = fft( r );
M = (N / 2) + 1;
R = R(1:M);
Zin = (1 + R) ./ (1 - R); % convert reflectance to impedance for cylindrical input
f = fs*(0:M-1)/(M-1)/2;
subplot(2, 1, 2)
plot(f, 20*log10(abs(Zin(1:M))), 'b');
plotTypes = [11 1];
% Compute TMM result for comparison
lossType = 2; % 0 = lossless, 1 = traditional losses, 2 = Zwikker-Kosten; 3 = Bessel function
endType = 1; % 0 = closed, 1 = unflanged, 2 = flanged, 3 = ideally open
f(1) = eps;
Zin = tmm( boreData, holeData, endType, f, lossType, T );
rzplot( f, Zin, plotTypes, true, true, [], 'r', true );
ylim( [-50 50] );
subplot(2, 1, 1)
legend('DWG', 'TMM')
title( 'Reflection function and input impedance of Keefe flute (lossy, unflanged Z_L)')