2017년 11월 6일 월요일

wav to scalogram

#!/usr/bin/python
import os
import re
import numpy
import scipy.misc
import os, array
from scipy import ndimage, misc
from wavelets import WaveletAnalysis
import wave
import sys
import matplotlib.pyplot as plt

images = []
for root, dirnames, filenames in os.walk("."):
    for filename in filenames:
        if re.search("\.(wav)$", filename):
            filepath = os.path.join(root, filename)
            f = open(filename,'rb');
            ln = os.path.getsize(filename); # length of file in bytes
            spf = wave.open(filename,'r')

#Extract Raw Audio from Wav File
            signal = spf.readframes(-1)
            signal = numpy.fromstring(signal, 'Int8')

# and a sample spacing
            dt = 10
            wa = WaveletAnalysis(signal, dt=dt)

# wavelet power spectrum
            power = wa.wavelet_power
# scales 
            scales = wa.scales

# associated time vector
            t = wa.time
# reconstruction of the original data
            rx = wa.reconstruction()

            fig, ax = plt.subplots()
            T, S = numpy.meshgrid(t, scales)
            ax.contourf(T, S)
            #ax.set_yscale('log')
            fig.savefig(filename + '.jpg')

댓글 1개:

  1. PyWavelets Installation for OSX
    pip install git+https://github.com/aaren/wavelets
    or install from a local copy:
    git clone https://github.com/aaren/wavelets.git
    cd wavelets
    pip install -r requirements.txt
    python setup.py install
    # Optional: Run testsuite
    pip install -r test-requirements.txt
    nosetests

    답글삭제

gpustat command

sudo apt install gpustat watch --color -n0.1 gpustat --color