demo.dirichlet <- function(K=10){ x <- seq(-pi, pi, length=300) y <- 1/(2*pi) * sin(K*x/2) / sin(x/2) plot(x, y, type="l", lwd=2, main=paste("Dirichlet_{", K, "} Kernel", sep="")) abline(h=0) abline(v=0) } demo.fejer <- function(K=10){ x <- seq(-pi, pi, length=300) y <- 1/(2*pi *K) * (sin(K*x/2) / sin(x/2))^2 plot(x, y, type="l", lwd=2, main=paste("Fejer_{", K, "} Kernel", sep="")) abline(h=0) abline(v=0) } demo.turkey <- function(a = 0.25, M=10){ x <- seq(-pi, pi, length=300) D <- function(x) 1/(2*pi) * sin((2*M+1)*x/2) / sin(x/2) y = a*D(x - pi/M) + (1-2*a)*D(x) + a*D(x + pi/M) if(a==0.25){ tit <- paste("Turkey-Hanning Kernel with M=", M, sep="") } else if(a==0.23){ tit <- paste("Turkey-Hamming Kernel with M=", M, sep="") } else { tit <- paste("Turkey Kernel with M=", M, " a=", a, sep="") } plot(x, y, type="l", lwd=2, main=tit) abline(h=0) abline(v=0) } demo.parzen <- function(M=10){ x <- seq(-pi, pi, length=300) y <- ((3/(8*pi*M^3)) * (sin(M*x/4) / (sin(x/2)/2))^4 * (1 - 2/3*sin(x/2)^2)) plot(x, y, type="l", lwd=2, main=paste("Parzen_{", M, "} Kernel", sep="")) abline(h=0) abline(v=0) } demo08 <- function(){ demos <- list("DirichletºË"=demo.dirichlet, "FejerºË"=demo.fejer, "Turkey´°"=demo.turkey, "Parzen´°"=demo.parzen ) ndemos <- length(demos) prompts <- paste(" ", seq(ndemos), ". ", names(demos), "\n", sep="") cat("µÚ8ÕÂÑÝʾ:\n", prompts) sel <- scan(n=1, quiet=TRUE) demos[[sel]]() }