# Understanding a lowpass - comb filter implementation

I try to understand the implementation of the low-pass comb filter of the Freeverb reverberation algorithm:

https://ccrma.stanford.edu/~jos/pasp/Lowpass_Feedback_Comb_Filter.html

The original implementation is as follows:

inline float comb::process(float input)
{
float output;
output = buffer[bufidx];
filterstore = (output*damp2) + (filterstore*damp1);
buffer[bufidx] = input + (filterstore*feedback);
if(++bufidx>=bufsize) bufidx = 0;
return output;
}


I drew the closed loop of this algorithm:

Inspection of comb.h in the Freeverb source shows that Freeverb's comb'' filter is more specifically a lowpass-feedback-comb filter (LBCF4.11--§2.6.5). It is constructed using a delay line whose output is lowpass-filtered and summed with the delay-line's input. The particular lowpass used in Freeverb is a unity-gain one-pole lowpass having the transfer function

$$\displaystyle H(z) = \frac{1-d}{1-d\,z^{-1}}.$$

When $$d=0$$ , the LBCF reduces to the feedback comb filter (FBCF) of §2.6.2 in which the feedback was not filtered. The overall LBCF transfer function is then

$$\displaystyle \hbox{LBCF}_{N}^{\,f,\,d} \;= \; \frac{z^{-N}}{1 -f\frac{1-d}{1-d\,z^{-1}}\,z^{-N}}.$$

Apparently, this transfer function is implemented here. But can someone tell me, how to derive this implementation out of this transfer function?

Your diagram looks correct. Let's call the transfer function in the feedback loop $$G(z)$$. Consider the signal $$w[n]$$ at the input to the delay line. Its $$\mathcal{Z}$$-transform satisfies

$$W(z)=X(z)+G(z)Y(z)\tag{1}$$

where $$X(z)$$ and $$Y(z)$$ are the $$\mathcal{Z}$$-transforms of the input and output sequences, respectively. The output is just a delayed version of $$w[n]$$, i.e.,

$$Y(z)=W(z)z^{-M}\tag{2}$$

From $$(1)$$ and $$(2)$$, the transfer function of the complete system can be derived as

$$H(z)=\frac{z^{-M}}{1-G(z)z^{-M}}\tag{3}$$

Now it remains to find $$G(z)$$. It is quite straightforward to show that

$$G(z)=\frac{d_2f}{1-d_1z^{-1}}\tag{4}$$

Combining $$(3)$$ and $$(4)$$ gives the desired result with $$d_1=d$$ and assuming that $$d_2=1-d_1$$.