[R] create waveform sawtooth

Michael Tiemann mdtiemann at gmail.com
Sun Nov 12 15:15:45 CET 2017

My tuneR sawtooth wave function generator is broken.

When I use the sine function, I get exactly what I expect: a sine wave whose frequency is defined by the freq parameter.  In particular, higher frequencies have shorter wavelengths (more cycles per second means shorter waves).  When I create a sawtooth wave, the opposite seems to occur: higher frequencies result in longer waves.  But that’s not all: as frequencies increase, it appears that wavelengths increase to infinite length, then get shorter again as the wave reverses, then it gets longer and flips again.

Here’s a small file that demonstrates the bad sawtooth waves:


sample_rate <- 12000
reverse <- FALSE
freqs <- c(111,112,113,114,115,116,117,118)
for (i in 1:length(freqs)) {
    temp <- sine(freqs[i],duration=round(sample_rate/100),samp.rate=sample_rate,xunit="samples")
    lines(temp at left,type="l",lty=2,col=mycolors[i])

	[[alternative HTML version deleted]]

More information about the R-help mailing list