Digitizing an analog signal

Here’s a bit of code that might help. from __future__ import division import numpy as np def find_transition_times(t, y, threshold): “”” Given the input signal `y` with samples at times `t`, find the times where `y` increases through the value `threshold`. `t` and `y` must be 1-D numpy arrays. Linear interpolation is used to estimate … Read more

Can I convert spectrograms generated with librosa back to audio?

Yes, it is possible to recover most of the signal and estimate the phase with e.g. Griffin-Lim Algorithm (GLA). Its “fast” implementation for Python can be found in librosa. Here’s how you can use it: import numpy as np import librosa y, sr = librosa.load(librosa.util.example_audio_file(), duration=10) S = np.abs(librosa.stft(y)) y_inv = librosa.griffinlim(S) And that’s how … Read more

2D Convolution in Python similar to Matlab’s conv2

There are a number of different ways to do it with scipy, but 2D convolution isn’t directly included in numpy. (It’s also easy to implement with an fft using only numpy, if you need to avoid a scipy dependency.) scipy.signal.convolve2d, scipy.signal.convolve, scipy.signal.fftconvolve, and scipy.ndimage.convolve will all handle a 2D convolution (the last three are N-d) … Read more

DSP – Filtering in the frequency domain via FFT

There are two issues: the way you use the FFT, and the particular filter. Filtering is traditionally implemented as convolution in the time domain. You’re right that multiplying the spectra of the input and filter signals is equivalent. However, when you use the Discrete Fourier Transform (DFT) (implemented with a Fast Fourier Transform algorithm for … Read more

How do you do bicubic (or other non-linear) interpolation of re-sampled audio data?

My favorite resource for audio interpolating (especially in resampling applications) is Olli Niemitalo’s “Elephant” paper. I’ve used a couple of these and they sound terrific (much better than a straight cubic solution, which is relatively noisy). There are spline forms, Hermite forms, Watte, parabolic, etc. And they are discussed from an audio point-of-view. This is … Read more