Skip to content

Commit

Permalink
Update README with spectrogram examples
Browse files Browse the repository at this point in the history
  • Loading branch information
VaysseRobin committed Jun 12, 2024
1 parent a289394 commit 470a0c0
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 9 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pip install rhythmoscope
```
## 🔬 Basic usage

As an example, we'll extract and plot the EMS of a speech signal from a .wav file:
### EMS

As an example, we'll extract and plot the EMS of a speech signal from a .wav file (examples wav files can be found in `/examples/audios`):

```python
from rhythmoscope.ems import EMSExtractor
Expand All @@ -27,12 +29,37 @@ fig = EMS.plot()
fig.show()
```

It produce the following output which represent the Envelope Modulation Spectrum of a signal:
It produce the following output which represent the Envelope Modulation Spectrum of a signal (examples wav files can be found in `/examples/audios`):

<div align="center">
<img src="docs/img/EMS_example.png" alt="EMS_example" width="90%" vspace="5">
</div>

### Rhythm spectrogram

```python
from rhythmoscope.ems import EMSExtractor
from rhythmoscope.signal import RollingWindow
from rhythmoscope.spectrogram import RhythmSpectrogramExtractor

EMS = EMSExtractor(min_freq=0, max_freq=15) # Define EMS extractor parameters
Window = RollingWindow(window_size=3, hop_size=0.5) # Define parameters of the spectrogram rolling window (in seconds)

SpectroExtract = RhythmSpectrogramExtractor(EMS, Window) # Define Spectrogram extractore parameters
spectrogram = SpectroExtract.from_file("count.wav") # Extract spectrogram

fig = spectrogram.plot()
fig.show()
```

It produce the following output which represent the Rhythm Spectrogram of a signal:

<div align="center">
<img src="docs/img/spectro.png" alt="Spectrogram_example" width="70%" vspace="5">
</div>

Each red line correspond to a regular rhythm at a given time. The rhythmic evolution in this example comes from the fact that the words spoken are mono-syllabic in the first half and bi-syllabic in the second.

## 🔗 Related work

- [Rhythm Formant Analysis](https://github.com/dafyddg/RFA) from Dafydd Gibbon
Expand Down
File renamed without changes
Binary file added docs/img/spectro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/audios/count.wav
Binary file not shown.
446 changes: 444 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ numpy = "^1.26.4"
scipy = "^1.12.0"
pandas = "^2.2.1"
plotly = "^5.19.0"
matplotlib = "^3.9.0"


[build-system]
Expand Down
5 changes: 3 additions & 2 deletions rhythmoscope/signal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .utils import load_wavfile
from .filters import butterworth_filter
from .rolling_window import WindowedSignal
from .rolling_window import RollingWindow
from .pitch import cepstral_pitch

__all__ = ["load_wavfile", "butterworth_filter", "WindowedSignal"]
__all__ = ["load_wavfile", "butterworth_filter", "RollingWindow", "cepstral_pitch"]
6 changes: 3 additions & 3 deletions rhythmoscope/spectrogram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def plot(
freq_range: Optional[Tuple] = None,
log_spectrogram: bool = False,
ylog: Optional[bool] = False,
saveplot: str = "",
savefig: str = "",
):
if time_range is not None:
ids_time = np.where(
Expand Down Expand Up @@ -63,6 +63,6 @@ def plot(
plt.ylabel("Frequency (Hz)")
plt.xlabel("Time (s)")

if saveplot:
plt.savefig(saveplot)
if savefig:
plt.savefig(savefig)
return fig

0 comments on commit 470a0c0

Please sign in to comment.