コード例 #1
0
def wavelet(nni=None,
            rpeaks=None,
            fs=4.,
            fbands=None,
            detrend=True,
            show=True,
            show_param=True,
            legend=True):

    # Check input
    nn = tools.check_input(nni, rpeaks)
    # Verify or set default frequency bands
    fbands = fd._check_freq_bands(fbands)

    # 外れ値をスプライン補間
    nni = _artefact_correction(nni, threshold=0.25)

    # 4Hzでリサンプリング
    nn_interpol = detrending.resample_to_4Hz(nni, fs)

    # 平滑化
    if detrend:
        nn_interpol = detrending.detrend(nn_interpol, Lambda=500)

    freqs = np.arange(0.001, 1, 0.025)
    omega0 = 8
    r = pycwt.cwt_f(nn_interpol, freqs, fs, pycwt.Morlet(omega0))
    rr = np.abs(r)
    t_interpol = np.arange(0, len(nn_interpol) / fs, 1. / fs)
    plt.imshow(rr,
               aspect='auto',
               extent=(t_interpol[0], t_interpol[-1], freqs[0], freqs[-1]))
    plt.xlabel('Time[s]')
    plt.ylabel('Frequency[Hz]')
    plt.show()
    pass
コード例 #2
0
ファイル: datacut.py プロジェクト: kitada4010/sbc
starttime = float(sys.argv[1])
endtime = float(sys.argv[2])
start = int(starttime * fs)
end = int(endtime * fs)

del starttime, endtime

specdatab = np.array(df[start:end])
specdataa = specdatab.flatten()

fp.close

P = 1024
widths = np.arange(1, P)

cwtmatr = pycwt.cwt_f(specdataa, widths, fs, pycwt.Morlet())
rr = np.abs(cwtmatr)
del cwtmatr

spec = pd.DataFrame(rr)
del specdataa

del rr
s = 100
print(len(df[start:end]))
spec_new = pd.DataFrame(index=spec.index, columns=[])
for i in range(0, len(df[start:end]), s):
    spec1 = spec[i]
    spec_new[i / s] = spec1
spec_new.T.to_csv(sys.argv[3] + '-' + sys.argv[4] + '-' + sys.argv[1] + '-' +
                  sys.argv[2] + '-cut.csv',
コード例 #3
0
from swan import pycwt
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 20, 0.01)
y = np.sin(2 * np.pi * 2 * x) * 2 + np.sin(2 * np.pi * 5 * x) * \
    2 + np.sin(2 * np.pi * 10 * x)
plt.plot(x, y)
plt.show()

Fs = 1000
omega0 = 8
# (1) Freqを指定してcwt
freqs = np.arange(0.1, 20, 0.025)
r = pycwt.cwt_f(y, freqs, Fs, pycwt.Morlet(omega0))
rr = np.abs(r)
plt.rcParams['figure.figsize'] = (10, 6)
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.75, 0.7, 0.2])
ax2 = fig.add_axes([0.1, 0.1, 0.7, 0.60], sharex=ax1)
ax3 = fig.add_axes([0.83, 0.1, 0.03, 0.6])
ax1.plot(x, y, 'k')
# , interpolation='nearest')
img = ax2.imshow(np.flipud(rr), extent=[0, 20, 0.1, 20], aspect='auto')
twin_ax = ax2
twin_ax.set_yscale('log')
twin_ax.set_xlim(0, 20)
twin_ax.set_ylim(0.1, 20)
ax2.tick_params(which='both', labelleft=False, left=False)
twin_ax.tick_params(which='both', labelleft=True, left=True, labelright=False)
fig.colorbar(img, cax=ax3)
コード例 #4
0
del datatime

specdatab = np.array(df[start:end])
del df
specdataa = specdatab.flatten()
fp.close
del specdatab
#widths = np.arange(1, 31)
P = 1024
#P = 16384

widths = np.arange(1, P)

plt.subplot(2, 1, 2)
fc = 1.5
cwtmatr = pycwt.cwt_f(specdataa, widths, 25000, pycwt.Morlet(fc))
rr = np.abs(cwtmatr)

del widths
#im = plt.imshow(np.flipud(rr), extent=[starttime, endtime, P, 1], aspect='auto',interpolation='nearest')
im = plt.imshow(np.flipud(rr),
                extent=[0, (endtime - starttime) * 1000, P, 1],
                aspect='auto',
                interpolation='nearest')
#xlim(starttime, endtime)
#xlim(0, (endtime-starttime)*1000)
#ylim(0, 4096)
plt.tick_params(length=10)
xlabel("time [ms]")
ylabel("frequency [Hz]  ")
#plt.yscale("log")