%% Convert Allpass coefficients to Wave Digital Filter Coefficients
% Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent  step syntax. For example, myObject(x) becomes step(myObject,x).
% Create a second order allpass filter with coefficients a = [0 0.5]. Convert these coefficients into wave digital filter form using allpass2wdf. Assign the transformed coefficients to an allpass filter using the wave digital filter structure. Pass a random input to both these filters and compare the outputs.

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

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