예제 #1
0
Average_ref_X_smooth = np.unique(np.abs(Average_ref_X_smooth))

Average_ref_X_smooth_linear = hp.linearize_pc_approx(Average_ref_X_smooth)

pos_avgpc, pos_orig_pcs, pos_norm_pcs = average_pc_waveform(
    Average_ref_X_smooth, W)

pcx = interpolate.interp1d(np.linspace(0, 1, pos_avgpc.size), pos_avgpc,
                           "cubic")
Wp = np.zeros(n)
for i in range(Average_ref_X_smooth_linear.size - 1):
    x0 = Average_ref_X_smooth_linear[i]
    x1 = Average_ref_X_smooth_linear[i + 1]
    Wp[x0:x1] = pcx(np.linspace(0, 1, x1 - x0))

se.save_wav(Wp, "Wp.wav", fps=fps)
'''============================================================================'''
'''                              PLOT LINES                                    '''
'''============================================================================'''

fig = fig = go.Figure()
fig.layout.template = "plotly_white"
# fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor="black")
fig.update_layout(
    # title = name,
    xaxis_title="Length",
    yaxis_title="Number of Ocurrences",

    # yaxis = dict(        # <|<|<|<|<|<|<|<|<|<|<|<|
    #   scaleanchor = "x", # <|<|<|<|<|<|<|<|<|<|<|<|
    #   scaleratio = 1,    # <|<|<|<|<|<|<|<|<|<|<|<|
예제 #2
0
    # Wp[x0 : x1] = pcx(np.linspace(0, 1, x1 - x0 + 1))[0:-1]
    # d_Wp[x0 : x1] = d_pcx(np.linspace(0, 1, x1 - x0 + 1))[0:-1]
    Wp[x0:x1] = pcx(np.linspace(0, 1, Wp[x0:x1].size, endpoint=False))
    d_Wp[x0:x1] = d_pcx(np.linspace(0, 1, d_Wp[x0:x1].size, endpoint=False))
'''==========================='''
''' Envelope: '''
'''==========================='''

Xf = np.unique(np.hstack([Xpos, Xneg]))
Ie = hp.split_raw_frontier(Xf, W, 5)
Ie = Xf[Ie].tolist()
Ae = hp.constrained_least_squares_arbitrary_intervals_X_to_Y(
    Wp, d_Wp, W, Ie, 2, "k")
E = hp.coefs_to_array_arbitrary_intervals(Ae, X, Ie, n)

se.save_wav(E * Wp, f"{name}_est.wav", fps=fps)
se.save_wav(W - E * Wp, f"{name}_res.wav", fps=fps)
print("############# HERE #############")
'''====================================================================================================================='''
transp_black = "rgba(38, 12, 12, 0.2)"


def to_plot(Matrix):
    X = []
    Y = []
    for line in Matrix:
        for x, y in enumerate(line):
            X.append(x)
            Y.append(y)
        X.append(None)
        Y.append(None)
예제 #3
0
name = "piano33"
W, fps = se.read_wav(f"Samples/{name}.wav")
W = W - np.average(W)
'''get and refine frontiers '''
Xpos, Xneg = se.get_frontiers(W)
Xpos = hp.refine_frontier_iter(Xpos, W)
Xneg = hp.refine_frontier_iter(Xneg, W)

compositeW = 0
WWe = []
WWl = []
residues = [W]
for i in range(3):
    We, Wl, W = loop(W, Xpos, Xneg)
    compositeW += Wl
    se.save_wav(Wl, f"+0{i+1}_{name}.wav", fps=fps)
    WWe.append(We)
    WWl.append(Wl)
    residues.append(W)

se.save_wav(residues[1], "res.wav", fps=fps)

se.save_wav(compositeW, f"+Final_{name}.wav", fps=fps)
'''============================================================================'''
'''                                    PLOT                                    '''
'''============================================================================'''
fig = go.Figure()
fig.layout.template = "plotly_white"
# fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor="black")
fig.update_layout(
    # title = name,
예제 #4
0
tau = np.linalg.inv(V @ QTQinv @ V.T)
QTY = Q.T @ Y
# par1 = V @ QTQinv @ QTY
A = QTQinv @ (QTY - V.T @ tau @ V @ QTQinv @ QTY)
A = np.reshape(A, (2, -1))

print(A)

Xc = np.linspace(0, 1, avgL, dtype=np.float64)
Yc = poly.polyval(Xc, A[0, :])

ncycles = int(np.round((Xpos.size + Xneg.size) / 2))

Wr = np.tile(Yc, ncycles) * 9000

se.save_wav(Wr)

# exit()
'''============================================================================'''
'''                                    PLOT                                    '''
'''============================================================================'''
fig = go.Figure()
fig.layout.template = "plotly_white"
# fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor="black")
fig.update_layout(
    # title = name,
    xaxis_title="x",
    yaxis_title="Amplitude",
    # yaxis = dict(scaleanchor = "x", scaleratio = 1 ),                   # <|<|<|<|<|<|<|<|<|<|<|<|
    legend=dict(orientation='h', yanchor='top', xanchor='left', y=1.1),
    margin=dict(l=5, r=5, b=5, t=5),
예제 #5
0
pa, used_positive_frontier, _ = hp.pseudocycles_average(Xpos, Xneg, W)
A = hp.approximate_pseudocycles_average(pa)
# if used_positive_frontier:
#   Wp = hp.parametric_W(hp.linearize_pc(Xpos.astype(np.int)), A, n, False)
# else:
#   Wp = hp.parametric_W(hp.linearize_pc(Xneg.astype(np.int)), A, n, False)

if used_positive_frontier:
    Wp = hp.parametric_W(Xpos, A, n, False)
else:
    Wp = hp.parametric_W(Xneg, A, n, False)

We = Wp * E

se.save_wav(We)

Xintervals = []
Yintervals = []
for x in Xf[Ix]:
    Xintervals.append(x)
    Xintervals.append(x)
    Xintervals.append(None)
    Yintervals.append(-amp)
    Yintervals.append(amp)
    Yintervals.append(None)
'''============================================================================'''
'''                                    PLOT                                    '''
'''============================================================================'''
fig = go.Figure()
fig.layout.template = "plotly_white"
예제 #6
0
# avgpc = avgpc / 7

wave = []
a = np.max(np.abs(pos_avgpc))

for i in range(Xpos.size):
  amp = np.max(np.abs(pos_avgpc))
  w = a * pos_avgpc / amp
  a = w[-1]
  for j in w:
    wave.append(j)

wave = np.array(wave)

se.save_wav(wave)

'''============================================================================'''
'''                                    PLOT                                    '''
'''============================================================================'''
fig = go.Figure()
fig.layout.template ="plotly_white"
# fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor="black")
fig.update_layout(
  # title = name,
  xaxis_title="x",
  yaxis_title="Amplitude",
  # yaxis = dict(scaleanchor = "x", scaleratio = 1 ),                   # <|<|<|<|<|<|<|<|<|<|<|<|
  legend=dict(orientation='h', yanchor='top', xanchor='left', y=1.1),
  margin=dict(l=5, r=5, b=5, t=5),
  font=dict(
예제 #7
0
Xf = np.unique(np.hstack([Xpos, Xneg]))
Ix = hp.split_raw_frontier(Xf, W, 10)

A = hp.constrained_least_squares_arbitrary_intervals_wtow(
    Wp, dWp, W, Xf[Ix].tolist(), 2)

E = hp.coefs_to_array_arbitrary_intervals_wtow(A, Wp, Xf[Ix].tolist(), n)

env = hp.coefs_to_array_arbitrary_intervals(A, X, Xf[Ix].tolist(), n)
# Ws = hp.parametric_W(Xpos, Ap, n, True)

We = E

# W = W * EWp
se.save_wav(We, fps=fps)
error = W - We
se.save_wav(error, "error.wav", fps=fps)

Xintervals = []
Yintervals = []
for x in Xf[Ix]:
    Xintervals.append(x)
    Xintervals.append(x)
    Xintervals.append(None)
    Yintervals.append(-amp)
    Yintervals.append(amp)
    Yintervals.append(None)
'''============================================================================'''
'''                                    PLOT                                    '''
'''============================================================================'''
예제 #8
0
    Xl = np.linspace(0, 1, int(x1) - int(x0) + 1, dtype=np.float64)
    Yl = poly.polyval(Xl, A)
    for j in range(Yl.size - 1):
        Xparam.append(x0 + j)
        Wparam.append(Yl[j])
for x in range(Xp[-1], n):
    Xparam.append(x)
    Wparam.append(0)

Wparam = np.array(Wparam)  #* amp

print(f"Wn = {W.size}, Wpn = {Wparam.size}")

# print(Wparam)

se.save_wav(Wparam)
'''============================================================================'''
'''                             SPLIT WAVE                                 '''
'''============================================================================'''
n_intervals = 3

limit = np.sum(np.abs(W)) / n_intervals
Ix = []
x0 = 0

for _ in range(n_intervals - 1):
    curr_sum = W[x0]
    while curr_sum < limit:
        x0 += 1
        curr_sum += np.abs(W[x0])
    Ix.append(x0 - 1)