function [y, b, a] = fbcomb_fft_lp(x, g, g1, d)

% A simple feedback comb filter function
% Inputs:
% x - input signal
% d - delay length
% g = g2/(1-g1), where g2 is the feedback gain of the comb filter (this should be less than 1 for stability) 
% g1 = the feedback gain of the low pass filter (this should be less than 1 for stability) 
% Outputs:
% y - output signal
% b - numerator coefficients of the transfer function
% a - denominator coefficients of the transfer function



 
%If g is more than 1, set it to 0.7 . 
if g>=1 
   g=0.7; 
end    
 
%If the low pass feedback gain is more than 1, set it to 0.7 . 
if g>=1 
   g=0.7; 
end    
 
%Set the b and a coefficients of the transfer function depending on g, g1 and d. 
b=[zeros(1,d) 1 -g1];             % Here the coefficients have been changed form the 
a=[1 -g1 zeros(1,d-2) -g*(1-g1)]; % original fbcomb.m function 
 
 

convolved_len = 5.*d;  % I looked at length always worked out about 27 times the delay

fftlength = 2.^nextpow2(convolved_len);

fft_a = fft(a, fftlength);

fft_b = fft(b, fftlength);

impres = real(ifft(fft_b./fft_a));
y = conv(x, impres);
