Unix and Linux Discussions Tagged with analysis |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
13 |
14,217 |
AIX |
|
|
|
3 |
8,205 |
UNIX for Advanced & Expert Users |
|
|
|
0 |
12,833 |
Infrastructure Monitoring |
|
|
|
0 |
2,097 |
AIX |
|
|
|
1 |
2,917 |
UNIX for Advanced & Expert Users |
|
|
|
2 |
5,023 |
Solaris |
|
|
|
0 |
1,307 |
Complex Event Processing RSS News |
|
|
|
0 |
1,633 |
UNIX and Linux RSS News |
|
|
|
0 |
1,666 |
UNIX and Linux RSS News |
|
|
|
0 |
9,585 |
Solaris BigAdmin RSS |
|
|
|
7 |
5,361 |
Programming |
|
|
|
0 |
1,654 |
Oracle Updates (RSS) |
|
|
|
0 |
1,845 |
Complex Event Processing RSS News |
|
|
|
1 |
16,046 |
UNIX for Dummies Questions & Answers |
|
|
|
8 |
21,125 |
UNIX for Dummies Questions & Answers |
|
|
|
4 |
3,600 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
3,548 |
UNIX for Dummies Questions & Answers |
spectral-analysis(7) Numm Tutorials spectral-analysis(7)
NAME
spectral analysis - perform realtime spectral analysis
SYNOPSIS
numm-run FILE
DESCRIPTION
Frequency makes for a meaningful description of many audio signals. We can use numpy's fourier analysis to compute spectra from the micro-
phone and display the results visually. We will break down the process into smaller parts: baby steps...
First, create and save a skeletal file that moves a line across the screen:
idx = 0
def video_out(a):
global idx
a[:,idx] = 255
idx = (idx + 1) % a.shape[1]
def audio_in(a):
pass
Save this snippet and run it with numm-run.
We will use the numpy.fft module for our analysis. First we define a function to get a particular frequency from the fourier transform:
import numpy as np
def get_freq(fourier, frequency):
freqs = np.fft.fftfreq(len(fourier), 1/44100.0)
nearest = (abs(freqs - frequency)).argmin()
return abs(fourier[nearest])
Next, we hook up this function to audio input from the microphone. A frequency bin is chosen on a log scale for each row on the screen to
display a spectogram. In total:
import numpy as np
idx = 0
recent_audio = np.zeros(4096, np.int16)
recent_video = np.zeros((240,320,3), np.uint8)
freq_bins = np.exp2(np.linspace(np.log2(27000),np.log2(27),240))
def get_freq(fourier, frequency):
freqs = np.fft.fftfreq(len(fourier), 1/44100.0)
nearest = (abs(freqs - frequency)).argmin()
return abs(fourier[nearest])
def video_out(a):
global idx
fourier=np.fft.fft(recent_audio)
values =np.array([get_freq(fourier,X) for X in freq_bins])
recent_video[:,idx,1] = (values/10000).clip(0,255)
idx = (idx + 1) % a.shape[1]
a[:] = np.roll(recent_video, -idx, axis=1)
def audio_in(a):
recent_audio[:] = np.roll(recent_audio, len(a))
recent_audio[:len(a)] = a.mean(axis=1)
SEE ALSO
numm-run(1), numm.getting-started(7), numm.one-bit-instrument(7)
numm February 2012 spectral-analysis(7)