% interpolation.m
%
% A Matlab script to plot linear and allpass interpolation
% frequency responses.
%
% Gary Scavone, McGill University, 2004.

% Signal and delay values.
N = 100;
omega = pi*(0:N)/N;
delta = [0.1:0.1:1];

% Calculate the frequency response for linear interpolation.
Gl = 1 + transpose(delta) * (exp(-j*omega) - 1);

subplot(2,1,1)
plot(omega/pi, 20*log10(abs(Gl)))
axis([0 1 -20 5])
grid
xlabel('Normalized Radian Frequency');
ylabel('Magnitude Response (dB)');
subplot(2,1,2)
plot(omega/pi, -unwrap(angle(Gl)) ./ (ones(length(delta),1)*omega))
axis([0 1 0 1])
grid
xlabel('Normalized Radian Frequency');
ylabel('Phase Delay (samples)');

disp('paused ... hit key to continue');
pause

delta = [0.1:0.1:2];
a = -(delta-1)./(delta+1);

% Calculate the frequency response for allpass interpolation.
Ga = transpose(a)*ones(size(omega)) + ones(size(transpose(a)))*exp(-j*omega);
Ga = Ga ./ (ones(size(Ga)) + transpose(a)*exp(-j*omega));

clf
plot(omega/pi, -unwrap(angle(Ga)) ./ (ones(length(delta),1)*omega))
%axis([0 1 0 1])
grid
xlabel('Normalized Radian Frequency');
ylabel('Phase Delay (samples)');