Stimgen Methods
All stimgen
TinnitusReconstructor.generate_stimulus
— Functiongenerate_stimulus(s::Stimgen)
Generate one stimulus sound.
Returns waveform, sample rate, spectral representation, binned representation, and a frequency vector (the last two empty if s >: BinnedStimgen). Methods are specialized for each concrete subtype of Stimgen.
TinnitusReconstructor.fs
— Functionfs(s::SG) where {SG<:Stimgen}
Return the number of samples per second.
TinnitusReconstructor.nsamples
— Functionnsamples(s::SG) where {SG<:Stimgen}
Return the number of samples as an Integer. This means that the product fs(s) * s.duration
must be an Integer or an InexactError
will be thrown.
Examples
```jldoctest julia> s = UniformPrior(; Fs=44.1e3, duration=0.5); nsamples(s) 22050
julia> s = UniformPrior(; Fs=44.1e3, duration=0.7); nsamples(s) ERROR: InexactError: Int64(30869.999999999996)
TinnitusReconstructor.subject_selection_process
— Methodsubject_selection_process(s::SG, target_signal::AbstractVector{T}, n_trials::I) where {SG<:Stimgen,T<:Real,I<:Integer}
Perform the synthetic subject decision process, generating the stimuli on-the-fly using the stimulus generation method s
.
TinnitusReconstructor.subject_selection_process
— Methodsubject_selection_process(s::SG, target_signal::AbstractMatrix{T}, n_trials::I) where {SG<:Stimgen,T<:Real,I<:Integer}
Convert target_signal to Vector if passed as a Matrix.
TinnitusReconstructor.generate_stimuli_matrix
— Methodgenerate_stimuli_matrix(s::SG, n_trials::I) where {SG<:Stimgen, I<:Integer}
Generate n_trials
of stimuli based on specifications in the stimgen type.
Returns stimuli_matrix
, Fs
, spect_matrix
, binned_repr_matrix
. binned_repr_matrix
= nothing if s >: BinnedStimgen.
Binned only
TinnitusReconstructor.generate_stimuli_matrix
— Methodgenerate_stimuli_matrix(s::BS, n_trials::I) where {BS<:BinnedStimgen, I<:Integer}
Generate n_trials
of stimuli based on specifications in the stimgen type.
Returns stimuli_matrix
, Fs
, spect_matrix
, binned_repr_matrix
.
TinnitusReconstructor.freq_bins
— Functionfreq_bins(s::BS; n_bins::I = 0) where {BS<:BinnedStimgen, I<:Integer}
Generates a vector indicating which frequencies belong to the same bin, following a tonotopic map of audible frequency perception. The number of bins can be specified with the n_bins
parameter. s.n_bins
is used by default.
TinnitusReconstructor.empty_spectrum
— Functionempty_spectrum(s::BS) where {BS<:BinnedStimgen}
Generate an nfft x 1
vector of Ints, where all values are -100.
TinnitusReconstructor.spect2binnedrepr
— Functionspect2binnedrepr(s::BinnedStimgen, spect::AbstractVecOrMat{T}; n_bins::I = 0) where {BS<:BinnedStimgen,T,I<:Integer}
Convert a spectral representation into a binned representation. The number of bins can be specified with the n_bins
parameter. s.n_bins
is used by default.
Returns an n_trials x n_bins
array containing the amplitude of the spectrum in each frequency bin, where n_trials
= size(binned_repr, 2).
TinnitusReconstructor.binnedrepr2spect
— Functionbinnedrepr2spect(s::BinnedStimgen, binned_repr::AbstractArray{T}) where {BS<:BinnedStimgen,T}
Convert the binned representation into a spectral representation. The number of bins can be specified with the n_bins
parameter. s.n_bins
is used by default.
Returns an n_frequencies x n_trials
spectral array, where n_trials
= size(binned_repr, 2).
TinnitusReconstructor.binnedrepr2wav
— Functionbinnedrepr2wav(s::BS, binned_repr::AbstractVecOrMat{T}, mult, binrange,
new_n_bins::I = 256) where {BS <: BinnedStimgen, I <: Integer, T}
Converts a binned spectral representation into a waveform by enhancing the resolution (to new_n_bins
) via interpolation, sharpening the peaks (mult
), and rescaling the dynamic range (binrange
).
Returns a waveform and the associated frequency spectrum.
TinnitusReconstructor.build_distribution
— Functionbuild_distribution(s::PowerDistribution; save_path::AbstractString=@__DIR__)
Builds the default power distribution from ATA tinnitus sample files. Saves the distribution as a vector in dB at save_path.