sfstoolbox / sfs-matlab

SFS Toolbox for Matlab/Octave
https://sfs-matlab.readthedocs.io
MIT License
98 stars 39 forks source link

Problem with Secondary Source Selection and eps #68

Closed fietew closed 8 years ago

fietew commented 8 years ago

Try the following

conf = SFS_config;

conf.plot.realloudspeakers = true;

conf.tapwinlen = 1.0;
conf.secondary_sources.number = 36;
conf.secondary_sources.geometry = 'circular';

xs = [0, 3, 0];
x0 = secondary_source_positions(conf);
[x0, idx] = secondary_source_selection(x0, xs, 'ps');
x0 = secondary_source_tapering(x0, conf);
figure,
subplot(2,2,1);
draw_loudspeakers(x0, [1 1 0], conf);
xlim([-1.6,1.6]);
ylim([-1.6,1.6]);
title(sprintf('number of secondary sources: %d', size(x0,1))); 
subplot(2,2,2);
plot(x0(:,7), 'b');

xs = [0, -3, 0];
x0 = secondary_source_positions(conf);
x0 = secondary_source_selection(x0, xs, 'ps');
x0 = secondary_source_tapering(x0, conf);
subplot(2,2,3);
draw_loudspeakers(x0, [1 1 0], conf);
xlim([-1.6,1.6]);
ylim([-1.6,1.6]);
title(sprintf('number of secondary sources: %d', size(x0,1))); 
subplot(2,2,4);
plot(x0(:,7), 'r');

untitled

Although everything is symmetric, the number of selected sources is different. I think this is related to the usage of epsin https://github.com/sfstoolbox/sfs/blob/master/SFS_general/secondary_source_selection.m#L124 . While replacing it with 0 does make a difference, replacing it with -eps leads to the same result for both setups. Note, that the range for azimuth of the the selected secondary sources lies between phi_s +- 60 degrees, where phi_s is the azimuth of the virtual point source. Due to the azimuthal grid of 10 degrees resolution two secondary sources are exactly on this bound.

hagenw commented 8 years ago

I have applied your proposed change from eps to 0 for a pint source (L124) in the branch fix_ssd_selection. If I run your example the output looks identical to me.

hagenw commented 8 years ago

As I understood it this is the crucial part why this bug happens: "two secondary sources are exactly on this bound", correct? I can reproduce the behavior for -eps, do you know why this is working and can we somehow become independent of the sign?

fietew commented 8 years ago

I understood the eps as the maximum value, which may be added or substracted to the true result of an arithmetic operation due to numerical noise, i.e. finite numerical resolution. Assuming the true value of the scalar product is 0, its calculated value might be between +eps and -eps. I guess choosing -eps for comparison is the conversative approach, as all sources are selected, where the scalar product yields greater-equal -eps. However, there might be a source, where the true is smaller than 0 and which are selected erroneously due to this selection criterion.

hagenw commented 8 years ago

I think you are right and it is more conservative to use a negative value. I tested the same for ls as source and added now -2*eps as the criterium as for ls -eps was not enough.

hagenw commented 8 years ago

Btw, for focused sources and plane wave there was no error with your loudspeaker array, so I didn't changed the selection criterium.