コード例 #1
0
ファイル: feature.py プロジェクト: peteraldaron/547take2
def abstract_cartoon(wave,
                     window_size=64,
                     resample_size=32768,
                     window_func=signal.hann,
                     freq=False,
                     norm=True):
    #whole wave analysis using a set transform window
    #TODO: resample the "cartoon" to a certain length and find trend.
    #resample wave to a set length
    resampled_wave = signal.resample(wave.data, resample_size)
    sr = wave.sr
    #segmentation:
    segments = fileio.segment(resampled_wave, window_size)

    #TODO: test this
    #try frequency:
    if freq:
        transformed_segments = [fft_to_freq(fft_extract(seg, window_func), sr, 1)[0] for seg in segments]
    else:
        transformed_segments = [fft_extract(seg, window_func).max() for seg in segments]

    #ft = fftpack.dct(wave.data * window_type(len(wave.data)))
    #window this?
    transformed_segments = syllable.moving_window(transformed_segments, window_size, window_func)
    if norm:
        transformed_segments = normalize(transformed_segments)
    #1st derivative for trend detection:
    #return np.diff(transformed_segments)
    return transformed_segments
コード例 #2
0
ファイル: main.py プロジェクト: peteraldaron/547take2
def plotstuff(filename):
    a=fileio.Wave("audio/samples/"+filename+".wav")
    am, fr = syllable.segmentation(a)
    title(filename)
    plot(feature.normalize(syllable.moving_window(am, 10)), label="amp")
    #plot(feature.normalize(syllable.moving_window(fr, 10)), label="freq")
    #plot(feature.normalize(am), label="amp")
    #plot(feature.normalize(fr), label="freq")
    legend(framealpha=0.5);
    show()
コード例 #3
0
ファイル: feature.py プロジェクト: peteraldaron/547take2
def align_peaks(sample, alignment_target, num_peaks, peak_r1=1, peak_r2=64):
    #doing a very direct and coarse alignment:
    #peak_s = signal.find_peaks_cwt(sample, np.arange(peak_r1,peak_r2))
    
    peak_s = list(signal.argrelmax(sample, order=32)[0])
    peak_s_vals = np.array([sample[x] for x in peak_s]).argsort()[-num_peaks:]
    peak_s = np.sort([peak_s[x] for x in peak_s_vals])

    #topnpeak_t = signal.find_peaks_cwt(alignment_target, np.arange(peak_r1,peak_r2))
    topnpeak_t = list(signal.argrelmax(sample, order=32)[0])
    peak_t_vals = np.array([alignment_target[x] for x in topnpeak_t]).argsort()[-num_peaks:]
    topnpeak_t = np.sort([topnpeak_t[x] for x in peak_t_vals])

    sample_partitions = np.split(sample, peak_s)
    chunk_len = []

    chunk_len.append(topnpeak_t[0])
    for i in range(1, len(topnpeak_t)):
        chunk_len.append(topnpeak_t[i]-topnpeak_t[i-1])
    chunk_len.append(len(alignment_target)-topnpeak_t[-1])
    new_samples = [interpolate_wave(seg[0], seg[1]) for seg in zip(sample_partitions, chunk_len)]
    #return np.hstack(new_samples)
    return normalize(syllable.moving_window(np.hstack(new_samples), 16))