%% Periodic and Aperiodic Sinc Functions
% The Dirichlet and sinc functions are related by D_N(\pi x)=\mathop{\rm sinc}\nolimits(Nx/2)/\mathop{\rm sinc}\nolimits(x/2). Show this relationship for N=6. Avoid indeterminate expressions by specifying that the ratio of sinc functions is {\left(-1\right)}^{k\left(N-1\right)} for x=2k, where k is an integer.

xmax = 4;
x = linspace(-xmax,xmax,1001)';

N = 6;

yd = diric(x*pi,N);
ys = sinc(N*x/2)./sinc(x/2);
ys(~mod(x,2)) = (-1).^(x(~mod(x,2))/2*(N-1));

subplot(2,1,1)
plot(x,yd)
title('D_6(x*pi)')
subplot(2,1,2)
plot(x,ys)
title('sinc(6*x/2) / sinc(x/2)')

%
% Repeat the calculation for N=13.

N = 13;

yd = diric(x*pi,N);
ys = sinc(N*x/2)./sinc(x/2);
ys(~mod(x,2)) = (-1).^(x(~mod(x,2))/2*(N-1));

subplot(2,1,1)
plot(x,yd)
title('D_{13}(x*pi)')
subplot(2,1,2)
plot(x,ys)
title('sinc(13*x/2) / sinc(x/2)')

% Copyright 2012 The MathWorks, Inc.