Given a duration and a frequency, this function can rapidly generate signals of different waveform types. The user may also optionally gate the signal on and off with a raised cosine ramp, as well as specify the starting phase and/or sample frequency.
OSCILLATOR generates a standard waveform, click train, or noise
duration (in seconds)
frequency (in Hz)
NOTE: linear and log sweeps require [start stop] frequency vector
Optional input arguments:
gate (in seconds): duration of a raised cosine on/off ramp
phase (in radians): starting phase of the waveform.
sample_rate (in samples): 44100 is default, custom rates are possible
wave = OSCILLATOR('Sinusoid',1,1000); % simple pure tone at 1000 Hz.
wave = OSCILLATOR('Sawtooth',2,440); % 2 second sawtooth at 440 Hz.
wave = OSCILLATOR('Pink Noise',1); % 1 second of pink (1/F) noise
wave = OSCILLATOR('Linear Sweep',2,[440 880]); % linear sweep from 440 to 880 Hz.
wave = OSCILLATOR('Log Sweep',2,[20 20000],.01); % ramped on/off log sweep.
wave = OSCILLATOR('White Noise',1,,0.1); %ramped on and off noise
wave = OSCILLATOR('Sinusoid',1,220,0,pi/2,48000); %pure tone with a
starting phase of 90 degrees and sample rate set to 48000.
Omitting 'wavetype' sets it to sinusoid, omitting 'duration' sets it to
one second, and omitting 'frequency sets it to 440 Hz. Gate is set to 0,
phase to 0 and sample rate to 44100; All output waves are scaled to a
peak absolute value of 1.0
Note that the grey noise is *generic* grey and is based the ISO 66-phon
(c) W. Owen Brimijoin - MRC Institute of Hearing Research
Tested on Matlab R2011b and R14
Version 1.0 18/05/12 - original
Version 1.1 29/06/12 - added pink and speech-shaped noise options
Version 1.2 26/06/13 - added swept sine and brown and grey noise options
Version 1.3 05/07/13 - added blue and violet and changed noise generation
to a slower but more accurate ifft method.