Skip to content

Commit

Permalink
Allow additional keyword arguments for spectrogram plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
maetshju committed Nov 4, 2022
1 parent 0bec84a commit 2bddd9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/phon_spectrogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using DSP
using Plots

"""
phonspec(s, fs; pre_emph=0.97, col=:magma, style=:broadband, dbr=55, size=(600, 400))
phonspec(s, fs; pre_emph=0.97, col=:magma, style=:broadband, dbr=55, size=(600, 400), kw...)
Rudimentary functionality to plot a spectrogram, with parameters familiar to phoneticians.
Includes a pre-emphasis routine which helps increase the intensity of the
Expand All @@ -19,8 +19,9 @@ Args
* `style` Either `:broadband` or `:narrowband`; will affect the window length and window stride
* `dbr` The dynamic range; all frequencies that are `dbr` decibels quieter than the loudest frequency will not be displayed
* `size` Size of plot in pixels; passed to `heatmap` call
* `args...` extra named parameters to pass to `heatmap`
"""
function phonspec(s::Vector, fs; pre_emph=0.97, col=:inferno, style=:broadband, dbr=55, size=(600, 400))
function phonspec(s::Vector, fs; pre_emph=0.97, col=:inferno, style=:broadband, dbr=55, size=(600, 400), ylim=(0, 5000), kw...)
pre_emph_filt = PolynomialRatio([1, -pre_emph], [1])
s = filt(pre_emph_filt, s)
if style == :broadband
Expand All @@ -34,5 +35,5 @@ function phonspec(s::Vector, fs; pre_emph=0.97, col=:inferno, style=:broadband,
spec = spectrogram(s, n, nov, fs=fs, window = n -> kaiser(n, 2), nfft=nfft)
spec_mx = maximum(spec.power)
db = 10 .* log10.(spec.power ./ spec_mx)
heatmap(spec.time, spec.freq, db, color=cgrad(col), ylim=(0, 5000), clim=(-dbr, 0), size=size, xlab="Time (s)", ylab="Frequency (Hz)")
heatmap(spec.time, spec.freq, db; color=cgrad(col), ylim=ylim, clim=(-dbr, 0), size=size, xlab="Time (s)", ylab="Frequency (Hz)", kw...)
end

0 comments on commit 2bddd9c

Please sign in to comment.