#  This script plots a dirichlet kernel and its periodogram.  

x.values <- seq(-6, 6, by = 0.01)
kernel.values <- sin(pi * x.values) / (100 * sin(pi * x.values /100))
periodogram.values <-abs(sin(pi * x.values) / (100 * sin(pi * x.values / 100)))^2

#  This corrects a singularity at the center.
singularity <- which(is.nan(kernel.values))
kernel.values[singularity] <- 1
periodogram.values[singularity] <- 1

#  Set up a graphics device.  
par(oma = rep(1, 4))
par(mar = c(4.5, 4.5, 1, 1))
par(mfrow = c(2, 1))

#  Set some graphical parameters.
x.axis <- seq(-6, 6, by = 2)
y.axis <- seq(0, 1, by = 0.5)
line.width <- 3
label.size <- 1.7
axis.size <- 1.7

#  Plot the Dirichlet kernel.
plot(x.values, kernel.values, 
     type = "l", lwd = line.width, 
     xaxt = "n", yaxt = "n", 
     xlab = "j", ylab = "", cex.lab = label.size)
axis(1, at = x.axis, x.axis, cex.axis = axis.size)
axis(2, at = y.axis, labels = y.axis, cex.axis = axis.size)

#  Plot the Dirichlet kernel's periodogram.
plot(x.values, periodogram.values, 
     type = "l", lwd = line.width, 
     xaxt = "n", yaxt = "n", 
     xlab = "j", ylab = "", cex.lab = label.size)
axis(1, at = x.axis, labels = x.axis, cex.axis = axis.size)
axis(2, at = y.axis, labels = y.axis, cex.axis = axis.size)

dev.print(device = postscript, "18.12.eps", horizontal = TRUE)