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

% A simple all-pass filter function
% Inputs:
% x - input signal
% g - feedforward gain, should be less than 1 for stability
% d - delay length

a = [1, zeros(1, d-1), g];

b = [g, zeros(1, d-1), 1];

convolved_len = 3.*d;

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);


