Skip to content
This repository was archived by the owner on Mar 23, 2019. It is now read-only.

Stimulus Generators

Mark Cafaro edited this page Apr 15, 2014 · 1 revision

A stimulus generator encapsulates the parameters and logic necessary to generate a stimulus. A number of generators are included with Symphony, but you may also create your own if necessary.

Defining a new stimulus generator

To define a new stimulus generator you need to create a sub-class of the StimulusGenerator class.

Your sub-class should:

  1. Uniquely identify the stimulus generator.
  2. Define parameters.
  3. Override at least the generateStimulus() method.

Identifying the stimulus generator

Identify the stimulus generator using constant properties of the StimulusGenerator sub-class.

properties (Constant)
    identifier = 'io.github.symphony-das.MyGenerator'
    version = 1
end

Defining parameters

The parameters of a stimulus generator should be defined using standard MATLAB properties:

properties
    preTime     % Leading duration (ms)
    stimTime    % Pulse duration (ms)
    tailTime    % Trailing duration (ms)
    amplitude   % Pulse amplitude (units)
    mean        % Mean amplitude (units)
    sampleRate  % Sample rate of generated stimulus (Hz)
    units       % Units of generated stimulus
end

Generating the stimulus

To generate the stimulus you should override the generateStimulus() method and return a stimulus object that implements the Symphony.Core.IStimulus interface. In general the object returned will be a RenderedStimulus. See the simple generator below for an example of how to do this.

Versioning

If changes need to be made to a generator down the line, you should version the generator. To version a generator create a duplicate of the generator's class file before making any modifications. Apply the suffix "_v" followed by the current version number to the duplicate generator's file and class name. Now modify the original version, incrementing it's version number and making the appropriate changes.

For example if you have a generator called MyGenerator at version 1, duplicate the MyGenerator.m file and call the duplicate file MyGenerator_v1.m (also edit its constructor method to match the new file name). Now edit the original MyGenerator.m file to increment its version to 2 and make the necessary changes to the generation code.

A simple generator

classdef SimpleGenerator < StimulusGenerator
    
    properties (Constant)
        identifier = 'io.github.symphony-das.SimpleGenerator'
        version = 1
    end
    
    properties
        duration    % Stimulus duration (ms)
        sampleRate  % Sample rate of generated stimulus (Hz)
    end
    
    methods
        
        function obj = SimpleGenerator(params)
            if nargin == 0
                params = struct();
            end
            
            obj = obj@StimulusGenerator(params);
        end
        
    end
    
    methods (Access = protected)
      
        function stim = generateStimulus(obj)
            import Symphony.Core.*;

            pts = round(obj.duration / 1e3 * obj.sampleRate;
            data = zeros(1, pts);
            
            measurements = Measurement.FromArray(data, 'V');
            rate = Measurement(obj.sampleRate, 'Hz');
            output = OutputData(measurements, rate);
            
            stim = RenderedStimulus(obj.identifier, obj.stimulusParameters, output);
        end

    end
end