Programmatic generation of pulses is one of the more advanced and, consequently, more powerful features of Ephus. It is relatively straightforward to write a function to generate a set of pulses. A set of pulses can be created using the following steps, including some finishing touches to make the function especially user-friendly:
- Identify the full path to the target pulseSet (the location in which the new pulses will be stored).
destDir = getDefaultCacheDirectory(progmanager, 'myCustomPulses');%Use a cached value, to reduce the need to prompt the user. if strcmpi(destDir, pwd) destDir = getDefaultCacheDirectory(progmanager, 'pulseDir'); %Use the pulseEditor's cached directory if this function's cached value is just Matlab's current directory (the default). end destDir = uigetdir(destDir, 'Choose a pulseSet for the destination of new pulses.'); %Prompt the user to choose a directory, defaulting to the cached value. if length(destDir) == 1 if destDir == 0 return; %The user has cancelled the directory selection, take that as a queue to quit the function completely. end end %Test that the directory is valid before proceeding. if ~exist(destDir, 'dir') error('pulseDest must be a valid directory: ''%s'' does not exist.', destDir); end setDefaultCacheValue(progmanager, 'myCustomPulses', destDir); %Update the cached value, for the subsequent calls to this function. [pulseDir, pulseSetName] = fileparts(destDir); %Hold on to these values for later use.
- Create a pulse.
channel1Pulse = signalobject('Name', 'myCustomCycleChan1', 'repeatable', 0, 'sampleRate', sampleRate);
- Parameterize the pulse.
set(channel1Pulse , 'Name', ['myCustomCycleChan1' num2str(1)]); %Update the pulse's name/number. dc(channel1Pulse , 1);%This uses a @signalobject convenience function to parameterize a DC pulse.
- Save the pulse.
signal = channel1Pulse; saveCompatible(fullfile(destDir, [get(signal, 'Name') '.signal']), 'signal', '-mat');
- Pulse objects are pass-by-reference objects, and thus they represent a potential memory leak in Matlab. It is good practice to delete them when they are no longer needed.
delete(channel1Pulse);
See also Writing a function to autogenerate a cycle.