pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
Loading...
Searching...
No Matches
Functions
pyACA.ToolResample Namespace Reference

Functions

 ToolResample (x, fs_out, fs_in)
 helper function: downmixes an audio signal into one channel
 

Function Documentation

◆ ToolResample()

ToolResample ( x,
fs_out,
fs_in )

helper function: downmixes an audio signal into one channel

Parameters
xarray with floating point audio data (dimension samples x channels)
fs_outtarget sample rate of audio data
fs_ininput sample rate of audio data
Returns
x_out: resampled audio signal
t_out: corresponding time vector

Definition at line 17 of file ToolResample.py.

17def ToolResample(x, fs_out, fs_in):
18
19 if fs_out > fs_in:
20 omega_cutoff = fs_in / fs_out
21 else:
22 omega_cutoff = fs_out / fs_in
23
24 # compute filter coefficients
25 iOrder = 4
26 [b, a] = butter(iOrder, 0.9 * omega_cutoff)
27
28 # time axes
29 t_in = np.arange(len(x)) / float(fs_in)
30 t_out = np.arange(np.round(t_in[-1] * fs_out)) / float(fs_out)
31
32 if fs_out > fs_in:
33 # upsample: interpolate and filter
34
35 # this uses the most horrible interpolation possible
36 hInterpol = interp1d(t_in, x, kind='linear')
37 x_out = hInterpol(t_out)
38
39 # low pass filter
40 x_out = filtfilt(b, a, x_out)
41 else:
42 # downsample: filter and interpolate
43
44 # low pass filter
45 x_out = filtfilt(b, a, x)
46
47 # this uses the most horrible interpolation possible
48 hInterpol = interp1d(t_in, x_out, kind='linear')
49 x_out = hInterpol(t_out)
50
51 return x_out, t_out