%% Design an Arbitrary Group Delay Filter
% Construct a signal consisting of two discrete-time windowed sinusoids (wave packets) with disjoint time support to illustrate frequency dispersion. One discrete-time sinusoid has a frequency of pi/2 radians/sample and the other has a frequency of pi/4 radians/sample. There are 9 periods of the higher-frequency sinusoid that precede 5 periods of the lower-frequency signal.
% Create the signal.

x = zeros(300,1);
x(1:36) = cos(pi/2*(0:35)).*hamming(36)';
x(40:40+39) = cos(pi/4*(0:39)).*hamming(40)';

%
% Create an arbitrary group delay filter that delays the higher-frequency wave packet by approximately 100 samples.

N = 18;
f = 0:.1:1;
gd = ones(size(f));

%
% Delay pi/2 radians/sample by 100 samples

gd(6) = 100;
d = fdesign.arbgrpdelay(N,f,gd);
Hd = design(d,'iirlpnorm','MaxPoleRadius',0.9,'SystemObject',true);

%
% Visualize the group delay

fvtool(Hd,'analysis','grpdelay');

%
% Filter the input signal with the arbitrary group delay filter and illustrate the frequency dispersion. The high-frequency wave packet, which initially preceded the low-frequency wave packet, now occurs later because of the nonconstant group delay.

y = Hd(x);
subplot(211)
plot(x); title('Input Signal');
grid on; ylabel('Amplitude');
subplot(212);
plot(y); title('Output Signal'); grid on;
xlabel('Samples'); ylabel('Amplitude');

% Copyright 2012 The MathWorks, Inc.