# NOT RUN {
## DFT of a 2D normal Gaussian function
n = 30
f = array(0,c(n,n))
for (i in seq(n)) {
for (j in seq(n)) f[i,j] = exp(-(i-6)^2/4-(j-8)^2/2-(i-6)*(j-8)/2)
}
plot(NA,xlim=c(0,2.1),ylim=c(0,1.1),asp=1,bty='n',xaxt='n',yaxt='n',xlab='',ylab='')
rasterImage(f,0,0,1,1,interpolate=FALSE)
g = dft(f)
img = array(hsv((pracma::angle(g)/2/pi)%%1,1,abs(g)/max(abs(g))),c(n,n))
rasterImage(img,1.1,0,2.1,1,interpolate=FALSE)
text(0.5,1,'Input function f',pos=3)
text(1.6,1,'DFT(f)',pos=3)
# }
Run the code above in your browser using DataLab