How to inject signals


Injecting signals in to ssm models is done at the time of simulating. In Topic 2 you learned how to simulate an LPF model which generated its noise internally. But you can also inject time-series data into the simulation in the form of AOs.

The two key parameters for ssm/simulate are:

Key Description
AOSAn array of AOs to be input to the simulation. Specify one per ''AOS VARIABLE NAMES''.
AOS VARIABLE NAMESAn cell-array of strings which give the names of the input ports you want to inject the AOs into.
The input ports should be specified using the "[block].[port]" notation. For example, to inject a guidance signal on the x1 control coordinate of our LPF model, you would do:
	  % The following supposes you already have an LPF SSM model called 'lpf' in your MATLAB workspace.
      
      % Create some time-series analysis object to inject
      aSignal = ao(plist('tsfcn', '1e-6*sin(2*pi*0.1*t)', 'fs', 10, 'nsecs', 1000));       
      
      % Create the plist to configure simulate      
      sim_pl = plist('AOS', aSignal, 'AOS Variable Names', 'GUIDANCE.ifo_x1', 'return outputs', 'DELAY_IFO.x1')
      
      % Run the simulation      
      out = simulate(lpf, sim_pl);
  
To inject multiple signals into different input ports, you would do something like:
      % The following supposes you already have an LPF SSM model called 'lpf' in your MATLAB workspace.
      
      % Create some time-series analysis object to inject
      fs    = 1/lpf.timestep; % Get the sample rate from the model's timestep
      nsecs = 1000; % Create signals 1000s long
      sig1 = ao(plist('tsfcn', '1e-6*sin(2*pi*0.1*t)', 'fs', fs, 'nsecs', nsecs));       
      sig2 = ao(plist('built-in', 'signals_3045_1_1', 'gaps', 1000));
      
      % Create the plist to configure simulate      
      sim_pl = plist('AOS', [sig1 sig2], ...      
                     'AOS Variable Names', {'GUIDANCE.ifo_x1', 'GUIDANCE.ifo_x12'}, ...
                     'return outputs', {'DELAY_IFO.x1', 'DELAY_IFO.x12'})
      
      % Run the simulation      
      out = simulate(lpf, sim_pl);
  

There are a number of rules which need to be followed for this all to work:

  1. The order of the AOs must match the order of the input port names.
  2. The time-series AOs must all have the same sample rate and that sample rate must match the time-step of the discretized ssm model.
  3. The length of the simulation will be governed by the shortest input AO. Specifying the number of samples with the 'NSamples' key for ssm/simulate will be ignored when input AOs are given.

How do I know which ports are available?

One of the difficulties of working with very large models like the LPF model, is that it's sometimes difficult to see which inputs and outputs are available to you. To aid in this process, we have two tools which can be useful. The first presents details of a given model in a documentation window. For example, suppose we have our LPF model in the MATLAB workspace, then you can do

      lpf.viewDetails
  
which will present a window like this one:
You can also use the ssm method getPortNamesForBlocks. This will return an cell-array of names for a given block. You can also configure what kind of blocks (inputs, outputs, or states) to return results for. For example, suppose we want to get a list of all guidance input ports, we could do
      portNames = lpf.getPortNamesForBlocks('GUIDANCE');
  
This returns only input ports because the LPF model we are using only has one block called 'GUIDANCE' and it is an input block. This need not necessarily be true, and there could be an input block with the same name as an output block. In that case, you would need to specify which block types to search like this:
      lpf.getPortNamesForBlocks(plist('blocks', 'guidance', 'type', 'inputs'))
  
The list returned from this method can be directly used as input to ssm/simulate.



©LTP Team