# Clear the Workspace rm (list=ls()) # Generate a 5 second 1 kHz signal at 44.1 kHz sampling f <- 500 # central frequency omega <- 2*pi*f # central angular frequencey amp <- 26213 # amplitude of the wave tau <- 0.015 # fade in and out time constant time <- 5 # time duration in seconds rate <- 44100 # audio file sample rate len <- time *rate # length of the file wf <- 4 # warble rate in times per second womega <- 2*pi*wf # warble angular frequency wa <- 37.5 # amplitude of phase shift # Increment time samples at 44.1 kHz t <- seq(rate*time)/rate # time increments ph <- wa*sin(womega*t) # shift the phase poffset <- 2*pi*wa # offset on the phase to prevent a negative angle theta <- poffset + omega*t - ph # time dependent angle audio <- amp*sin(theta) # generate warble for analysis final <- as.integer(audio) # Analyze the results # plot( final, pch="." ) # lines( c(1, length(final)), c(0,0) ) lwin <- 1 hwin <- 10000 ff <- Mod( fft( final )[1:(length(final)/2)] ) feq <- (seq(length(ff))-1)*rate/length(final) plot( feq[lwin:hwin], ff[lwin:hwin] ) # Most of the frequency content falls +- wa*wf from the central frequency lines( c(f-wa*wf,f-wa*wf), c(0,max(ff)), col=2, lwd=2) lines( c(f+wa*wf,f+wa*wf), c(0,max(ff)), col=2, lwd=2) # Fade the signal in and out audio <- amp*sin(theta)*(1-exp(-t/tau))*(1-exp(-(time-t)/tau)) # Append zero a 1/2 second before and 1/2 second after t1 <- seq(rate/2)*0 final <- as.integer(c(t1, audio, t1)) # Save the file to Warble500.txt write( final, file="Warble500.txt", ncolumns = 1 ) play( final )