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

Combination of dummy_irs() and resampling of Matlab #132

Open
VeraE opened this issue Feb 16, 2017 · 3 comments
Open

Combination of dummy_irs() and resampling of Matlab #132

VeraE opened this issue Feb 16, 2017 · 3 comments
Labels

Comments

@VeraE
Copy link
Member

VeraE commented Feb 16, 2017

I encountered a problem when using dummy_irs() and Matlab's resample() function together. resample() does not work properly when the to be resampled vector does not contain some zeros at the start and end. This happens since we moved the impulse to the first sample in commit 4b50bd7.

An example where this matters: Simulating the impulse response of a linear WFS array with ir_wfs() leads to ripples in the frequency response below the aliasing frequency (in this case about 850 Hz). Setting conf.delayline.resampling = 'none' shows the expected behaviour.

SFS_start
SOFAstart

conf = SFS_config;
conf.N = 5000;
%secondary sources
conf.secondary_sources.geometry = 'line';
conf.secondary_sources.size = 10;
conf.secondary_sources.number = 51;
hrtf = dummy_irs(conf);
%wfs
conf.wfs.hprefhigh = 20000;
conf.xref = [0 -3 0];
%interpolation, delaying, weighting
conf.ir.hrirpredelay = 0; %pre-delay in samples
conf.delayline.resampling = 'matlab';
conf.delayline.resamplingfactor = 100;
conf.delayline.filter = 'integer';

[ir,x0] = ir_wfs(conf.xref,pi/2,[0 3 0],'ps',hrtf,conf);

%plot
N = length(ir(:,1));
f = (0:N-1)/N*conf.fs;
TF = fft(ir(:,1));
figure
    semilogx(f,db(abs(TF)))
    grid
    set(gca,'XLim',[20 conf.fs/2])
    xlabel('frequency / Hz'), ylabel('dB')

My suggestion would be to move the position of the dirac in dummy_irs() to e.g. sample 101 (from my experience the resample() problem is not noticable for this value) and then the additional delay can be substracted by setting conf.ir.hrirpredelay = 100 if this is important to the user for time alignment of stimuli. This procedure would be in accordance with the handling of predelays in HRTF/BRIRs.

@VeraE VeraE added the bug label Feb 16, 2017
@trettberg
Copy link
Contributor

Maybe the delay line should be responsible if it needs zero-padding?

@fietew
Copy link
Member

fietew commented Feb 17, 2017

Maybe the delay line should be responsible if it needs zero-padding?

Yes, if the signal needs to be delayed in order to achieve optimal interpolation, this should be done in the delay line. https://github.com/sfstoolbox/sfs-matlab/blob/master/SFS_general/delayline.m#L102 seems to be the right place for that. delay_offset has to be set accordingly.

@VeraE
Copy link
Member Author

VeraE commented Feb 17, 2017

As we discussed, if this is done properly, this means figuring out first how Matlab's resample() function is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants