Library


Module

Signal generators

AuditoryStimuli.NoiseSourceType
NoiseSource(eltype, samplerate, nchannels, std=1)

NoiseSource is a multi-channel noise signal generator. The noise on each channel is independent.

Inputs

  • samplerate specifies the sample rate of the signal specified in Hz.
  • nchannels specifies the number of channels of the signal.
  • std specifies the desired standard deviation of the signal.

Output

  • SampleSource object

Example

source_object = NoiseSource(Float64, 48u"kHz", 2, 0.3)
wn = read(source_object, 480)         # Specify number of samples of signal to generate
wn = read(source_object, 50u"ms")     # Specify length of time of signal to generate
AuditoryStimuli.CorrelatedNoiseSourceType
CorrelatedNoiseSource(eltype, samplerate, nchannels, std, correlation)

CorrelatedNoiseSource is a two-channel noise signal generator with controlled correlation between channels.

Inputs

  • samplerate specifies the sample rate of the signal.
  • nchannels specifies the number of channels of the signal.
  • std specifies the desired standard deviation of the signal.
  • correlation specifies the desired correlation between the signals.

Output

  • SampleSource object

Example

source_object = CorrelatedNoiseSource(Float64, 48000, 2, 0.3, 0.75)
cn = read(source_object, 480)         # Specify number of samples of signal to generate
cn = read(source_object, 50u"ms")     # Specify length of time of signal to generate
AuditoryStimuli.SinusoidSourceType
SinusoidSource(eltype, samplerate, freqs)

SinusoidSource is a single-channel sine-tone signal generator. freqs can be an array of frequencies for a multi-frequency source, or a single frequency for a single sinusoid source.

Inputs

  • samplerate specifies the sample rate of the signal.
  • freqs sinusoid frequencies to generate.

Output

  • SampleSource object

Example

source_object = SinusoidSource(Float64, 48u"kHz", 200:200:2400)
cn = read(source_object, 50u"ms")     # Generate 50 ms of harmonic stack audio

Online signal modifiers

AuditoryStimuli.AmplificationType
Amplification(target, current, change_limit)

Apply amplification to the signal.

This modifier allows the user to specify a target linear amplification value that will be applied to the signal. The modifier will then change the amplification of the signal until the desired amplification is achieved. The rate at which the amplification can be changed per frame is parameterised by the change_limit parameter.

To slowly ramp a signal to a desired value set the target amplification to the desired value, and the change_limit to a small value.

To instantly change the signal set the change_limit to infinity and modify the target value.

When initialising the modifier specify the desired starting point using the current parameter.

You can access the exact amplification at any time by querying the current parameter.

Inputs

  • target desired linear amplification factor to be applied to signal.
  • current linear amplification currently applied to signal. Also used to specify the intial value for the process.
  • change_limit maximum change that can occur per frame.
  • enable enable the modifier, if false the signal will be passed through without modification.

Example

amplify = Amplification(0.1, 0.0, 0.05)
attenuated_sound = modify(amplify, original_sound)
AuditoryStimuli.FilterType
Filter(filters)

Apply filter to the signal

Inputs

  • filters array of DSP filter objects.

Example

using DSP
responsetype = Bandpass(500, 4000; fs=48000)
designmethod = Butterworth(4)
zpg = digitalfilter(responsetype, designmethod)
f_left = DSP.Filters.DF2TFilter(zpg)
f_right = DSP.Filters.DF2TFilter(zpg)

bandpass = AuditoryStimuli.Filter([f_left, f_right])
filtered_sound = modify(bandpass, original_sound)
AuditoryStimuli.AmplitudeModulationType
AmplitudeModulation(rate, phase, depth)

Apply amplitude modulation to the signal

Inputs

  • rate (Hz) desired modulation rate to be applied to signal.
  • phase phase of modulation to be applied to signal applied to signal. Defaults to pi so that modulation starts at a minimum.
  • depth modulation depth.

Example

modulate = AmplitudeModulation(1u"Hz")
modulated_sound = modify(modulate, original_sound)
AuditoryStimuli.TimeDelayType
TimeDelay(channel, delay, enable, buffer)
TimeDelay(channel, delay, enable, buffer; samplerate)

Apply a time delay to a specific channel.

Inputs

  • channel which channel should have a time delay applied.
  • delay delay to be applied in samples or unit of time.
  • enable should the modifier be enabled. Defaults to true.
  • buffer initial values with which to pad the time delay. Defaults to zeros.
  • samplerate keyword argument required if delay is specified in unit of time.

Example

itd = TimeDelay(2, 0.5u"ms", samplerate=48u"kHz")
sound_with_itd = modify(itd, original_sound)

Offline Signal modifiers

Plotting

AuditoryStimuli.plot_cross_correlationFunction
plot_cross_correlation(x::SampleBuf, lags::Unitful.Time)

Plot the cross correlation of a two channel audio signal.

Inputs

  • x data in the form of SampledSignals.SampleBuf. Must be two channels of audio.
  • lags time range of lags to be used when plotting the cross correlation function. If lags=0, then the entire function will be used, effecively same as lags=Inf.

Example

correlation = 0.6
source = CorrelatedNoiseSource(Float64, 48u"kHz", 2, 0.1, correlation)
a = read(source, 3u"s")
plot_cross_correlation(a, lags=4u"ms")

Signal Metrics

AuditoryStimuli.interaural_coherenceFunction
interaural_coherence(x::SampleBuf, lags::Unitful.Time)

Compute the interaural coherence of a two channel sound signals.

Interaural coherence (IAC) is commonly defined as the peak of the cross-correlation coefficient of the signals at the two ears [1, 2]. It is commonly computed over a restricted range of lags of the cross-correlation function.

Inputs

  • x data in the form of SampledSignals.SampleBuf. Must be two channels of audio.
  • lags time range of lags to be used for finding maximum in cross correlation function. If lags=0, then the entire function will be used, effecively same as lags=Inf.

References

  1. Chait, M., Poeppel, D., de Cheveigne, A., and Simon, J.Z. (2005). Human auditory cortical processing of changes in interaural correlation. J Neurosci 25, 8518-8527.
  2. Aaronson, N.L., and Hartmann, W.M. (2010). Interaural coherence for noise bands: waveforms and envelopes. J Acoust Soc Am 127, 1367-1372.

Example

correlation = 0.6
source = CorrelatedNoiseSource(Float64, 48000, 2, 0.1, correlation) 
a = read(source, 3u"s")
@test interaural_coherence(a.data) ≈ correlation atol = 0.025

Depreciated

AuditoryStimuli.bandpass_noiseFunction
bandpass_noise(number_samples, number_channels, lower_bound, upper_bound, sample_rate; filter_order=14)

Generates band pass noise with specified upper and lower bounds using a butterworth filter.

AuditoryStimuli.bandpass_filterFunction
bandpass_filter(AbstractArray, lower_bound, upper_bound, sample_rate; filter_order=14)
bandpass_filter(SampledSignal, lower_bound, upper_bound;              filter_order=14)

Signal will be filtered with bandpass butterworth filter between 'lowerbound' and `upperboundwith filter offilter_order`.