Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Subscriptable 'Frequencies' class #265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TKosir
Copy link

@TKosir TKosir commented Dec 4, 2023

Greetings,

First of all, thank you for this great package!

The other day I needed to calculate sound pressure levels in specific frequency regions. I wanted to use the Signal.bandpass_frequencies method which needs Frequencies class as input frequencies. The code I used is the following:

import numpy as np
import matplotlib.pyplot as plt

sample_rate = 44100
signal = np.random.randn(10000)
s = Signal(signal, sample_rate)

freq_bands = np.array([[100, 200], [200, 400], [800, 1600], [3200, 6400]])
frequencies = Frequencies(center=freq_bands.mean(axis=1), lower=freq_bands[:, 0], upper=freq_bands[:, 1])

f, o = s.bandpass_frequencies(frequencies=frequencies)
Lp = o.leq()
fig, ax = plt.subplots()
ax.plot(f.center, Lp, ".-")

However, when using the following code, I get "TypeError: 'Frequencies' object is not subscriptable". I want to therefore propose a small change for the base Frequencies class by adding __getitem__ method, like in other child frequencies classes to resolve this issue and make Frequencies class usable also as stand alone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant