SpectralCentroid transform
See original GitHub issue🚀 Feature
torchaudio.transforms.SpectralCentroid
Motivation
This is a common audio transform, included in Librosa.
Pitch
A differentiable SpectralCentroid would be useful for audio neural networks.
Alternatives
Here is the librosa implementation.
Additional context
Here is a simplified implementation I have made, based upon the librosa implementation:
def spectral_centroid(y, sr, n_fft, hop_length=512):
S = torchaudio.transforms.Spectrogram(n_fft=n_fft, hop_length=hop_length, power=1.0)(y)
# freq = fft_frequencies(sr=sr, n_fft=n_fft)
freq = torch.linspace(0,
float(sr) / 2,
int(1 + n_fft//2))
#endpoint=True)
if freq.ndim == 1:
freq = freq.reshape((-1, 1))
def tl1norm(S):
return S / torch.sum(torch.abs(S), axis=0)
# Column-normalize S
return torch.sum(freq * tl1norm(S),
axis=0, keepdims=True)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spectral centroid
The spectral centroid is a measure used in digital signal processing to characterise a spectrum. It indicates where the center of mass of...
Read more >Spectral Centroid - an overview
The discrete Fourier transform is a powerful tool that is widely used to transform a time domain signal into a frequency domain audio...
Read more >Spectral Centroid
transform's frequency and magnitude information. The individual centroid of a spectral frame is defined as the average frequency weighted by amplitudes, ...
Read more >SPECTRAL CENTROID
Goal: Use spectral centroid to control FM synthesis parameters. • What's a spectral centroid? • Example code. ICM Week 5 ... Discrete Fourier...
Read more >(PDF) Fast computation of spectral centroids
A spectral centroid provides a noise-robust estimate of how the dominant frequency of a signal changes over time. As such, spectral centroids ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Excellent, thanks @mthrok
I will make a new merge request with optional frequency limiting, probably this weekend.
I’ll give this a shot!