def synthbeats(duration, meanhr=60, stdhr=1, samplingfreq=250, sinfreq=None):
    t = (np.arange((duration * samplingfreq)) / float(samplingfreq))
    signal = np.zeros(len(t))
    print(len(t))
    print(len(signal))
    if (sinfreq == None):
        npeaks = (1.2 * ((duration * meanhr) / 60))
        hr = ((pl.randn(npeaks) * stdhr) + meanhr)
        peaks = (pl.cumsum((60.0 / hr)) * samplingfreq)
        peaks = peaks.astype('int')
        peaks = peaks[(peaks < (t[(- 1)] * samplingfreq))]
    else:
        hr = (meanhr + (sin((((2 * pi) * t) * sinfreq)) * float(stdhr)))
        index = int(((60.0 / hr[0]) * samplingfreq))
        peaks = []
        while (index < len(t)):
            peaks += [index]
            index += int(((60.0 / hr[index]) * samplingfreq))
    signal[peaks] = 1.0
    return (t, signal, peaks)
def synthbeats(duration, meanhr=60, stdhr=1, samplingfreq=250, sinfreq=None):
    t = (np.arange((duration * samplingfreq)) / float(samplingfreq))
    signal = np.zeros(len(t))
    print(len(t))
    print(len(signal))
    if (sinfreq == None):
        npeaks = (1.2 * ((duration * meanhr) / 60))
        hr = ((pl.randn(npeaks) * stdhr) + meanhr)
        peaks = (pl.cumsum((60.0 / hr)) * samplingfreq)
        peaks = peaks.astype('int')
        peaks = peaks[(peaks < (t[(- 1)] * samplingfreq))]
    else:
        hr = (meanhr + (sin((((2 * pi) * t) * sinfreq)) * float(stdhr)))
        index = int(((60.0 / hr[0]) * samplingfreq))
        peaks = []
        while (index < len(t)):
            peaks += [index]
            index += int(((60.0 / hr[index]) * samplingfreq))
    signal[peaks] = 1.0
    return (t, signal, peaks)