Data Compression Algorithms

There are a ton of compression algorithms out there. What you need here is a lossless compression algorithm. A lossless compression algorithm compresses data such that it can be decompressed to achieve exactly what was given before compression. The opposite would be a lossy compression algorithm. Lossy compression can remove data from a file. PNG … Read more

Plotting power spectrum in python

Numpy has a convenience function, np.fft.fftfreq to compute the frequencies associated with FFT components: from __future__ import division import numpy as np import matplotlib.pyplot as plt data = np.random.rand(301) – 0.5 ps = np.abs(np.fft.fft(data))**2 time_step = 1 / 30 freqs = np.fft.fftfreq(data.size, time_step) idx = np.argsort(freqs) plt.plot(freqs[idx], ps[idx]) Note that the largest frequency you see … Read more

Any good recommendations for MP3/Sound libraries for java? [closed]

JLayer should do everything you need. It’s not dead, it’s just stable. The author finished it up quite a long time ago and the MP3 format has not seen much change since. You’ll notice that his MP3SPI codebase is a little more recent. What MP3SPI does, is that translates JLayer’s abilities into JavaSound APIs. Thus … Read more

Beats per minute from real-time audio input

Calculate a powerspectrum with a sliding window FFT: Take 1024 samples: double[] signal = stream.Take(1024); Feed it to an FFT algorithm: double[] real = new double[signal.Length]; double[] imag = new double[signal.Length); FFT(signal, out real, out imag); You will get a real part and an imaginary part. Do NOT throw away the imaginary part. Do the … Read more

Invertible STFT and ISTFT in Python

Here is my Python code, simplified for this answer: import scipy, pylab def stft(x, fs, framesz, hop): framesamp = int(framesz*fs) hopsamp = int(hop*fs) w = scipy.hanning(framesamp) X = scipy.array([scipy.fft(w*x[i:i+framesamp]) for i in range(0, len(x)-framesamp, hopsamp)]) return X def istft(X, fs, T, hop): x = scipy.zeros(T*fs) framesamp = X.shape[1] hopsamp = int(hop*fs) for n,i in enumerate(range(0, … Read more

How to do unsigned saturating addition in C?

You probably want portable C code here, which your compiler will turn into proper ARM assembly. ARM has conditional moves, and these can be conditional on overflow. The algorithm then becomes: add and conditionally set the destination to unsigned(-1), if overflow was detected. uint16_t add16(uint16_t a, uint16_t b) { uint16_t c = a + b; if … Read more