|
1 |
| -function varargout = freq_response_localwfs(X,xs,src,conf) |
2 |
| -%FREQ_RESPONSE_WFS simulates the frequency response for WFS at the given |
3 |
| -%listener position |
4 |
| -% |
5 |
| -% Usage: [S,f] = freq_response_wfs(X,xs,src,conf) |
6 |
| -% |
7 |
| -% Input parameters: |
8 |
| -% X - listener position / m |
9 |
| -% xs - position of virtual source / m |
10 |
| -% src - source type of the virtual source |
11 |
| -% 'pw' -plane wave |
12 |
| -% 'ps' - point source |
13 |
| -% 'fs' - focused source |
14 |
| -% conf - configuration struct (see SFS_config) |
15 |
| -% |
16 |
| -% Output parameters: |
17 |
| -% S - simulated frequency response |
18 |
| -% f - corresponding frequency axis / Hz |
19 |
| -% |
20 |
| -% FREQ_RESPONSE_WFS(X,xs,src,conf) simulates the frequency response of the |
21 |
| -% sound field at the given position X. The sound field is simulated for the |
22 |
| -% given source type (src) using a monochromatic WFS driving function. |
23 |
| -% |
24 |
| -% See also: sound_field_mono_wfs, sound_field_imp_wfs |
25 |
| - |
26 |
| -%***************************************************************************** |
| 1 | +function varargout = freq_response_localwfs(X,xs,src,conf) |
| 2 | +%FREQ_RESPONSE_WFS simulates the frequency response for WFS at the given |
| 3 | +%listener position |
| 4 | +% |
| 5 | +% Usage: [S,f] = freq_response_wfs(X,xs,src,conf) |
| 6 | +% |
| 7 | +% Input parameters: |
| 8 | +% X - listener position / m |
| 9 | +% xs - position of virtual source / m |
| 10 | +% src - source type of the virtual source |
| 11 | +% 'pw' -plane wave |
| 12 | +% 'ps' - point source |
| 13 | +% 'fs' - focused source |
| 14 | +% conf - configuration struct (see SFS_config) |
| 15 | +% |
| 16 | +% Output parameters: |
| 17 | +% S - simulated frequency response |
| 18 | +% f - corresponding frequency axis / Hz |
| 19 | +% |
| 20 | +% FREQ_RESPONSE_WFS(X,xs,src,conf) simulates the frequency response of the |
| 21 | +% sound field at the given position X. The sound field is simulated for the |
| 22 | +% given source type (src) using a monochromatic WFS driving function. |
| 23 | +% |
| 24 | +% See also: sound_field_mono_wfs, sound_field_imp_wfs |
| 25 | + |
| 26 | +%***************************************************************************** |
27 | 27 | % The MIT License (MIT) *
|
28 | 28 | % *
|
29 | 29 | % Copyright (c) 2010-2016 SFS Toolbox Team *
|
|
49 | 49 | % The SFS Toolbox allows to simulate and investigate sound field synthesis *
|
50 | 50 | % methods like wave field synthesis or higher order ambisonics. *
|
51 | 51 | % *
|
52 |
| -% http://sfstoolbox.org sfstoolbox@gmail.com * |
53 |
| -%***************************************************************************** |
54 |
| - |
55 |
| - |
56 |
| -%% ===== Checking of input parameters ================================== |
57 |
| -nargmin = 4; |
58 |
| -nargmax = 4; |
59 |
| -narginchk(nargmin,nargmax); |
60 |
| -isargposition(X); |
61 |
| -isargxs(xs); |
62 |
| -isargchar(src); |
63 |
| -isargstruct(conf); |
64 |
| - |
65 |
| - |
66 |
| -%% ===== Configuration ================================================== |
67 |
| -% Plotting result |
68 |
| -useplot = conf.plot.useplot; |
69 |
| -showprogress = conf.showprogress; |
70 |
| -% Disable progress bar for sound field function |
71 |
| -conf.showprogress = false; |
72 |
| -% Check type of secondary sources to use |
73 |
| -if strcmp('2D',conf.dimension) |
74 |
| - greens_function = 'ls'; |
75 |
| -else |
76 |
| - greens_function = 'ps'; |
77 |
| -end |
78 |
| - |
79 |
| - |
80 |
| -%% ===== Computation ==================================================== |
81 |
| -% Get the position of the loudspeakers |
82 |
| -x0_real = secondary_source_positions(conf); |
83 |
| -% Generate frequencies (10^0-10^5) |
84 |
| -f = logspace(0,5,500)'; |
85 |
| -% We want only frequencies until f = 20000Hz |
86 |
| -idx = find(f>20000,1); |
87 |
| -f = f(1:idx); |
88 |
| -S = zeros(size(f)); |
89 |
| -% Get the result for all frequencies |
90 |
| -for ii = 1:length(f) |
91 |
| - if showprogress, progress_bar(ii,length(f)); end |
92 |
| - [D, x0] = driving_function_mono_localwfs(x0_real,xs,src,f(ii),conf); |
93 |
| - % Calculate sound field at the listener position |
94 |
| - P = sound_field_mono(X(1),X(2),X(3),x0,greens_function,D,f(ii),conf); |
95 |
| - S(ii) = abs(P); |
96 |
| -end |
97 |
| - |
98 |
| -% Return parameter |
99 |
| -if nargout>0, varargout{1}=S; end |
100 |
| -if nargout>1, varargout{2}=f; end |
101 |
| - |
102 |
| - |
103 |
| -%% ===== Plotting ======================================================== |
104 |
| -if nargout==0 || useplot |
105 |
| - figure; |
106 |
| - figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit); |
107 |
| - semilogx(f,db(S)); |
108 |
| - set(gca,'XTick',[10 100 250 1000 5000 20000]); |
109 |
| - ylabel('Amplitude (dB)'); |
110 |
| - xlabel('Frequency (Hz)'); |
111 |
| -end |
| 52 | +% http://sfstoolbox.org sfstoolbox@gmail.com * |
| 53 | +%***************************************************************************** |
| 54 | + |
| 55 | + |
| 56 | +%% ===== Checking of input parameters ================================== |
| 57 | +nargmin = 4; |
| 58 | +nargmax = 4; |
| 59 | +narginchk(nargmin,nargmax); |
| 60 | +isargposition(X); |
| 61 | +isargxs(xs); |
| 62 | +isargchar(src); |
| 63 | +isargstruct(conf); |
| 64 | + |
| 65 | + |
| 66 | +%% ===== Configuration ================================================== |
| 67 | +% Plotting result |
| 68 | +useplot = conf.plot.useplot; |
| 69 | +showprogress = conf.showprogress; |
| 70 | +% Disable progress bar for sound field function |
| 71 | +conf.showprogress = false; |
| 72 | +% Check type of secondary sources to use |
| 73 | +if strcmp('2D',conf.dimension) |
| 74 | + greens_function = 'ls'; |
| 75 | +else |
| 76 | + greens_function = 'ps'; |
| 77 | +end |
| 78 | + |
| 79 | + |
| 80 | +%% ===== Computation ==================================================== |
| 81 | +% Get the position of the loudspeakers |
| 82 | +x0_real = secondary_source_positions(conf); |
| 83 | +% Generate frequencies (10^0-10^5) |
| 84 | +f = logspace(0,5,500)'; |
| 85 | +% We want only frequencies until f = 20000Hz |
| 86 | +idx = find(f>20000,1); |
| 87 | +f = f(1:idx); |
| 88 | +S = zeros(size(f)); |
| 89 | +% Get the result for all frequencies |
| 90 | +for ii = 1:length(f) |
| 91 | + if showprogress, progress_bar(ii,length(f)); end |
| 92 | + [D, x0] = driving_function_mono_localwfs(x0_real,xs,src,f(ii),conf); |
| 93 | + % Calculate sound field at the listener position |
| 94 | + P = sound_field_mono(X(1),X(2),X(3),x0,greens_function,D,f(ii),conf); |
| 95 | + S(ii) = abs(P); |
| 96 | +end |
| 97 | + |
| 98 | +% Return parameter |
| 99 | +if nargout>0, varargout{1}=S; end |
| 100 | +if nargout>1, varargout{2}=f; end |
| 101 | + |
| 102 | + |
| 103 | +%% ===== Plotting ======================================================== |
| 104 | +if nargout==0 || useplot |
| 105 | + figure; |
| 106 | + figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit); |
| 107 | + semilogx(f,db(S)); |
| 108 | + set(gca,'XTick',[10 100 250 1000 5000 20000]); |
| 109 | + ylabel('Amplitude (dB)'); |
| 110 | + xlabel('Frequency (Hz)'); |
| 111 | +end |
0 commit comments