Python scipy.signal.hilbert() Examples
The following are 30
code examples of scipy.signal.hilbert().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.signal
, or try the search function
.
Example #1
Source File: SynchronisationIndex.py From ComputationalNeurodynamics with GNU General Public License v3.0 | 6 votes |
def SynchronisationIndex(MF1, MF2): """ Computes the synchronisation index between two populations given firing data MF1 and MF2. """ if len(MF1) != len(MF2): raise Exception("Both time series must have the same length") # Centre time series on zero MF1 = MF1 - np.mean(MF1) MF2 = MF2 - np.mean(MF2) # Calculate phase using Hilbert transform phase1 = np.angle(hilbert(MF1)) phase2 = np.angle(hilbert(MF2)) # Calculate synchronisation index phi = np.abs((np.exp(1j*phase1) + np.exp(1j*phase2)) / 2.0) return np.mean(phi)
Example #2
Source File: connectivity.py From mmvt with GNU General Public License v3.0 | 6 votes |
def pli(data, channels_num, window_length): try: from scipy.signal import hilbert if data.shape[0] != channels_num: data = data.T data_hil = hilbert(data) # if data_hil.shape != (channels_num, window_length): # raise Exception('PLI: Wrong dimentions!') m = np.zeros((channels_num, channels_num)) for i in range(channels_num): for j in range(channels_num): if i < j: m[i, j] = abs(np.mean(np.sign(np.imag(data_hil[i] / data_hil[j])))) # m[i, j] = abs(np.mean(np.sign(np.imag(data_hil[:, i] / data_hil[:, j])))) return m + m.T except: print(traceback.format_exc()) return None
Example #3
Source File: fit.py From rapidtide with Apache License 2.0 | 6 votes |
def phaseanalysis(firstharmonic, displayplots=False): print('entering phaseanalysis') analytic_signal = hilbert(firstharmonic) amplitude_envelope = np.abs(analytic_signal) instantaneous_phase = np.angle(analytic_signal) if displayplots: print('making plots') fig = pl.figure() ax1 = fig.add_subplot(311) ax1.set_title('Analytic signal') X = np.linspace(0.0, 1.0, num=len(firstharmonic)) pl.plot(X, analytic_signal.real, 'k', X, analytic_signal.imag, 'r') ax2 = fig.add_subplot(312) ax2.set_title('Phase') pl.plot(X, instantaneous_phase, 'g') ax3 = fig.add_subplot(313) ax3.set_title('Amplitude') pl.plot(X, amplitude_envelope, 'b') pl.show() pl.savefig('phaseanalysistest.jpg') instantaneous_phase = np.unwrap(instantaneous_phase) return instantaneous_phase, amplitude_envelope
Example #4
Source File: adjoint.py From seisflows with BSD 2-Clause "Simplified" License | 6 votes |
def InstantaneousPhase(syn, obs, nt, dt, eps=0.05): """ Instantaneous phase (from Bozdag et al. 2011, eq 27) """ r = _np.real(_analytic(syn)) i = _np.imag(_analytic(syn)) phi_syn = _np.arctan2(i, r) r = _np.real(_analytic(obs)) i = _np.imag(_analytic(obs)) phi_obs = _np.arctan2(i, r) phi_rsd = phi_syn - phi_obs esyn = abs(_analytic(syn)) emax = max(esyn**2.) wadj = phi_rsd*_np.imag(_analytic(syn))/(esyn**2. + eps*emax) + \ _np.imag(_analytic(phi_rsd * syn/(esyn**2. + eps*emax))) return wadj
Example #5
Source File: adjoint.py From seisflows with BSD 2-Clause "Simplified" License | 6 votes |
def InstantaneousPhase2(syn, obs, nt, dt, eps=0.): esyn = abs(_analytic(syn)) eobs = abs(_analytic(obs)) esyn1 = esyn + eps*max(esyn) eobs1 = eobs + eps*max(eobs) esyn3 = esyn**3 + eps*max(esyn**3) diff1 = syn/(esyn1) - obs/(eobs1) diff2 = _hilbert(syn)/esyn1 - _hilbert(obs)/eobs1 part1 = diff1*_hilbert(syn)**2/esyn3 - diff2*syn*_hilbert(syn)/esyn3 part2 = diff1*syn*_hilbert(syn)/esyn3 - diff2*syn**2/esyn3 wadj = part1 + _hilbert(part2) return wadj # Migration
Example #6
Source File: noise_module.py From NoisePy with MIT License | 6 votes |
def snr(data,sampling_rate): """ Signal to noise ratio of N cross-correlations. Follows method of Clarke et. al, 2011. Measures SNR at each point. """ data = np.array(data) N,t = data.shape data_mean = np.mean(data,axis=0) # calculate noise and envelope functions sigma = np.mean(data**2,axis=0) - (data_mean)**2 sigma = np.sqrt(sigma/(N-1.)) s = np.abs(data_mean + 1j*scipy.signal.hilbert(data_mean)) # smooth with 10 second sliding cosine window # half window length is 5s, i.e. 5 * sampling rate sigma = smooth(sigma,half_win=int(sampling_rate*5)) s = smooth(s,half_win=int(sampling_rate*5)) return np.real(s/sigma)
Example #7
Source File: test_basic.py From arlpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_envelope(self): x = np.random.normal(0, 1, 1000) self.assertArrayEqual(signal.envelope(x), np.abs(sp.hilbert(x)))
Example #8
Source File: signal.py From arlpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def envelope(x, axis=-1): """Generate a Hilbert envelope of the real signal x. :param x: real passband signal :param axis: axis of the signal, if multiple signals specified """ return _np.abs(_sig.hilbert(x, axis=axis))
Example #9
Source File: representations.py From CorpusTools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def to_envelopes(path,num_bands,freq_lims,downsample=True): """Generate amplitude envelopes from a full path to a .wav, following Lewandowski (2012). Parameters ---------- filename : str Full path to .wav file to process. num_bands : int Number of frequency bands to use. freq_lims : tuple Minimum and maximum frequencies in Hertz to use. downsample : bool If true, envelopes will be downsampled to 120 Hz Returns ------- 2D array Amplitude envelopes over time """ sr, proc = preproc(path,alpha=0.97) #proc = proc / 32768 #hack!! for 16-bit pcm proc = proc/sqrt(mean(proc**2))*0.03; bandLo = [ freq_lims[0]*exp(log(freq_lims[1]/freq_lims[0])/num_bands)**x for x in range(num_bands)] bandHi = [ freq_lims[0]*exp(log(freq_lims[1]/freq_lims[0])/num_bands)**(x+1) for x in range(num_bands)] envelopes = [] for i in range(num_bands): b, a = butter(2,(bandLo[i]/(sr/2),bandHi[i]/(sr/2)), btype = 'bandpass') env = filtfilt(b,a,proc) env = abs(hilbert(env)) if downsample: env = resample(env,int(ceil(len(env)/int(ceil(sr/120))))) #env = decimate(env,int(ceil(sr/120))) envelopes.append(env) return array(envelopes).T
Example #10
Source File: derive.py From teneto with GNU General Public License v3.0 | 5 votes |
def _instantaneous_phasesync(data, params, report): """Derivce instantaneous phase synchrony. See func: teneto.timeseries.derive_temporalnetwork.""" analytic_signal = hilbert(data.transpose()) instantaneous_phase = np.angle(analytic_signal) ips = np.zeros([data.shape[1], data.shape[1], data.shape[0]]) for n in range(data.shape[1]): for m in range(data.shape[1]): ips[n, m, :] = 1 - np.sin(np.abs(instantaneous_phase[n] - instantaneous_phase[m])/2) report = {} report['method'] = 'instantaneousphasesync' report['instantaneousphasesync'] = {} return ips, report
Example #11
Source File: signal.py From alphacsc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def fast_hilbert(array): n_points = array.shape[0] n_fft = next_power2(n_points) return hilbert(array, n_fft)[:n_points]
Example #12
Source File: comp_stacking.py From NoisePy with MIT License | 5 votes |
def pws(cc_array,sampling_rate,power=2,pws_timegate=5.): ''' Performs phase-weighted stack on array of time series. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack PARAMETERS: --------------------- arr: N length array of time series data (numpy.ndarray) sampling_rate: sampling rate of time series arr (int) power: exponent for phase stack (int) pws_timegate: number of seconds to smooth phase stack (float) RETURNS: --------------------- weighted: Phase weighted stack of time series data (numpy.ndarray) Originally written by Tim Clements Modified by Chengxin Jiang @Harvard ''' if cc_array.ndim == 1: print('2D matrix is needed for pws') return cc_array N,M = cc_array.shape # construct analytical signal analytic = hilbert(cc_array,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0) phase_stack = np.abs(phase_stack)**(power) # weighted is the final waveforms weighted = np.multiply(cc_array,phase_stack) return np.mean(weighted,axis=0)
Example #13
Source File: noise_module.py From NoisePy with MIT License | 5 votes |
def pws(arr,sampling_rate,power=2,pws_timegate=5.): ''' Performs phase-weighted stack on array of time series. Modified on the noise function by Tim Climents. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack PARAMETERS: --------------------- arr: N length array of time series data (numpy.ndarray) sampling_rate: sampling rate of time series arr (int) power: exponent for phase stack (int) pws_timegate: number of seconds to smooth phase stack (float) RETURNS: --------------------- weighted: Phase weighted stack of time series data (numpy.ndarray) ''' if arr.ndim == 1: return arr N,M = arr.shape analytic = hilbert(arr,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0) phase_stack = np.abs(phase_stack)**(power) # smoothing #timegate_samples = int(pws_timegate * sampling_rate) #phase_stack = moving_ave(phase_stack,timegate_samples) weighted = np.multiply(arr,phase_stack) return np.mean(weighted,axis=0)
Example #14
Source File: noise_module.py From NoisePy with MIT License | 5 votes |
def pws(arr,sampling_rate,power=2,pws_timegate=5.): ''' Performs phase-weighted stack on array of time series. Modified on the noise function by Tim Climents. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack PARAMETERS: --------------------- arr: N length array of time series data (numpy.ndarray) sampling_rate: sampling rate of time series arr (int) power: exponent for phase stack (int) pws_timegate: number of seconds to smooth phase stack (float) RETURNS: --------------------- weighted: Phase weighted stack of time series data (numpy.ndarray) ''' if arr.ndim == 1: return arr N,M = arr.shape analytic = hilbert(arr,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0) phase_stack = np.abs(phase_stack)**(power) # smoothing #timegate_samples = int(pws_timegate * sampling_rate) #phase_stack = moving_ave(phase_stack,timegate_samples) weighted = np.multiply(arr,phase_stack) return np.mean(weighted,axis=0)
Example #15
Source File: noise_module.py From NoisePy with MIT License | 5 votes |
def pws(arr,sampling_rate,power=2,pws_timegate=5.): ''' Performs phase-weighted stack on array of time series. Modified on the noise function by Tim Climents. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack PARAMETERS: --------------------- arr: N length array of time series data (numpy.ndarray) sampling_rate: sampling rate of time series arr (int) power: exponent for phase stack (int) pws_timegate: number of seconds to smooth phase stack (float) RETURNS: --------------------- weighted: Phase weighted stack of time series data (numpy.ndarray) ''' if arr.ndim == 1: return arr N,M = arr.shape analytic = hilbert(arr,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0) phase_stack = np.abs(phase_stack)**(power) # smoothing #timegate_samples = int(pws_timegate * sampling_rate) #phase_stack = moving_ave(phase_stack,timegate_samples) weighted = np.multiply(arr,phase_stack) return np.mean(weighted,axis=0)
Example #16
Source File: noise_module.py From NoisePy with MIT License | 5 votes |
def pws(arr,power=2.,sampling_rate=20.,pws_timegate = 5.): """ Performs phase-weighted stack on array of time series. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack :type arr: numpy.ndarray :param arr: N length array of time series data :type power: float :param power: exponent for phase stack :type sampling_rate: float :param sampling_rate: sampling rate of time series :type pws_timegate: float :param pws_timegate: number of seconds to smooth phase stack :Returns: Phase weighted stack of time series data :rtype: numpy.ndarray """ if arr.ndim == 1: return arr N,M = arr.shape analytic = arr + 1j * hilbert(arr,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0)/N phase_stack = np.abs(phase_stack)**2 # smoothing timegate_samples = int(pws_timegate * sampling_rate) phase_stack = runningMean(phase_stack,timegate_samples) weighted = np.multiply(arr,phase_stack) return np.mean(weighted,axis=0)/N
Example #17
Source File: noise_module.py From NoisePy with MIT License | 5 votes |
def pws(arr,sampling_rate,power=2,pws_timegate=5.): """ Performs phase-weighted stack on array of time series. Modified on the noise function by Tim Climents. Follows methods of Schimmel and Paulssen, 1997. If s(t) is time series data (seismogram, or cross-correlation), S(t) = s(t) + i*H(s(t)), where H(s(t)) is Hilbert transform of s(t) S(t) = s(t) + i*H(s(t)) = A(t)*exp(i*phi(t)), where A(t) is envelope of s(t) and phi(t) is phase of s(t) Phase-weighted stack, g(t), is then: g(t) = 1/N sum j = 1:N s_j(t) * | 1/N sum k = 1:N exp[i * phi_k(t)]|^v where N is number of traces used, v is sharpness of phase-weighted stack :type arr: numpy.ndarray :param arr: N length array of time series data :type power: float :param power: exponent for phase stack :type sampling_rate: float :param sampling_rate: sampling rate of time series :type pws_timegate: float :param pws_timegate: number of seconds to smooth phase stack :Returns: Phase weighted stack of time series data :rtype: numpy.ndarray """ if arr.ndim == 1: return arr N,M = arr.shape analytic = hilbert(arr,axis=1, N=next_fast_len(M))[:,:M] phase = np.angle(analytic) phase_stack = np.mean(np.exp(1j*phase),axis=0) phase_stack = np.abs(phase_stack)**(power) # smoothing #timegate_samples = int(pws_timegate * sampling_rate) #phase_stack = moving_ave(phase_stack,timegate_samples) weighted = np.multiply(arr,phase_stack) return np.mean(weighted,axis=0)
Example #18
Source File: kpm.py From quantum-honeycomp with GNU General Public License v3.0 | 5 votes |
def correlator0d(m_in,i=0,j=0,scale=10.,npol=None,ne=500,write=True, x=None): """Return two arrays with energies and local DOS""" if npol is None: npol = ne mus = get_moments_ij(m_in/scale,n=npol,i=i,j=j,use_fortran=True) if np.sum(np.abs(mus.imag))>0.001: # print("WARNING, off diagonal has nonzero imaginary elements",np.sum(np.abs(mus.imag))) pass if x is None: xs = np.linspace(-1.0,1.0,ne,endpoint=True)*0.99 # energies else: xs = x/scale # use from input ys = generate_green_profile(mus,xs,kernel="jackson",use_fortran=False)/scale*np.pi # so it is the Green function # imys = hilbert(ys).imag if write: np.savetxt("CORRELATOR_KPM.OUT",np.matrix([scale*xs,-ys.imag,ys.real]).T) return (scale*xs,ys.real,ys.imag)
Example #19
Source File: spectrum.py From pactools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def phase_amplitude(signals, phase=True, amplitude=True): """Extract instantaneous phase and amplitude with Hilbert transform""" # one dimension array if signals.ndim == 1: signals = signals[None, :] one_dim = True elif signals.ndim == 2: one_dim = False else: raise ValueError('Impossible to compute phase_amplitude with ndim =' ' %s.' % (signals.ndim, )) n_epochs, n_points = signals.shape n_fft = compute_n_fft(signals) sig_phase = np.empty(signals.shape) if phase else None sig_amplitude = np.empty(signals.shape) if amplitude else None for i, sig in enumerate(signals): sig_complex = hilbert(sig, n_fft)[:n_points] if phase: sig_phase[i] = np.angle(sig_complex) if amplitude: sig_amplitude[i] = np.abs(sig_complex) # one dimension array if one_dim: if phase: sig_phase = sig_phase[0] if amplitude: sig_amplitude = sig_amplitude[0] return sig_phase, sig_amplitude
Example #20
Source File: spectrum.py From pactools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def crop_for_fast_hilbert(signals): """Crop the signal to have a good prime decomposition, for hilbert filter. """ if signals.ndim < 2: tmax = signals.shape[0] while prime_factors(tmax)[-1] > 20: tmax -= 1 return signals[:tmax] else: tmax = signals.shape[1] while prime_factors(tmax)[-1] > 20: tmax -= 1 return signals[:, :tmax]
Example #21
Source File: mark.py From psola with MIT License | 5 votes |
def __hilbert(x): """ Hilbert transform to the power of 2 Args: x (array): numpy array of data Returns: y (array): numpy array of Hilbert transformed x (same size as x) """ l = x.size pad = int(2**(np.floor(np.log2(l)) + 1)) y = signal.hilbert(x, N=pad)[:l] return y
Example #22
Source File: training_audio.py From ibllib with MIT License | 5 votes |
def _detect_ready_tone(w, fs): # get envelope of DC free signal and envelope of BP signal around freq of interest h = np.abs(signal.hilbert(w - np.median(w))) fh = np.abs(signal.hilbert(dsp.bp(w, si=1 / fs, b=FTONE * np.array([0.9, 0.95, 1.15, 1.1])))) dtect = _running_mean(fh / (h + 1e-3), int(fs * 0.1)) > 0.8 return np.where(np.diff(dtect.astype(int)) == 1)[0] # tone = np.sin(2 * np.pi * FTONE * np.arange(0, fs * 0.1) / fs) # tone = tone / np.sum(tone ** 2) # xc = np.abs(signal.hilbert(signal.correlate(w - np.mean(w), tone)))
Example #23
Source File: evaluate.py From 2.5D-Visual-Sound with Creative Commons Attribution 4.0 International | 5 votes |
def Envelope_distance(predicted_binaural, gt_binaural): #channel1 pred_env_channel1 = np.abs(hilbert(predicted_binaural[0,:])) gt_env_channel1 = np.abs(hilbert(gt_binaural[0,:])) channel1_distance = np.sqrt(np.mean((gt_env_channel1 - pred_env_channel1)**2)) #channel2 pred_env_channel2 = np.abs(hilbert(predicted_binaural[1,:])) gt_env_channel2 = np.abs(hilbert(gt_binaural[1,:])) channel2_distance = np.sqrt(np.mean((gt_env_channel2 - pred_env_channel2)**2)) #sum the distance between two channels envelope_distance = channel1_distance + channel2_distance return float(envelope_distance)
Example #24
Source File: math.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def hilbert(w): return np.imag(analytic(w))
Example #25
Source File: misfit.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def Envelope(syn, obs, nt, dt, eps=0.05): """ Envelope difference (Yuan et al 2015, eq 9) """ esyn = abs(_analytic(syn)) eobs = abs(_analytic(obs)) ersd = esyn-eobs return np.sqrt(np.sum(ersd*ersd*dt))
Example #26
Source File: misfit.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def InstantaneousPhase(syn, obs, nt, dt, eps=0.05): """ Instantaneous phase from Bozdag et al. 2011 """ r = np.real(_analytic(syn)) i = np.imag(_analytic(syn)) phi_syn = np.arctan2(i, r) r = np.real(_analytic(obs)) i = np.imag(_analytic(obs)) phi_obs = np.arctan2(i, r) phi_rsd = phi_syn - phi_obs return np.sqrt(np.sum(phi_rsd*phi_rsd*dt))
Example #27
Source File: misfit.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def Envelope2(syn, obs, nt, dt, eps=0.): """ Envelope amplitude ratio (Yuan et al 2015, eq B-1) """ esyn = abs(_analytic(syn)) eobs = abs(_analytic(obs)) raise NotImplementedError
Example #28
Source File: misfit.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def Envelope3(syn, obs, nt, dt, eps=0.): """ Envelope cross-correlation lag (Yuan et al 2015, eqs B-4) """ esyn = abs(_analytic(syn)) eobs = abs(_analytic(obs)) return Traveltime(esyn, eobs, nt, dt)
Example #29
Source File: hilbert.py From neurodsp with Apache License 2.0 | 5 votes |
def robust_hilbert(sig, increase_n=False): """Compute the Hilbert transform, ignoring any boundaries that are NaN. Parameters ---------- sig : 1d array Time series. increase_n : bool, optional, default: False If True, zero pad the signal to length the next power of 2 for the Hilbert transform. This is because ``scipy.signal.hilbert`` can be very slow for some signal lengths. Returns ------- sig_hilb : 1d array The Hilbert transform of the input signal. Examples -------- Compute a Hilbert transform of a signal, using zero padding: >>> from neurodsp.sim import sim_combined >>> sig = sim_combined(n_seconds=10, fs=500, ... components={'sim_powerlaw': {}, 'sim_oscillation': {'freq': 10}}) >>> sig_hilb = robust_hilbert(sig, increase_n=True) """ # Extract the signal that is not nan sig_nonan, sig_nans = remove_nans(sig) # Compute Hilbert transform of signal without nans if increase_n: sig_len = len(sig_nonan) n_components = 2**(int(np.log2(sig_len)) + 1) sig_hilb_nonan = hilbert(sig_nonan, n_components)[:sig_len] else: sig_hilb_nonan = hilbert(sig_nonan) # Fill in output hilbert with nans on edges sig_hilb = restore_nans(sig_hilb_nonan, sig_nans, dtype=complex) return sig_hilb
Example #30
Source File: adjoint.py From seisflows with BSD 2-Clause "Simplified" License | 5 votes |
def Envelope3(syn, obs, nt, dt, eps=0.): """ Envelope cross-correlation lag (Yuan et al 2015, eqs B-2, B-5) """ esyn = abs(_analytic(syn)) eobs = abs(_analytic(obs)) erat = _np.zeros(nt) erat[1:-1] = (esyn[2:] - esyn[0:-2])/(2.*dt) erat[1:-1] /= esyn[1:-1] erat *= misfit.Envelope3(syn, obs, nt, dt) wadj = -erat*syn + _hilbert(erat*_hilbert(esyn)) return wadj