The instantaneous frequency increases from the lower bound of the frequency band to the higher. When applying the signal to a system, it gives good control over the excited frequency band and is therefore often used for system identification. In this example, the chirp function will be defined in C and then used as an external function in Modelica.
Begin by creating a Modelica function called Chirp that will make an external call to a C function with the same name.
input Modelica.SIunits.AngularVelocity w_start;
input Modelica.SIunits.AngularVelocity w_end;
input Real A;
input Real M;
input Real t;
output Real u "output signal";
external "C" annotation(Include="#include \"Chirp.c\"", IncludeDirectory = "modelica://IntroductoryExamples/Resources/Chirp.c");
The function has five input signals, one output signal, and a call to the external function Chirp.c. The declaration assumes that the function Chirp.c is declared with these five inputs and returns a double. If for some reason you wish to switch the order of the variables in calling the function, this is possible by changing the declaration to, for instance, the following.
external "C" Chirp(t,A,M,w_start,w_end) annotation(...);
The function can be written in any text editor and stored with the name Chirp.c. In this case, the C file should be placed in a new directory called Resources inside the directory where the package is stored. It can be placed in other places too, and the IncludeDirectory annotation should then be changed accordingly.
As soon as the C function is saved, the Modelica function is ready to use. To do this, a new Modelica block is created and the Chirp function is called within it. After creating the ChirpSignal block and defining the necessary parameters, you can drag and drop the predefined Modelica connector Modelica.Blocks.Interfaces.RealOutput from the Class Browser onto the Diagram View. This will create an instance of the connector in the ChirpSignal block, and it can be directly used in the equation section of the block.
Plotting the chirp signal u of the IntroductoryExamples.ExternalFunctions.ChirpSignal model.
As a result of using the predefined Modelica connector Modelica.Blocks.Interfaces.RealOutput, ChirpSignal can be used in other models as an input source. For instance, it can be used to test the resonance frequency of the following electric circuits.
The Diagram View of the IntroductoryExamples.ExternalFunctions.SeriesCircuit model.
Plotting the current i of the IntroductoryExamples.ExternalFunctions.SeriesCircuit model.