Skip to content

Commit f26d25e

Browse files
committed
Made README code copy and paste able
1 parent 47f834e commit f26d25e

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

README.md

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,54 @@ Before showing the different geometries, we start with some common settings. Fir
5353
and set the array size/diameter to 3m.
5454

5555
```Matlab
56-
conf = SFS_config;
56+
conf = SFS_config_example;
5757
conf.secondary_sources.size = 3;
5858
```
5959

6060
#### linear array
6161

6262
```Matlab
63+
conf = SFS_config_example;
6364
conf.secondary_sources.geometry = 'line'; % or 'linear'
6465
conf.secondary_sources.number = 21;
6566
x0 = secondary_source_positions(conf);
6667
figure;
6768
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
68-
draw_loudspeakers(x0);
69+
draw_loudspeakers(x0,[1 1 0],conf);
6970
axis([-2 2 -2 1]);
70-
print_png('img/secondary_sources_linear.png');
71+
%print_png('img/secondary_sources_linear.png');
7172
```
7273

7374
![Image](doc/img/secondary_sources_linear.png)
7475

7576
#### circular array
7677

7778
```Matlab
79+
conf = SFS_config_example;
7880
conf.secondary_sources.geometry = 'circle'; % or 'circular'
7981
conf.secondary_sources.number = 56;
8082
x0 = secondary_source_positions(conf);
8183
figure;
82-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
83-
draw_loudspeakers(x0);
84+
figsize(540,404,'px');
85+
draw_loudspeakers(x0,[1 1 0],conf);
8486
axis([-2 2 -2 2]);
85-
print_png('img/secondary_sources_circle.png');
87+
%print_png('img/secondary_sources_circle.png');
8688
```
8789

8890
![Image](doc/img/secondary_sources_circle.png)
8991

9092
#### box shaped array
9193

9294
```Matlab
95+
conf = SFS_config_example;
9396
conf.secondary_sources.geometry = 'box';
9497
conf.secondary_sources.number = 84;
9598
x0 = secondary_source_positions(conf);
9699
figure;
97-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
98-
draw_loudspeakers(x0);
100+
figsize(540,404,'px');
101+
draw_loudspeakers(x0,[0 0 1],conf);
99102
axis([-2 2 -2 2]);
100-
print_png('img/secondary_sources_box.png');
103+
%print_png('img/secondary_sources_box.png');
101104
```
102105

103106
![Image](doc/img/secondary_sources_box.png)
@@ -117,14 +120,17 @@ download the whole [data repository](http://github.com/sfstoolbox/data) to the
117120
<code>data</code> folder.
118121

119122
```Matlab
123+
conf = SFS_config_example;
124+
conf.secondary_sources.size = 3;
120125
conf.secondary_sources.geometry = 'sphere'; % or 'spherical'
126+
conf.secondary_sources.grid = 'equally_spaced_points';
121127
conf.secondary_sources.number = 225;
122128
x0 = secondary_source_positions(conf);
123129
figure;
124-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
125-
draw_loudspeakers(x0);
130+
figsize(540,404,'px');
131+
draw_loudspeakers(x0,[1 1 0],conf);
126132
axis([-2 2 -2 2]);
127-
print_png('img/secondary_sources_sphere.png');
133+
%print_png('img/secondary_sources_sphere.png');
128134
```
129135

130136
![Image](doc/img/secondary_sources_sphere.png)
@@ -143,6 +149,7 @@ the sound field from the given driving signals and secondary sources. For WFS
143149
the <code>r^2 cos(theta)</code> weights for integration on a sphere.
144150

145151
```Matlab
152+
conf = SFS_config_example;
146153
% create a stadium like shape by combining two half circles with two linear
147154
% arrays
148155
% first getting a full circle with 56 loudspeakers
@@ -177,10 +184,10 @@ conf.secondary_sources.x0 = [x01; x02; x03; x04];
177184
% simply return the defined x0 matrix
178185
x0 = secondary_source_positions(conf);
179186
figure;
180-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
181-
draw_loudspeakers(x0);
187+
figsize(540,404,'px');
188+
draw_loudspeakers(x0,[1 1 0],conf);
182189
axis([-2 2 -2.5 2.5]);
183-
print_png('img/secondary_sources_arbitrary.png');
190+
%print_png('img/secondary_sources_arbitrary.png');
184191
```
185192

186193
![Image](doc/img/secondary_sources_arbitrary.png)
@@ -194,10 +201,10 @@ symbols, for example the following will replot the last array.
194201
```Matlab
195202
conf.plot.realloudspeakers = true;
196203
figure;
197-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
204+
figsize(540,404,'px');
198205
draw_loudspeakers(x0,conf);
199206
axis([-2 2 -2.5 2.5]);
200-
print_png('img/secondary_sources_arbitrary_realloudspeakers.png');
207+
%print_png('img/secondary_sources_arbitrary_realloudspeakers.png');
201208
```
202209

203210
![Image](doc/img/secondary_sources_arbitrary_realloudspeakers.png)
@@ -226,18 +233,18 @@ The following will simulate the field of a virtual plane wave with a frequency
226233
of 800 Hz going into the direction of (0 -1 0) synthesized with 3D WFS.
227234

228235
```Matlab
229-
conf = SFS_config;
236+
conf = SFS_config_example;
230237
conf.dimension = '3D';
231238
conf.secondary_sources.size = 3;
232239
conf.secondary_sources.number = 225;
233240
conf.secondary_sources.geometry = 'sphere';
234241
% [P,x,y,z,x0,win] = sound_field_mono_wfs(X,Y,Z,xs,src,f,conf);
235242
sound_field_mono_wfs([-2 2],[-2 2],0,[0 -1 0],'pw',800,conf);
236-
print_png('img/sound_field_wfs_3d_xy.png');
243+
%print_png('img/sound_field_wfs_3d_xy.png');
237244
sound_field_mono_wfs([-2 2],0,[-2 2],[0 -1 0],'pw',800,conf);
238-
print_png('img/sound_field_wfs_3d_xz.png');
245+
%print_png('img/sound_field_wfs_3d_xz.png');
239246
sound_field_mono_wfs(0,[-2 2],[-2 2],[0 -1 0],'pw',800,conf);
240-
print_png('img/sound_field_wfs_3d_yz.png');
247+
%print_png('img/sound_field_wfs_3d_yz.png');
241248
```
242249

243250
![Image](doc/img/sound_field_wfs_3d_xy.png)
@@ -258,12 +265,12 @@ have to explicitly say if we want also plot the results, by
258265
<code>conf.plot.useplot = true;</code>.
259266

260267
```Matlab
261-
conf = SFS_config;
268+
conf = SFS_config_example;
262269
conf.dimension = '2.5D';
263270
conf.plot.useplot = 1;
264271
% [P,x,y,z,x0] = sound_field_mono_wfs(X,Y,Z,xs,src,f,conf);
265272
[P,x,y,z,x0] = sound_field_mono_wfs([-2 2],[-2 2],0,[0 2.5 0],'ps',800,conf);
266-
print_png('img/sound_field_wfs_25d.png');
273+
%print_png('img/sound_field_wfs_25d.png');
267274
```
268275

269276
![Image](doc/img/sound_field_wfs_25d.png)
@@ -281,7 +288,7 @@ x0_all = secondary_source_positions(conf);
281288
x0_all(:,7) = zeros(1,size(x0_all,1));
282289
x0_all(idx,7) = x0(:,7);
283290
plot_sound_field(P,x,y,z,x0_all,conf);
284-
print_png('img/sound_field_wfs_25d_with_all_sources.png');
291+
%print_png('img/sound_field_wfs_25d_with_all_sources.png');
285292
```
286293

287294
![Image](doc/img/sound_field_wfs_25d_with_all_sources.png)
@@ -293,11 +300,11 @@ In the following we will simulate the field of a virtual plane wave with a frequ
293300
of 800 Hz traveling into the direction (0 -1 0), synthesized with 2.5D NFC-HOA.
294301

295302
```Matlab
296-
conf = SFS_config;
303+
conf = SFS_config_example;
297304
conf.dimension = '2.5D';
298305
% sound_field_mono_nfchoa(X,Y,Z,xs,src,f,conf);
299306
sound_field_mono_nfchoa([-2 2],[-2 2],0,[0 -1 0],'pw',800,conf);
300-
print_png('img/sound_field_nfchoa_25d.png');
307+
%print_png('img/sound_field_nfchoa_25d.png');
301308
```
302309

303310
![Image](doc/img/sound_field_nfchoa_25d.png)
@@ -311,10 +318,11 @@ single secondary sources to the resulting sound field. With these function you
311318
can for example easily simulate a stereophonic setup.
312319

313320
```Matlab
321+
conf = SFS_config_example;
314322
x0 = [-1 2 0 0 -1 0 1;1 2 0 0 -1 0 1];
315323
% [P,x,y,z] = sound_field_mono(X,Y,Z,x0,src,D,f,conf)
316-
sound_field_mono([-2 2],[-1 3],0,x0,'ps',[1 1],800)
317-
print_png('img/sound_field_stereo.png');
324+
sound_field_mono([-2 2],[-1 3],0,x0,'ps',[1 1],800,conf)
325+
%print_png('img/sound_field_stereo.png');
318326
```
319327
![Image](doc/img/sound_field_stereo.png)
320328

@@ -328,12 +336,12 @@ In the following we will create a snapshot in time after 200 samples for a broad
328336
virtual point source placed at (0 2 0) m for 2.5D NFC-HOA.
329337

330338
```Matlab
331-
conf = SFS_config;
339+
conf = SFS_config_example;
332340
conf.dimension = '2.5D';
333341
conf.plot.useplot = true;
334342
% sound_field_imp_nfchoa(X,Y,Z,xs,src,t,conf)
335343
[p,x,y,z,x0] = sound_field_imp_nfchoa([-2 2],[-2 2],0,[0 2 0],'ps',200,conf);
336-
print_png('img/sound_field_imp_nfchoa_25d.png');
344+
%print_png('img/sound_field_imp_nfchoa_25d.png');
337345
```
338346

339347
![Image](doc/img/sound_field_imp_nfchoa_25d.png)
@@ -348,7 +356,7 @@ We change also the color map to the Matlab default one.
348356
conf.plot.usedb = true;
349357
conf.plot.colormap = 'jet';
350358
plot_sound_field(p,x,y,z,x0,conf);
351-
print_png('img/sound_field_imp_nfchoa_25d_dB.png');
359+
%print_png('img/sound_field_imp_nfchoa_25d_dB.png');
352360
```
353361

354362
![Image](doc/img/sound_field_imp_nfchoa_25d_dB.png)
@@ -382,28 +390,28 @@ two available angles will be applied. Afterwards a noise signal is created and c
382390
with the impulse response by the <code>auralize_ir()</code> function.
383391

384392
```Matlab
385-
conf = SFS_config;
386-
irs = read_irs('QU_KEMAR_anechoic_3m.mat');
393+
conf = SFS_config_example;
394+
irs = read_irs('QU_KEMAR_anechoic_3m.mat',conf);
387395
ir = get_ir(irs,[rad(30) 0 3]);
388396
nsig = randn(44100,1);
389-
sig = auralize_ir(ir,nsig);
397+
sig = auralize_ir(ir,nsig,1,conf);
390398
sound(sig,conf.fs);
391399
```
392400

393401
To simulate the same source as a virtual point source synthesized by WFS and a
394402
circular array with a diameter of 3 m, you have to do the following.
395403

396404
```Matlab
397-
conf = SFS_config;
405+
conf = SFS_config_example;
398406
conf.secondary_sources.size = 3;
399407
conf.secondary_sources.number = 56;
400408
conf.secondary_sources.geometry = 'circle';
401409
conf.dimension = '2.5D';
402-
irs = read_irs('QU_KEMAR_anechoic_3m.mat');
410+
irs = read_irs('QU_KEMAR_anechoic_3m.mat',conf);
403411
% ir = ir_wfs(X,phi,xs,src,irs,conf);
404412
ir = ir_wfs([0 0 0],pi/2,[0 3 0],'ps',irs,conf);
405413
nsig = randn(44100,1);
406-
sig = auralize_ir(ir,nsig);
414+
sig = auralize_ir(ir,nsig,1,conf);
407415
```
408416

409417
Binaural simulations are also a nice way to investigate the frequency response
@@ -414,25 +422,25 @@ expected aliasing frequency of the system (above these frequency the spectrum
414422
becomes very noise as you can see in the figure).
415423

416424
```Matlab
417-
conf = SFS_config;
425+
conf = SFS_config_example;
418426
conf.ir.usehcomp = 0;
419427
conf.wfs.usehpre = 0;
420428
irs = dummy_irs;
421429
[ir1,x0] = ir_wfs([0 0 0],pi/2,[0 2.5 0],'ps',irs,conf);
422430
conf.wfs.usehpre = 1;
423-
conf.wfs.hprefhigh = aliasing_frequency(x0);
431+
conf.wfs.hprefhigh = aliasing_frequency(x0,conf);
424432
ir2 = ir_wfs([0 0 0],pi/2,[0 2.5 0],'ps',irs,conf);
425-
[a1,p,f] = easyfft(ir1(:,1)./max(abs(ir1(:,1))));
426-
a2 = easyfft(ir2(:,1)./max(abs(ir2(:,1))));
433+
[a1,p,f] = easyfft(ir1(:,1)./max(abs(ir1(:,1))),conf);
434+
a2 = easyfft(ir2(:,1)./max(abs(ir2(:,1))),conf);
427435
figure;
428-
figsize(conf.plot.size(1),conf.plot.size(2),conf.plot.size_unit);
436+
figsize(540,404,'px');
429437
semilogx(f,20*log10(a1),'-b',f,20*log10(a2),'-r');
430438
axis([10 20000 -80 -40]);
431439
set(gca,'XTick',[10 100 250 1000 5000 20000]);
432440
legend('w/o pre-filter','w pre-filter');
433441
xlabel('frequency / Hz');
434442
ylabel('magnitude / dB');
435-
print_png('img/impulse_response_wfs_25d.png');
443+
%print_png('img/impulse_response_wfs_25d.png');
436444
```
437445

438446
![Image](doc/img/impulse_response_wfs_25d.png)
@@ -443,7 +451,8 @@ frequency range will be affected.
443451

444452
```Matlab
445453
freq_response_wfs([0 0 0],[0 2.5 0],'ps',conf);
446-
print_png('img/impulse_response_wfs_25d_mono.png');
454+
axis([10 20000 -20 20]);
455+
%print_png('img/impulse_response_wfs_25d_mono.png');
447456
```
448457

449458
![Image](doc/img/impulse_response_wfs_25d_mono.png)
@@ -460,6 +469,7 @@ responses used by the SoundScape Renderer.
460469
All functions regarding the SSR are stored in <code>SFS_ssr</code>.
461470

462471
```Matlab
472+
conf = SFS_config_example;
463473
brs = ssr_brs_wfs(X,phi,xs,src,irs,conf);
464474
wavwrite(brs,fs,16,'brs_set_for_SSR.wav');
465475
```
@@ -490,7 +500,7 @@ you cannot do the plotting to png afterwards like in Matlab, but have to specify
490500
the output file before. Note, that the same will work with Matlab.
491501

492502
```Matlab
493-
conf = SFS_config;
503+
conf = SFS_config_example;
494504
conf.plot.colormap = 'gray';
495505
conf.plot.usegnuplot = 1;
496506
conf.plot.file = 'img/sound_field_nfchoa_25d_gnuplot.png';

0 commit comments

Comments
 (0)