def harmonic_reference(f0, fs, Ns, Nh=1, standardise_out=False): """ Generate reference signals for canonical correlation analysis (CCA) -based steady-state visual evoked potentials (SSVEPs) detection [1, 2]. function [ y_ref ] = cca_reference(listFreq, fs, Ns, Nh) Input: f0 : stimulus frequency fs : Sampling frequency Ns : # of samples in trial Nh : # of harmonics Output: X : Generated reference signals with shape (Nf, Ns, 2*Nh) """ X = np.zeros((Nh * 2, Ns)) for harm_i in range(Nh): # Sin and Cos X[2 * harm_i, :] = np.sin( np.arange(1, Ns + 1) * (1 / fs) * 2 * np.pi * (harm_i + 1) * f0) gc.collect() X[2 * harm_i + 1, :] = np.cos( np.arange(1, Ns + 1) * (1 / fs) * 2 * np.pi * (harm_i + 1) * f0) gc.collect() # print(micropython.mem_info(1)) if standardise_out: # zero mean, unit std. dev return standardise(X) return X
ref_result = [0.81649658, 0.81649658, 0.81649658] for p, q in zip(list(result), ref_result): print(math.isclose(p, q, rel_tol=1e-06, abs_tol=1e-06)) print("Testing np.median:") a = np.array([253, 254, 255], dtype=np.uint8) print(np.median(a)) print(np.median(a, axis=0)) a = np.array([range(255 - 3, 255), range(240 - 3, 240), range(250 - 3, 250)], dtype=np.float) print(np.median(a)) print(np.median(a, axis=0)) print(np.median(a, axis=1)) print("Testing np.roll:") ## Here is problem print(np.arange(10)) print(np.roll(np.arange(10), 2)) print(np.roll(np.arange(10), -2)) a = np.array([1, 2, 3, 4, 5, 6, 7, 8]) print(np.roll(a, 2)) print(np.roll(a, -2)) print("Testing np.clip:") print(np.clip(5, 3, 6)) ## Here is problem print(np.clip(7, 3, 6)) print(np.clip(1, 3, 6)) a = np.array([1, 2, 3, 4, 5, 6, 7], dtype=np.int8) print(np.clip(a, 3, 5)) a = np.array([1, 2, 3, 4, 5, 6, 7], dtype=np.float) print(np.clip(a, 3, 5))
def __getitem__(self, key: Union[_RClassKeyType, Tuple[_RClassKeyType, ...]]): if not isinstance(key, tuple): key = (key, ) objs: List[np.ndarray] = [] scalars: List[int] = [] arraytypes: List[_DType] = [] scalartypes: List[_DType] = [] # these may get overridden in following loop axis = 0 for idx, item in enumerate(key): scalar = False try: if isinstance(item, np.ndarray): newobj = item elif isinstance(item, slice): step = item.step start = item.start stop = item.stop if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size = int(abs(step)) newobj: np.ndarray = np.linspace(start, stop, num=size) else: newobj = np.arange(start, stop, step) # if is number elif isinstance(item, (int, float, bool)): newobj = np.array([item]) scalars.append(len(objs)) scalar = True scalartypes.append(newobj.dtype()) else: newobj = np.array(item) except TypeError: raise Exception( "index object %s of type %s is not supported by r_[]" % (str(item), type(item))) objs.append(newobj) if not scalar and isinstance(newobj, np.ndarray): arraytypes.append(newobj.dtype()) # Ensure that scalars won't up-cast unless warranted final_dtype = min(arraytypes + scalartypes) for idx, obj in enumerate(objs): if obj.dtype != final_dtype: objs[idx] = np.array(objs[idx], dtype=final_dtype) return np.concatenate(tuple(objs), axis=axis)
# Prior sample for pre-emphasis self.prior = 0 self.alpha = alpha # Build mel filter matrix self.filters = numpy.zeros((nfft/2+1,nfilt), 'd') dfreq = float(samprate) / nfft if upperf > samprate/2: raise(Exception, "Upper frequency %f exceeds Nyquist %f" % (upperf, samprate/2)) melmax = mel(upperf) melmin = mel(lowerf) dmelbw = (melmax - melmin) / (nfilt + 1) # Filter edges, in Hz filt_edge = melinv(melmin + dmelbw * numpy.arange(nfilt + 2, dtype='d')) for whichfilt in range(0, nfilt): # Filter triangles, in DFT points leftfr = round(filt_edge[whichfilt] / dfreq) centerfr = round(filt_edge[whichfilt + 1] / dfreq) rightfr = round(filt_edge[whichfilt + 2] / dfreq) # For some reason this is calculated in Hz, though I think # it doesn't really matter fwidth = (rightfr - leftfr) * dfreq height = 2. / fwidth if centerfr != leftfr: leftslope = height / (centerfr - leftfr) else: leftslope = 0
def hamm(M): x = np.arange(M, dtype=np.float) pi = np.array([2*np.pi/(M - 1)]) a_54, b_46 = np.array([0.54]), np.array([0.46]) return a_54 - b_46*np.cos(pi*x)
print(np.array(np.array(range(5), dtype=np.uint16), dtype=np.int8)) print(np.array(np.array(range(5), dtype=np.uint16), dtype=np.uint16)) print(np.array(np.array(range(5), dtype=np.uint16), dtype=np.int16)) print(np.array(np.array(range(5), dtype=np.uint16), dtype=np.float)) print(np.array(np.array(range(5), dtype=np.int16), dtype=np.uint8)) print(np.array(np.array(range(5), dtype=np.int16), dtype=np.int8)) print(np.array(np.array(range(5), dtype=np.int16), dtype=np.uint16)) print(np.array(np.array(range(5), dtype=np.int16), dtype=np.int16)) print(np.array(np.array(range(5), dtype=np.int16), dtype=np.float)) print(np.array(np.array(range(5), dtype=np.float), dtype=np.uint8)) print(np.array(np.array(range(5), dtype=np.float), dtype=np.int8)) print(np.array(np.array(range(5), dtype=np.float), dtype=np.uint16)) print(np.array(np.array(range(5), dtype=np.float), dtype=np.int16)) print(np.array(np.array(range(5), dtype=np.float), dtype=np.float)) print("Array creation using ARANGE:") print(np.arange(10)) print(np.arange(2, 10)) print(np.arange(2, 10, 3)) print(np.arange(2, 10, 3, dtype=np.float)) print("Array concatenation:") a = np.array([1,2,3], dtype=np.float) b = np.array([4,5,6], dtype=np.float) print(np.concatenate((a,b))) print(np.concatenate((a,b), axis=0)) a = np.array([[1,2,3],[4,5,6],[7,8,9]], dtype=np.float) b = np.array([[1,2,3],[4,5,6],[7,8,9]], dtype=np.float) print(np.concatenate((a,b), axis=0)) print(np.concatenate((a,b), axis=1)) print(np.concatenate((b,a), axis=0)) print(np.concatenate((b,a), axis=1)) print("Identity array creation:")
def resample(X, factor): idx_rs = np.arange(0, len(X) - 1, factor) return X[idx_rs]