Exemplo n.º 1
0
import plotly.graph_objects as go
import numpy as np
from scipy.interpolate.interpolate import interp1d
from Helper import read_wav, get_pulses_area, split_pulses, signal_to_pulses, get_frontier  #, save_wav, get_frontier
from scipy.signal import savgol_filter

# os.path.dirname(os.path.dirname(path))
'''==============='''
''' Read wav file '''
'''==============='''
fig = go.Figure()

parent_path = str(Path(os.path.abspath('./')).parents[1])
print(parent_path)
name = "piano33"
W, fps = read_wav(f"{parent_path}/Python/Samples/{name}.wav")

W = W[100103:100775]

W = W - np.average(W)
amplitude = np.max(np.abs(W))
W = W / amplitude
n = W.size
print(n)
X = np.arange(n)

pulses = signal_to_pulses(W)

areas_X, areas_Y = get_pulses_area(pulses)

pos_pulses, neg_pulses, pos_noises, neg_noises = split_pulses(pulses)
Exemplo n.º 2
0
class Pulse:
    # pulses = []
    # max_length = 0
    def __init__(self, x0, W):
        # Pulse.pulses.append(self)
        self.start = x0 - .5
        self.end = self.start + W.shape[0]
        self.n = W.shape[0]
        self.W = W
        self.normalized_W = W / np.max(np.abs(W))
        self.a = np.average(W)
        self.group = None


W, fps = read_wav("Samples/piano33.wav")
W = W - np.average(W)
a = np.max(np.abs(W))
W = W / a

# W = savgol_filter(W, 5, 3)

W = W[70000:80000]

n = W.shape[0]
X = np.arange(n)

## Split the signal into pulses
pulses = []
sign = np.sign(W[0])
x0 = 0
Exemplo n.º 3
0
        s = (a + b + c) / 2.0
        area = np.sqrt(s * (s - a) * (s - b) * (s - c))
        circum_r = a * b * c / (4.0 * area)
        if circum_r < alpha:
            add_edge(edges, ia, ib)
            add_edge(edges, ib, ic)
            add_edge(edges, ic, ia)
    return edges


'''==============='''
''' Read wav file '''
'''==============='''

name = "piano33"
W, fps = read_wav(f"Samples/{name}.wav")
W = W - np.average(W)
amplitude = np.max(np.abs(W))
W = W / amplitude

# W = W [ : W.size // 10]

pulses = signal_to_pulses(W)

# avg_len = np.average([p.len for p in pulses])
# avg_y = np.average([abs(p.y) for p in pulses])
# for p in pulses:
#   p.len = p.len / avg_len
#   p.y = p.y / avg_y

areas_X, areas_Y = get_pulses_area(pulses)
Exemplo n.º 4
0
        self.normalized_W = W / np.max(np.abs(W))
        self.avg = np.average(W)
        self.var = np.var(W)
        centered_W = W - np.average(W)
        FT = np.fft.rfft(centered_W)
        self.f = np.argmax(np.abs(FT))
        self.p = np.angle(FT[self.f])
        sign = np.sign(W[0])
        self.zeros = 0
        for w in centered_W:
            if sign != np.sign(w):
                self.zeros += 1
                sign = np.sign(w)


W, fps = read_wav("Samples/tom.wav")
W = W - np.average(W)
a = np.max(np.abs(W))
W = W / a

# W = savgol_filter(W, 5, 3)

# W = W [ : 5000]

n = W.shape[0]
X = np.arange(n)

## Split the signal into pulses
pulses = []
sign = np.sign(W[0])
x0 = 0