Python scipy.signal.sawtooth() Examples
The following are 3
code examples of scipy.signal.sawtooth().
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: triangle_reference_generator.py From gym-electric-motor with MIT License | 6 votes |
def _reset_reference(self): # get absolute values of amplitude, frequency and offset self._amplitude = self._get_current_value(self._amplitude_range) self._frequency = self._get_current_value(self._frequency_range) offset_range = np.clip( self._offset_range, -self._limit_margin[1] + self._amplitude, self._limit_margin[1] - self._amplitude ) self._offset = self._get_current_value(offset_range) t = np.linspace(0, (self._current_episode_length - 1) * self._physical_system.tau, self._current_episode_length) phase = np.random.rand() * 2 * np.pi # note: in the scipy implementation of sawtooth() 1 time-period # corresponds to a phase of 2pi ref_width = np.random.rand() # a random value between 0,1 that creates asymmetry in the triangular reference # wave ref_width=1 creates a sawtooth waveform self._reference = self._amplitude * sg.sawtooth(2*np.pi * self._frequency * t + phase, ref_width) + self._offset self._reference = np.clip(self._reference, self._limit_margin[0], self._limit_margin[1])
Example #2
Source File: sawtooth_reference_generator.py From gym-electric-motor with MIT License | 5 votes |
def _reset_reference(self): # get absolute values of amplitude, frequency and offset self._amplitude = self._get_current_value(self._amplitude_range) self._frequency = self._get_current_value(self._frequency_range) offset_range = np.clip(self._offset_range, -self._limit_margin[1] + self._amplitude, self._limit_margin[1] - self._amplitude) self._offset = self._get_current_value(offset_range) t = np.linspace(0, (self._current_episode_length - 1) * self._physical_system.tau, self._current_episode_length) phase = np.random.rand() * 2 * np.pi # note: in the scipy implementation of sawtooth() 1 time-period corresponds to a phase of 2pi self._reference = self._amplitude * sg.sawtooth(2 * np.pi * self._frequency * t + phase) + self._offset self._reference = np.clip(self._reference, self._limit_margin[0], self._limit_margin[1])
Example #3
Source File: generatesignal.py From eegsynth with GNU General Public License v3.0 | 4 votes |
def _start(): '''Start the module This uses the global variables from setup and adds a set of global variables ''' global parser, args, config, r, response, patch, monitor, debug, ft_host, ft_port, ft_output, name global nchannels, fsample, shape, scale_frequency, scale_amplitude, scale_offset, scale_noise, scale_dutycycle, offset_frequency, offset_amplitude, offset_offset, offset_noise, offset_dutycycle, blocksize, datatype, block, begsample, endsample, stepsize, timevec, phasevec # get the options from the configuration file nchannels = patch.getint('generate', 'nchannels') fsample = patch.getfloat('generate', 'fsample') # sin, square, triangle, sawtooth or dc shape = patch.getstring('signal', 'shape') # the scale and offset are used to map the Redis values to internal values scale_frequency = patch.getfloat('scale', 'frequency', default=1) scale_amplitude = patch.getfloat('scale', 'amplitude', default=1) scale_offset = patch.getfloat('scale', 'offset', default=1) scale_noise = patch.getfloat('scale', 'noise', default=1) scale_dutycycle = patch.getfloat('scale', 'dutycycle', default=1) offset_frequency = patch.getfloat('offset', 'frequency', default=0) offset_amplitude = patch.getfloat('offset', 'amplitude', default=0) offset_offset = patch.getfloat('offset', 'offset', default=0) offset_noise = patch.getfloat('offset', 'noise', default=0) offset_dutycycle = patch.getfloat('offset', 'dutycycle', default=0) blocksize = int(round(patch.getfloat('generate', 'window') * fsample)) datatype = 'float32' if datatype == 'uint8': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_UINT8) elif datatype == 'int8': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_INT8) elif datatype == 'uint16': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_UINT16) elif datatype == 'int16': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_INT16) elif datatype == 'uint32': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_UINT32) elif datatype == 'int32': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_INT32) elif datatype == 'float32': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_FLOAT32) elif datatype == 'float64': ft_output.putHeader(nchannels, fsample, FieldTrip.DATATYPE_FLOAT64) monitor.debug("nchannels = " + str(nchannels)) monitor.debug("fsample = " + str(fsample)) monitor.debug("blocksize = " + str(blocksize)) block = 0 begsample = 0 endsample = blocksize - 1 stepsize = blocksize / fsample # the time axis per block remains the same, the phase linearly increases timevec = np.arange(1, blocksize + 1) / fsample phasevec = np.zeros(1) # there should not be any local variables in this function, they should all be global if len(locals()): print("LOCALS: " + ", ".join(locals().keys()))