DPsim
Loading...
Searching...
No Matches
CosineFMGenerator.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
10
11using namespace CPS;
12
14 Real modulationFrequency,
15 Real modulationAmplitude,
16 Real frequency /*= 0.0*/,
17 bool zigzag /*= false*/) {
18 mMagnitude = Math::abs(initialPhasor);
19 mInitialPhase = Math::phase(initialPhasor);
20 mBaseFrequency = frequency;
21 mModulationFrequency = modulationFrequency;
22 mModulationAmplitude = modulationAmplitude;
23
24 // default value, should implement a way to set it during runtime
25 mZigZag = zigzag;
26
27 **mSigOut = initialPhasor;
28 **mFreq = frequency;
29
30 SPDLOG_LOGGER_INFO(mSLog, "Parameters:");
31 SPDLOG_LOGGER_INFO(mSLog,
32 "\nInitial Phasor={}"
33 "\nModulation Frequency={} [Hz]"
34 "\nModulation Amplitude={}"
35 "\nBase Frequency={} [Hz]",
36 Logger::phasorToString(initialPhasor), modulationFrequency,
37 modulationAmplitude, frequency);
38}
39
41 Real phase = 2. * PI * mBaseFrequency * time + mInitialPhase;
42
43 if (mZigZag) {
44 Real tmp = 2 * time * mModulationFrequency;
45 Real sign = (((int)floor(tmp)) % 2 == 0) ? -1 : 1;
46 phase += 2 * mModulationAmplitude *
47 (pow(2 * (tmp - floor(tmp)) - 1, 2) - 1) / PI * sign;
48 **mFreq = mBaseFrequency +
49 mModulationAmplitude * (2 * (tmp - floor(tmp)) - 1) * sign;
50 } else {
51 phase += mModulationAmplitude / mModulationFrequency *
52 sin(2. * PI * mModulationFrequency * time);
53 **mFreq = mBaseFrequency +
54 mModulationAmplitude * cos(2. * PI * mModulationFrequency * time);
55 }
56
57 **mSigOut = Complex(mMagnitude * cos(phase), mMagnitude * sin(phase));
58}
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
static Real phase(Complex value)
Definition MathUtils.cpp:23
static Real abs(Complex value)
Definition MathUtils.cpp:27
void setParameters(Complex initialPhasor, Real modulationFrequency, Real modulationAmplitude, Real frequency=0.0, bool zigzag=false)
set the source's parameters
void step(Real time)
implementation of inherited method step to update and return the current signal value
const CPS::Attribute< Real >::Ptr mFreq
const CPS::Attribute< Complex >::Ptr mSigOut
Logger::Log mSLog
Component logger.
#define PI
Definition Definitions.h:43
double Real
Definition Definitions.h:62
std::complex< Real > Complex
Definition Definitions.h:63