Filter the results

Hi,

I am trying to export the output of my model using AnyOutputfile as below:
AnyOutputFile L5S1_JRF_WOE = {
FileName = TEMP_PATH+"/"+ Main.ModelSetup.TrialSpecificData.TrialFileName + "-L5S1_JRF.csv";

NumberFormat = {

Digits = 2;
//Width = 2;
Style = ScientificNumber;
};
SepSign = ",";
LineSepSign = "";
SuppressTimeColumnOnOff = On;
Header =
{
TitleSectionOnOff = Off;
ConstSectionOnOff = Off;
ConstSectionSaveOptionsOnOff = Off;
VarSectionOnOff = Off;
ColumnNamesOnOff = On;
LinePrefix = "";
ShortenNamesOnOff = Off;
ColumnIDString = "col";
};

  AnyVar out0 =  Main.Studies.InverseDynamicStudy.t;
  AnyVar out1 =  Main.HumanModel.BodyModel.SelectedOutput.Trunk.JointReactionForce.L5SacrumCompressionForce; 
  AnyVar out2 =  Main.HumanModel.BodyModel.SelectedOutput.Trunk.JointReactionForce.L5SacrumAnteroPosteriorShearForce; 
  AnyVar out3 = Main.HumanModel.BodyModel.SelectedOutput.Trunk.JointReactionForce.L4L5MedioLateralShearForce; 

I also have defined a filter using AnyFunButterworthFilter
I am wondering how can I apply a lowpass filter to the variables before exporting them into csv? Im assuming that filter can only be applied on vectors and not variables?

Thanks for your help,
Mina

Hi Mina,

Correct the filter works on vectors. I think one way to do this would be using AnyOutPutFun

This is the description from the manual

" This class defines a function for making and getting access to values in the output data structures of studies, see the Output member in AnyStudy and derived classes. The output data structure does not exist at loadtime and therefore you cannot access then directly in mathematical expression as most normal variables, but by means of AnyOutputFun style functions you can work around this problem."

I have made this small sample model to illustrate, it is not exactly what you want however...

Main  ={
  AnyBodyStudy Study ={
    Gravity ={0,0,0};
    AnyFixedRefFrame global= {};
    AnySeg Seg={Mass=10; Jii={0,0,0};AnyRefNode Node ={sRel ={1,0,0};};};
    AnyRevoluteJoint Jnt ={
      AnyRefFrame &ref1=.global;
      AnySeg &ref2=.Seg;
    };
    AnyKinEqSimpleDriver drv ={
      AnyRevoluteJoint &ref=.Jnt;
      DriverPos={0};
      DriverVel={0};
    };
    AnyVar CutOffFrequency = 5.0; // Hz 
    /// The sample frequency
    AnyVar SampleFreq = 100;
    /// The filter orders (used for all filters)
    AnyInt FilterOrders =4;
    /// The number of samples
    AnyInt NoSamples = 1000;
    
    AnyFunButterworthFilter LowPassFilter =     {
      FilterForwardBackwardOnOff = On;
      AutomaticInitialConditionOnOff = On;
      N = .FilterOrders;
      W = {1/(.SampleFreq*0.5)*.CutOffFrequency};
      Type = LowPass;
    };
    AnyOutputFun Outputfun = {
     DummyReturn = {zeros(Main.Study.nStep),zeros(Main.Study.nStep),zeros(Main.Study.nStep)};
      Val = .Seg.r;
    };
   
    AnyFloat test = LowPassFilter(Outputfun());
  };
};

It is a very small model and i try to filter the location of the seg.node.

by creating the output function we can get access to the output... but we need to set its DummyReturn to the correct size which in this case is 101x3.
When the model loads Outputfun(is 101x3) and while the model is running it will gradually fill up the output and apply the filter.

The bad thing is that if you look in the output folder of the study "Main.Study.Output.test" it will be 101x101x3 this essentially means that the last frame output is what you are actually looking for, all the other frames are similar output but not entirely filled up yet, hope it makes sense and you can use it.

Best regards
Søren

1 Like