def _wt_func(signal: ndarray, params: TFParams, return_opt: bool): impl = params.get_item("implementation") or "python" result = pymodalib.wavelet_transform( signal=signal, fs=params.fs, fmin=params.get_item("fmin"), fmax=params.get_item("fmax"), resolution=params.get_item("f0"), cut_edges=params.get_item("CutEdges") == "on", wavelet=params.get_item("Wavelet"), padding=params.get_item("Padding"), preprocess=params.get_item("Preprocess") == "on", rel_tolerance=params.get_item("RelTol"), return_opt=return_opt, implementation=impl, ) try: wt, freq, opt = result except ValueError: wt, freq = result opt = {} return wt, freq, opt
def _wt_surrogate_calc(wt_signal: ndarray, surrogate: ndarray, params: PCParams) -> ndarray: """ Calculates the phase coherence between a signal and a surrogate. :param wt_signal: the wavelet transform of the signal :param surrogate: the values of the surrogate (not the wavelet transform) :param params: the params object with parameters to pass to the wavelet transform function :return: [1D array] the wavelet phase coherence between the signal and the surrogate """ wt_surrogate, _ = pymodalib.wavelet_transform(surrogate, params.fs, **params.get(), Display="off") surr_avg, _ = wphcoh(wt_signal, wt_surrogate) return surr_avg
import platform import numpy import numpy as np import pymodalib os.chdir(os.path.abspath(os.path.dirname(__file__))) if __name__ == "__main__": signal = np.load("../1signal_10Hz.npy") fs = 10 times = np.arange(0, signal.size / fs, 1 / fs) wt, freq = pymodalib.wavelet_transform(signal, fs, cut_edges=True, implementation="matlab") # Save results to a data file. numpy.savez("output", wt=wt, freq=freq, times=times, implementation="MATLAB") if platform.system() != "Linux": # Plot the result by importing the plotting script. import plot_wavelet # Prevents Pycharm from cleaning up the import statement. dummy_variable = plot_wavelet
os.chdir(os.path.abspath(os.path.dirname(__file__))) if __name__ == "__main__": signal = np.load("../1signal_10Hz.npy") fs = 10 # Time values associated with the signal. times = np.arange(0, signal.size / fs, 1 / fs) # Frequency interval (0.07Hz-0.33Hz). fmin, fmax = 0.07, 0.33 # Note: your IDE may incorrectly display an error on this statement. wt, freq, wopt = pymodalib.wavelet_transform( signal, fs, fmin=fmin, fmax=fmax, return_opt=True, implementation="matlab", ) iamp, iphi, ifreq = pymodalib.ridge_extraction(wt, freq, fs, wopt=wopt) fig, ax = plt.subplots() wt_amp = np.abs(wt) mesh1, mesh2 = np.meshgrid(times, freq) # Plot wavelet transform. ax.contourf(mesh1, mesh2, wt_amp) # Plot frequency ridge. ax.plot(times, ifreq, color="red")