forked from interactiveaudiolab/penn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
related to: #5
- Loading branch information
Showing
3 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .core import * | ||
from . import mplt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import penn | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
def plot_stft(axis : plt.Axes, | ||
audio, | ||
sr=penn.SAMPLE_RATE, | ||
window_length=2048*4, | ||
hop_length=penn.data.preprocess.GSET_HOPSIZE): | ||
""" | ||
Add a plot of STFT to given audio. | ||
Parameters: | ||
axis - matplotlib pyplot figure axis to have the STFT plot | ||
audio - source data | ||
sr - sampling rate | ||
window_length - length of the moving STFT window | ||
hop_length - hop step of the moving window in samples | ||
""" | ||
|
||
stft, freqs, times = penn.plot.raw_data.extract_spectrogram(audio, | ||
sr=sr, | ||
window_length=window_length, | ||
hop_length=hop_length) | ||
|
||
axis.pcolormesh(times, freqs, np.abs(stft), ) | ||
axis.set_ylim([50, 300]) | ||
axis.set_xlim([times[0], times[-1]]) | ||
|
||
# take inspiration from this post: https://dsp.stackexchange.com/a/70136 | ||
|
||
|
||
def plot_with_matplotlib(audio, sr=penn.SAMPLE_RATE, pitch_pred=None, pred_times=None, ground_truth=None, periodicity=None, threshold=None): | ||
""" | ||
Plot stft to the given audio. Optionally put raw pitch data | ||
or even thresholded periodicity data on top of it. | ||
""" | ||
|
||
# Create plot | ||
figure, axis = plt.subplots(figsize=(7, 3)) | ||
|
||
# Make pretty | ||
axis.spines['top'].set_visible(False) | ||
axis.spines['right'].set_visible(False) | ||
axis.spines['bottom'].set_visible(False) | ||
axis.spines['left'].set_visible(False) | ||
|
||
plot_stft(axis, audio, sr) | ||
|
||
# figure.show() | ||
plt.show() |