%% Signal Delay Using Multitap Fractional Delay
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% Delay the input signal using the dsp.VariableFractionalDelay object. Each delay value is unique and can vary from sample to sample within a frame, and can vary across channels. You can compute multiple delayed versions of the same input signal concurrently by passing a delay input with the appropriate dimension.
%
% Consider the input to be a random signal with one channel and a frame size of 10. Apply a delay of 4.8 and 8.2 samples concurrently.

vfd = dsp.VariableFractionalDelay
in = randn(10,1)
delayVec = [4.8 8.2];
outcase1 = vfd(in,delayVec)

% Each channel in the output is delayed by 4.8 and 8.2 samples, respectively. The object uses the 'Linear' interpolation method to compute the delayed value. For more details, see 'Algorithms' in the dsp.VariableFractionalDelay object page.
%
% For the same delay vector, if the input has 2 channels, each element of the delay vector is applied on the corresponding channel in the input.

release(vfd);
in = randn(10,2)
outcase2 = vfd(in,delayVec)

%
% To compute multiple delayed versions of the two-dimensional input signal, pass the delay vector as a three-dimensional array. The third dimension contains the taps or delays to apply on the signal. If you pass a non-singleton third dimension (1-by-1-by-P), where P represents the number of taps, the same tap is applied across all the channels. Pass the delays [4.8 8.2] in the third dimension.

clear delayVec;
delayVec(1,1,1) = 4.8;
delayVec(1,1,2) = 8.2;
whos delayVec

% delayVec is a 1-by-1-by-2 array. Pass the two-dimensional input to the dsp.VariableFractionalDelay object with this delay vector.

release(vfd);
outcase3 = vfd(in,delayVec)
whos outcase3

% outcase3(:,:,1) represents the input signal delayed by 4.8 samples. outcase3(:,:,2) represents the input signal delayed by 8.2 samples. The same delay is applied across all the channels.
%
% In addition, if you pass a non-singleton second dimension (1-by-L-by-P), where L is the number of input channels, taps vary across channels. Apply the delay vectors [2.3 3.5] and [4.4 5.6] to compute the two delayed versions of the input signal.

clear delayVec;
delayVec(1,1,1) = 2.3;
delayVec(1,2,1) = 3.5;
delayVec(1,1,2) = 4.4;
delayVec(1,2,2) = 5.6;
whos delayVec
release(vfd);
outcase4 = vfd(in,delayVec)
whos outcase4

% outcase4(:,:,1) contains the input signal delayed by the vector [2.3 3.5]. outcase4(:,:,2) contains the input signal delayed by the vector [4.4 5.6].
%
% To vary the delay within a frame from sample to sample, the first dimension of the delay vector (N-by-1-by-P or N-by-L-by-P) must equal the frame size of the input (N-by-L). Pass a delay vector of size 10-by-1-by-2.

clear delayVec;
delayVec(:,1,1) = 3.1:0.1:4;
delayVec(:,1,2) = 0.1:0.1:1;
whos delayVec

release(vfd);
outcase5 = vfd(in,delayVec)

% Delay varies across each element in a channel. Same set of delay values apply across all channels. delayVec(:,1,1) applies to the first delayed signal and delayVec(:,1,2) applies to the second delayed signal.
% Copyright 2012 The MathWorks, Inc.