%
%  w05dirichlet.m
%

%  initialize workspace & set some control variables
clear;
Nd = 8;  Np = 16*Nd;  %  number of plot points

%  set x (row) vector
dx = 2*pi/(Np+1);  x = -pi:dx:pi;

%  fourier series 
dN = (sin((2*Nd+1)*x/2))./(sin(x/2));

%  fejer kernel
kN = (sin((Nd+1)*x/2))./(sin(x/2));
kN = ((kN).^2)/(Nd+1);

%  choose figure & clear 
figure(1);
clf;
subplot(2,1,1)
hold on

plot(x,dN,'k.');  
plot(x,dN,'b');

title('\bf dirichlet kernel')
xlabel('\bf x-axis')
ylabel('\bf D_N(x)')
axis([-pi pi -(2*Nd+1)/4 2*Nd+1])

subplot(2,1,2)
hold on

plot(x,kN,'k.');  
plot(x,kN,'b');

title('\bf fejer kernel')
xlabel('\bf x-axis')
ylabel('\bf K_N(x)')
axis([-pi pi -1 Nd+1])

figure(2)
subplot(2,1,1)
hold on

plot(x,dN,'b');

title('\bf dirichlet kernel')
xlabel('\bf x-axis')
ylabel('\bf D_N(x)')
axis([-pi pi -5 20])

subplot(2,1,2)
hold on

plot(x,kN,'b');

title('\bf fejer kernel')
xlabel('\bf x-axis')
ylabel('\bf K_N(x)')
axis([-pi pi -1 10])
