Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove conf.N setting #90

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions SFS_ir/ir_correct_distance.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%
% IR_CORRECT_DISTANCE(ir,ir_distance,r,conf) weights and delays the given
% impulse responses, that they are conform with the specified distance r.
% The impulse responses are zero-padded to length conf.N.
% The impulse responses are zero-padded to not loose information.
%
% See also: get_ir

Expand Down Expand Up @@ -55,32 +55,17 @@
%% ===== Configuration ==================================================
c = conf.c;
fs = conf.fs;
useoriglength = conf.ir.useoriglength;
N = conf.N;


%% ===== Computation ====================================================
% Append zeros at the end of the impulse responses to reach a length of N
ir_origlength = size(ir,3);
ir = cat(3,ir,zeros(size(ir,1),size(ir,2),N-ir_origlength));
% Append zeros at the beginning of the impulse responses corresponding to
% its maximum radius
if ~useoriglength
zero_padding = ceil(ir_distance/c*fs); % / samples
else
zero_padding = 0;
end
% Time delay to ensure zeros before the maximum radius
offset = ceil(ir_distance/c*fs); % / samples
% Time delay of the source (at the listener position)
delay = (r-ir_distance)/c*fs; % / samples
% Amplitude weighting (point source model)
% This gives weight=1 for r==ir_distance
weight = ir_distance./r;
% Check if impulse responses are long enough compared to intended delay
if conf.N-(zero_padding+delay)<ir_origlength
error(['%s: Choose a larger conf.N value, otherwise you will '...
'lose samples from the original impulse response.'],...
upper(mfilename));
end
% Make sure impulse response is long enough for the specified delay
ir = cat(3,ir,zeros(size(ir,1),size(ir,2),max(ceil(delay+offset))));
% Apply delay and weighting
ir = delayline(ir,[delay+zero_padding; delay+zero_padding], ...
[weight; weight],conf);
ir = delayline(ir,[delay+offset; delay+offset],[weight; weight],conf);
5 changes: 4 additions & 1 deletion SFS_time_domain/driving_function_imp_nfchoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@

%% ===== Configuration ==================================================
nls = size(x0,1);
N = conf.N;
X0 = conf.secondary_sources.center;
% Length of driving signal (to which the driving signal is zero padded
% before the filter)
N = 2048;


%% ===== Computation =====================================================
% Generate stimulus pusle
Expand Down
21 changes: 8 additions & 13 deletions SFS_time_domain/driving_function_imp_wfs.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@

%% ===== Configuration ==================================================
fs = conf.fs;
N = conf.N;
c = conf.c;
t0 = conf.wfs.t0;

Expand Down Expand Up @@ -112,17 +111,12 @@
if strcmp('system',t0)
% Set minimum delay to 0, in order to begin always at t=1 with the first
% wave front at any secondary source
delay = delay - min(delay);
delay = delay - min(delay); % / s
% Return extra offset due to prefilter
delay_offset = prefilter_delay;
delay_offset = prefilter_delay; % / s
elseif strcmp('source',t0)
% Add extra delay to ensure causality at all secondary sources (delay>0)
[diameter,center] = secondary_source_diameter(conf);
t0 = diameter/c;
if (ceil((max(delay)+t0)*fs) - 1 ) > N
% This is a lot more likely to happen.
warning('conf.N = %i is too short for requested source.',N);
end
if strcmp('fs',src)
% Reject focused source that's too far away
% (this will only happen for unbounded listening arrays.)
Expand All @@ -132,19 +126,20 @@
'spanned by the array diameter.'],upper(mfilename));
end
end
delay = delay + t0;
delay = delay + diameter/c; % / s
% Return extra added delay. This is can be used to ensure that the virtual
% source always starts at t = 0.
delay_offset = t0 + prefilter_delay;
delay_offset = diameter/c + prefilter_delay; % / s
else
error('%s: t0 needs to be "system" or "source" and not "%s".', ...
upper(mfilename),t0);
end
% Append zeros at the end of the driving function. This is necessary, because
% the delayline function cuts into the end of the driving signals in order to
% delay them. NOTE: this can be changed by the conf.N setting
d_proto = repmat([row_vector(pulse) zeros(1,N-length(pulse))]',1,size(x0,1));
% delay them.
zero_padding = zeros(1,ceil(max(delay)*fs));
d_proto = repmat([row_vector(pulse) zero_padding]',1,size(x0,1));
% Shift and weight prototype driving function
[d, delayline_delay] = delayline(d_proto,delay*fs,weight,conf);
[d,delayline_delay] = delayline(d_proto,delay*fs,weight,conf);
% Add delay offset of delayline
delay_offset = delay_offset + delayline_delay;
1 change: 0 additions & 1 deletion SFS_time_domain/localwfs_findhpref.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@


%% ===== Variables ======================================================
N = conf.N;
irs = dummy_irs(N,conf); % Impulse responses
fs = conf.fs; % Sampling rate
dimension = conf.dimension; % dimensionality
Expand Down
6 changes: 3 additions & 3 deletions SFS_time_domain/wfs_preequalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
% Delay in s added by filter
delay = conf.wfs.hpreFIRorder/2 / fs;
elseif strcmp('IIR',conf.wfs.hpretype)
if len_ir == 1
if len_ir < 2048
% Happens when called from driving_function_imp_wfs()
% Zeropadding to length conf.N
ir = [ir; zeros(conf.N-1,size(ir,2))];
% Zeropadding to 2048 (IIR filter needs infinite long signal)
ir = [ir; zeros(2048-len_ir,size(ir,2))];
end
% Get IIR filter
hpre = wfs_iir_prefilter(conf);
Expand Down