Learn R Programming

seewave (version 2.1.6)

synth: 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 details.

shape

modification of the whole amplitude shape of the wave, see details.

p

initial phase (in radians).

am

a numeric vector of length 3 describing amplitude modulation parameters, see details.

fm

a numeric vector of length 5 describing frequency modulation parameters, see details.

harmonics

a numeric specifying the number and the relative amplitude of harmonics, see details.

plot

if TRUE returns the spectrogram of the synthezised sound (by default FALSE).

listen

if TRUE the new sound is played back.

output

character string, the class of the object to return, either "matrix", "Wave", "Sample", "audioSample" or "ts".

other spectro graphical parameters.

Value

If plot is FALSE, a new wave is returned. The class of the returned object is set with the argument output.

Details

  • signal is a character vector of length 1 that specifies the function used to synthesize the signal. There are three options:

    1. "sine": for a sinus function,

    2. "tria": for a triangle function,

    3. "square": for a square function,

    4. "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:

    1. "incr": linear increase

    2. "decr": linear decrease

    3. "sine": sinusoid-like shape

    4. "tria": triangular shape

  • am is a numeric vector of length 3 including:

    1. the amplitude modulation depth (in %)

    2. the frequency of the amplitude modulation (in Hz),

    3. the phase of the amplitude modulation (in radian).

  • fm is a numeric vector of length 5 including:

    1. the maximum excursion of a sinusoidal frequency modulation (in Hz),

    2. the frequency of a sinusoidal frequency modulation (in Hz),

    3. the maximum excursion of a linear frequency modulation (in Hz).

    4. the phase of the frequency modulation (in radian).

    5. 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 default harmonics = 1 meaning that a pure tone made of a single harmonic (fundamental) will be produced. To produce harmonics, the length of harmonics has to be greater than 1. The length of harmonics will set the number of harmonics, including the first one (fundamental). The value of each element of harmonics specify the relative ampltiude of each harmonic. The first value must equal to 1. 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.

References

Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.

See Also

synth2, noisew, pulse, echo

Examples

Run this code
# NOT RUN {
## 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)
# }

Run the code above in your browser using DataLab