-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect plotting #15
Comments
Turns out this is a very specific and annoying scenario. JSC simplifies this system to the extent that there are no discrete variables: |
Looking at the component definition, there isn't any discrete-ness. It gets a continuous input, and gives a continuous output. Discrete subsystems are "delimited" by specific operators: any input is a |
Consider the following modification of the example: julia> @mtkmodel QuantizationModel begin
@components begin
input = Sine(amplitude=1.5, frequency=1)
quant = Quantization(; z, bits=2, y_min = -1, y_max = 1)
quant_c = Quantization(; z, bits=2, y_min = -1, y_max = 1)
end
@variables begin
sine_disc(t) = 0
x(t) = 0 # Dummy variable to work around a bug for models without continuous-time state
end
@equations begin
sine_disc ~ Sample(Clock(0.1))(input.output.u)
quant.input.u ~ sine_disc
connect(input.output, quant_c.input)
D(x) ~ 0 # Dummy equation
end
end
julia> @named m = QuantizationModel()
julia> m = complete(m)
julia> ssys = structural_simplify(IRSystem(m))
julia> prob = ODEProblem(ssys, [], (0.0, 2.0))
julia> sol = solve(prob, Tsit5())
julia> plot(sol, idxs=[m.input.output.u, m.quant.y, m.quant_c.y, m.sine_disc]) Note the difference between the continuous and discrete quantization. Quantization (as implemented) itself does not make a variable discrete. It is a transformation of an input signal to an output signal. If you want it to take a continuous input and give a discrete output, you'd need to throw a |
There is something discrete
the variables are being indexed by the shift index y(z) ~ ifelse(quantized == true, quantize(u(z), bits, y_min, y_max, midrise), u(z)) this should be enough for JSC to determine that the entire system is discrete. Shifts are used in both function ModelingToolkit.input_timedomain(x::IRElement)
@match x begin
Term(&DT, _...) || Term(&SAMPLE, _...) => SciMLBase.Continuous
Term(&HOLD, _...) || Term(&SHIFT, _...) => ModelingToolkit.InferredDiscrete
Term(&CLOCKCHANGE, [_, Const((from, _), _), _...], _...) => SciMLBase.Clock(from)
Term(_...) => error("$x is not an operator.")
_ => nothing
end
end |
|
that sounds good, would it then be a matter of adding a check for this VariableTimeDomain in the case |
I see, thanks for the clarification. The check would have to be in |
https://juliacomputing.github.io/ModelingToolkitSampledData.jl/dev/tutorials/noise/#Quantization
Discrete time and continuous time plots sometimes use the same style
The text was updated successfully, but these errors were encountered: