#demonstrate autoregressive filtering of noise
library(tuneR)
N = 4*8192
L = 3 # number of AR components
y = rep(0,N)
theta = .3;
r = .95
a = c(1,-2*r*cos(theta),r*r) # the AR filter. this filter "selects" frequencies
# around theta. note similarity to the equation
# that generated a sine at ang frequency theta.
for (i in L:N) {
y[i] = -a[2]*y[i-1] - a[3]*y[i-2] + rnorm(1)
} # AR model "driven" by noise
A = fft(c(a,rep(0,N-length(a)))); # fft of filter padded with 0s
Y = fft(y)
plot(Mod(Y[1:(N/2)])) # plot the freq dist of our sound
curve = 1/Mod(A[1:(N/2)]) # our AR freq response .... note 1/Mod(A)
curve = curve * max(Mod(Y[1:(N/2)]))/max(curve) # just scaling the curve
lines(curve);
#stopp;
y = round((2^13)*y / max(y))
u = Wave(y, samp.rate = 8000, bit=16)
play(u)