%% Convert Wave Digital Filter Coefficients to Allpass Polynomial Coefficients
% Note: If you are using R2016a or earlier, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% Create a second order allpass filter with wave digital filter coefficients w = [0.5 0]. Convert these coefficients into polynomial form using wdf2allpass. Assign the polynomial coefficients to an allpass filter using the 'Minimum multiplier' structure. Pass a random input to both these filters and compare the outputs.

w = [0.5 0];
allpasswdf = dsp.AllpassFilter('Structure', 'Wave Digital Filter',...
    'WDFCoefficients', w);
a = wdf2allpass(w);
allpass = dsp.AllpassFilter('AllpassCoefficients', a);
in = randn(512, 1);
outputallpasswdf = allpasswdf(in);
outputallpass = allpass(in);
plot(outputallpasswdf-outputallpass)

% The difference between the two outputs is very small.
% Copyright 2012 The MathWorks, Inc.