Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

## Fractional Delay Filters Using Farrow Structures

This example shows how to design digital fractional delay filters that are implemented using Farrow structures. Digital fractional delay (FD) filters are useful tools to fine-tune the sampling instants of signals. They are, for example, typically found in the synchronization of digital modems where the delay parameter varies over time. This example illustrates the Farrow structure, a popular method for implementing time-varying FIR FD filters.

Ideal Fractional Delay Filter

The ideal fractional delay filter is a linear phase allpass filter. Its impulse response is a time-shifted discrete sinc function that corresponds to a non causal filter. Since the impulse response is infinite, it can not be made causal by a finite shift in time. It is therefore non realizable and must be approximated.

The Farrow Structure

To compute the output of a fractional delay filter, we need to estimate the values of the input signal between the existing discrete-time samples. Special interpolation filters can be used to compute new sample values at arbitrary points. Among those, polynomial-based filters are of particular interest because a special structure - the Farrow structure - permits simple handling of coefficients. In particular, the tunability of the Farrow structure makes its well-suited for practical hardware implementations.

Maximally-Flat FIR Approximation (Lagrange Interpolation)

Lagrange interpolation is a time-domain approach that leads to a special case of polynomial-based filters. The output signal is approximated with a polynomial of degree M. The simplest case (M=1) corresponds to linear interpolation. Let's design and analyze several linear fractional delay filters that will split the unit delay by various fractions:

```h = repmat(dfilt.farrowlinearfd, [1 10]);
for d=0:9,
h(d+1) = dfilt.farrowlinearfd(d/10);
end
fvtool(h,'Color','white')
fvtool(h,'Analysis','PhaseDelay','Color','white')
```

For any value of the delay, the ideal filter should have both a flat magnitude response and a flat phase delay response. The approximation is correct only for the lowest frequencies. This means that in practice the signals need to be over-sampled for the linear FD to work correctly. Let's apply the filter is this case and overlay the delayed signal on top of the input of the filter:

```t = 0:9;
x = sin(2*pi*.1*t);
y1 = filter(h(2),x);
y2 = filter(h(5),x);
figure('Color','white')
stem(t,x);hold on;stem(t-.1,y1,'g','filled')
hold on;stem(t-.4,y2,'r','filled')
legend('Input Signal', 'Input Delayed by 0.1 Sample', ...
'Input Delayed by 0.4 Sample','Location','SouthWest')
```

Higher order Lagrange interpolators can be designed. Let's compare a cubic Lagrange interpolator with a linear one:

```d = .4; % Fractional Delay
hl1 = dfilt.farrowlinearfd(d) % Coefficients hard-coded in this structure
```
```
hl1 =

FilterStructure: 'Farrow Linear Fractional Delay'
Arithmetic: 'double'
FracDelay: 0.4
PersistentMemory: false

```

For the cubic Lagrange interpolator, let's use a fractional delay filter designer (FDESIGN.FRACDELAY):

```fd = fdesign.fracdelay(d,'N',3)
```
```
fd =

Response: 'Fractional Delay'
Specification: 'N'
Description: {'Filter Order'}
FracDelay: 0.4
NormalizedFrequency: true
FilterOrder: 3

```

The filter is actually designed by invoking the "design" function:

```hl2 = design(fd,'lagrange','FilterStructure','farrowfd')
```
```
hl2 =

FilterStructure: 'Farrow Fractional Delay'
Arithmetic: 'double'
Coefficients: [4x4 double]
FracDelay: 0.4
PersistentMemory: false

```
```hfvt = fvtool(hl1,hl2,'Color','white');
legend(hfvt, 'Linear', 'Cubic')
fvtool(hl1,hl2,'Analysis','PhaseDelay','Color','white')
```

Increasing the order of the polynomials slightly increase the useful bandwidth but when Lagrange approximation is used, the length of the differentiating filters i.e. the number of pieces of the impulse response (number of rows of the 'Coefficients' property) is equal to the length of the polynomials (number of columns of the 'Coefficients' property). Other design methods can be used to overcome this limitation.

Also notice how the phase delay of the third order filter is shifted from 0.4 to 1.4 samples at DC. Although both filters have a fractional delay of 0.4 samples, they have a respective nominal integer group delay equal to half the filter order (rounded towards zero).

Time-Varying Fractional Delay

The advantage of the Farrow structure over a Direct-Form FIR resides in its tunability. In many practical applications, the delay is time-varying. For each new delay we would need a new set of coefficients in the Direct-Form implementation but with a Farrow implementation, the polynomial coefficients remain constant.

```t = 0:9;
x = sin(2*pi*.1*t);
d = (t+1)/10;
ty = zeros(10,1);
y = zeros(10,1);
h = dfilt.farrowlinearfd;
h.PersistentMemory = true;
for i=1:10,
h.FracDelay = d(i);
ty(i) = t(i)-d(i);
y(i) = filter(h,x(i));
end
figure('Color','white')
stem(t,x);hold on;stem(ty,y,'r','filled')
legend('Input','Input Delayed by a Variable Delay','Location','SouthWest')
```