synth {seewave} | R Documentation |
Synthesis of time wave (additive model)
Description
This functions synthesizes pure or harmonic tone sound with amplitude modulation (am) and/or frequency modulation (fm).
Usage
synth(f, d, cf, a = 1, signal = "sine", shape = NULL, p = 0,
am = c(0, 0, 0), fm = c(0, 0, 0, 0, 0), harmonics = 1,
plot = FALSE, listen = FALSE, output = "matrix",...)
Arguments
f |
sampling frequency (in Hz). |
d |
duration (in s). |
cf |
carrier frequency (in Hz). |
a |
amplitude (linear scale, relative when adding different waves). |
signal |
a character vector specifying the shape of the signal,
see |
shape |
modification of the whole amplitude shape of the wave,
see |
p |
initial phase (in radians). |
am |
a numeric vector of length 3 describing amplitude modulation parameters,
see |
fm |
a numeric vector of length 5 describing frequency modulation parameters,
see |
harmonics |
a numeric specifying the number and the relative
amplitude of harmonics, see |
plot |
if |
listen |
if |
output |
character string, the class of the object to return, either
|
... |
other |
Details
signal
is a character vector of length 1 that specifies the function used to synthesize the signal. There are three options:"sine": for a sinus function,
"tria": for a triangle function,
"square": for a square function,
"saw": for a square function.
shape
is a character vector of length 1 that allows to modify the whole amplitude shape of the wave. There are four options:"incr": linear increase
"decr": linear decrease
"sine": sinusoid-like shape
"tria": triangular shape
am
is a numeric vector of length 3 including:the amplitude modulation depth (in %)
the frequency of the amplitude modulation (in Hz),
the phase of the amplitude modulation (in radian).
fm
is a numeric vector of length 5 including:the maximum excursion of a sinusoidal frequency modulation (in Hz),
the frequency of a sinusoidal frequency modulation (in Hz),
the maximum excursion of a linear frequency modulation (in Hz).
the phase of the frequency modulation (in radian).
the maximum excursion of an exponential frequency modulation (in Hz).
harmonics
is a numeric vector that controls the number and the relative amplitude of harmonics synthesized.
By defaultharmonics = 1
meaning that a pure tone made of a single harmonic (fundamental) will be produced.
To produce harmonics, the length ofharmonics
has to be greater than 1. The length ofharmonics
will set the number of harmonics, including the first one (fundamental). The value of each element ofharmonics
specify the relative ampltiude of each harmonic. The first value must equal to1
.
Here are some examples:harmonics = c(1, 0.5, 0.25)
will produce a sound with three harmonics (fundamental + 2 harmonics), the second harmonic having an amplitude half the fundamental ampltiude and the second harmonic an amplitude a quarter of the fundamental amplitude.harmonics = c(1, 0, 0.25)
will produce a sound with two harmonics (fundamental + 1 harmonic) the second harmonic having a null relative amplitude.harmonics = rep(1,4)
will produce a sound with four harmonics (fundamental + 3 harmonics) of equal amplitude.
Value
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Author(s)
Jerome Sueur and Laurent Lellouch.
References
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
See Also
Examples
## You can use plot=TRUE and spectro() options
## to directly 'see' the new-built sounds
f <- 8000 # sampling frequency
d <- 1 # duration (1 s)
cf <- 440 # carrier frequecy (440 Hz, i.e. flat A tone)
# pure sinusoidal tone
s <- synth(f=f,d=d,cf=cf)
# pure triangular tone
s <- synth(f=f,d=d,cf=cf, signal="tria")
# pure tone with triangle overall shape
s <- synth(f=f,d=d,cf=cf,shape="tria")
# pure tones with am
s <- synth(f=f,d=d,cf=cf,am=c(50,10))
# pure tones with am
# and phase shift of pi radian (180 degrees)
s <- synth(f=f,d=d,cf=cf,am=c(50,10,pi))
# pure tone with +1000 Hz linear fm
s <- synth(f=f,d=d,cf=cf,fm=c(0,0,1000,0,0))
# pure tone with sinusoidal fm
# (maximum excursion of 250 Hz, frequency of 10 Hz)
s <- synth(f=f,d=d,cf=cf,fm=c(250,10,0,0,0))
# pure tone with sinusoidal fm
# (maximum excursion of 250 Hz, frequency of 10 Hz,
# phase shift of pi radian (180 degrees))
s <- synth(f=f,d=d,cf=cf,fm=c(250,10,0, pi,0))
# pure tone with sinusoidal am
# (maximum excursion of 250 Hz, frequency of 10 Hz)
# and linear fm (maximum excursion of 500 Hz)
s <- synth(f=f,d=d,cf=cf,fm=c(250,10,500,0,0))
# the same with am
s <- synth(f=f,d=d,cf=cf,am=c(50,10), fm=c(250,10,250,0,0))
# the same with am and a triangular overall shape
s <- synth(f=f,d=d,cf=cf,shape="tria",am=c(50,10), fm=c(250,10,250,0,0))
# an harmonic sound
s <- synth(f=f,d=d,cf=cf, harmonics=c(1, 0.5, 0.25))
# a clarinet-like sound
clarinet <- c(1, 0, 0.5, 0, 0.14, 0, 0.5, 0, 0.12, 0, 0.17)
s <- synth(f=f, d=d, cf = 235.5, harmonics=clarinet)
# inharmonic FM sound built 'manually'
fm <- c(250,5,0,0,0)
F1<-synth(f=f,d=d,cf=cf,fm=fm)
F2<-synth(f=f,d=d,a=0.8,cf=cf*2,fm=fm)
F3<-synth(f=f,d=d,a=0.6,cf=cf*3.5,fm=fm)
F4<-synth(f=f,d=d,a=0.4,cf=cf*6,fm=fm)
final1<-F1+F2+F3+F4
spectro(final1,f=f,wl=512,ovlp=75,scale=FALSE)