Exemple #1
0
def get_stimulus(pattern_name="iso"):
    if use_matlab_stimulus:
        D = loadmat('examples/iso44_signal')
        sr = float(D['Fs'][0][0])
        s = D['signal'][0]  # analytical signal (generated in matlab)
        s = Signal(s, sr=sr)
    else:
        p = get_pattern(pattern_name)
        sr = 22050
        x, _ = p.as_signal(tempo=120.0,
                         reps=6.0,
                         lead_silence=0.0,
                         sr=sr,
                         click_freq=1200.0,
                         with_beat=False,
                         beat_freq=1800.0,
                         accented=False)
        x = Signal(x, sr=sr)
        s = onset_detection_signal(x)

        rms = np.sqrt(np.sum(s**2)/len(s))
        s *= 0.06/rms
        s = Signal(hilbert(s), sr=s.sr)
    t = s.time_vector()
    dt = 1/s.sr
    # print "SR: ", s.sr
    return s, t, dt
agogic_pattern = np.array([0, d_star]+[d_prime]*(N-1))

print agogic_pattern
print np.cumsum(agogic_pattern)

p = Pattern(agogic_pattern, numerator=N, denominator=D)

sr = 22050
x, _ = p.as_signal(120, reps=10, sr=sr)
# t = np.arange(len(x))/sr
# plt.plot(t, x)
# plt.show()


x = Signal(x, sr=sr)
x = 0.99*x.normalize()


play_pattern = False
if play_pattern:
    play_signal(x)

s = onset_detection_signal(x)
rms = np.sqrt(np.sum(s**2)/len(s))
s *= 0.06/rms
s = Signal(hilbert(s), sr=s.sr)
t = s.time_vector()
dt = 1/s.sr