1
$\begingroup$

I am attempting to implement a fractional delay line in Matlab which operates in real time, uses an object-oriented approach, and whose length can be modulated each time a sample is processed. I have already successfully implemented a fractional delay line, but I am having some trouble with the modulation step.

Below are some graphs of my current output:

Sawtooth Input Test

Shows how buffer is changing

As you can see, discontinuities occur when the current position approaches a part of the buffer which has not been encountered yet, due to the changing length of the buffer. I am wondering if anyone may know of a way to smooth these discontinuities out. My delay line uses linear interpolation at the moment, and I was thinking of using the first-order all pass filter interpolation method instead, but I am not sure if that would help at all, so I wanted to seek some advice first.

The end goal is to have this be a flanger effect for audio, so if anyone has expertise on this particular topic it would be greatly appreciated.

Some specifics for graph interpretation:

  • LFO period: 2 seconds

  • LFO shape: triangle

  • Base delay time: 8 ms

  • Max delay time: 18 ms

Process function for delay line:

function xDelayed = process(obj, x, L)

    % Current position index
    i = obj.currentPos;

    % Modulate delay time
    L_int = floor(L);
    obj.bufferLen = L_int+1;
    obj.delta = L-L_int;
    obj.delayLen = L;

    % Output delayed sample
    if i < obj.bufferLen
        xDelayed = obj.delta*obj.buffer(i)+(1-obj.delta)*obj.buffer(i+1);
    else
        xDelayed = obj.delta*obj.buffer(i)+(1-obj.delta)*obj.buffer(1);
    end

    % Save current sample to buffer
    obj.buffer(i) = x;

    % Increment delay line or go back to beginning if currently at
    % last position
    if i >= obj.bufferLen
        obj.currentPos = 1;
    else
        obj.currentPos = i+1;
    end
end

Any advice on how to handle these discontinuities or improve my implementation would be greatly appreciated. Thank you, and please let me know if you need any additional information. I apologize if what I posted here is not sufficient.

$\endgroup$
  • $\begingroup$ "real-time" and "MATLAB" together sound a bit funky to me. are you building a MATLAB user interface (that's real time)? but are you operating on a real-time signal? $\endgroup$ – robert bristow-johnson Apr 22 '19 at 21:41
  • $\begingroup$ probably the simplest good method to do precision delay is with a Kaiser-windowed sinc function. do you understand how to use the Nyquist-Shannon sampling and reconstruction theorem to accomplish a precision delay? $\endgroup$ – robert bristow-johnson Apr 22 '19 at 21:43
  • $\begingroup$ I am building code that works in real-time in MATLAB (by processing one sample at a time) that will eventually either have a user interface or be ported to C++. I have not heard of precision delays before, but I will look in to this. Thank you. $\endgroup$ – Big_Thin_Ker Apr 22 '19 at 21:47
  • $\begingroup$ i tried to get to a mathematically formal answer (that can be translated into code of any language) before. check that out, maybe. $\endgroup$ – robert bristow-johnson Apr 22 '19 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.