# How can I get a plot for y when I use ACME package

Hello everyone,
I am using an example of a ACME.jl package to use for my project in which I should simulate a RLC circuit in Julia, but I don’t know how can I plot y according to time.
this is the code which I use from example to expand for my project
(Getting Started · ACME.jl)

using ACME

circ = @circuit begin
j_in = voltagesource()
r1 = resistor(1e3)
c1 = capacitor(47e-9)
d1 = diode(is=1e-15)
d2 = diode(is=1.8e-15)
j_out = voltageprobe()
j_in[+] ⟷ r1[1]
j_in[-] ⟷ gnd
r1[2] ⟷ c1[1] ⟷ d1[+] ⟷ d2[-] ⟷ j_out[+]
gnd ⟷ c1[2] ⟷ d1[-] ⟷ d2[+] ⟷ j_out[-]
end
model = DiscreteModel(circ, 1/44100)
y = run!(model, sin.(2π 1000/44100 (0:44099)’))
and this the output
1×100 Array{Float64,2}:
1.83357e-8 3.1622e-7 2.59861e-6 … 0.00465423 0.00459275 0.00453208
so now my question is how can use above matrix as well as time to get a plot

### First order analysis

Looking at the code, it appears like this ACME.jl simulation uses a constant time step of `Ts=1/44100`, and it is driven by a `1kHz` sinusoidal source.

### Clean up code a bit

To start off, I would slightly modify your inputs for readability purposes:

``````fs = 44100 #Hz - should be integer value.
fsig = 1000 #Hz - pick integer value to ensure whole periods are simulated.
Tsim = 1 #sec - pick integer value to ensure whole periods of fsig are simulated.

Tsim = round(Int, Tsim) #Recommendation: always simulate for whole periods
Nsamples = round(Int, Tsim*fs) - 1 # "-1" generates "cleaner" fft() results
t = (0:Nsamples)'/fs

model = DiscreteModel(circ, 1/fs)
y = run!(model, sin.(2π*f .* t))
``````

### Plotting

For your first run, I suggest using Plots.jl. It seems to be the most popular on this forum, so more people can help you. It also supports multiple backends, so you can just switch to a different one by adding a single command later on. Here is the plotting code:

``````using Plots
plot(t', y')
``````

NOTE: ACME.jl appears to use row vectors, whereas Plots.jl expects column vectors. That’s why you need to plot the transpose of t & y.

### Switching backend

To switch backends, you simply select the desired backend after importing Plots.jl:

``````using Plots
inspectdr() #Select InspectDR backend instead of default (GR)
plot(t', y')
``````

Other Plots.jl backends are listed here:
Backends · Plots

But for interactive circuit analysis, I suggest you use try out my own InspectDR backend. It was designed with exploring simulation results in mind:

• Large datasets.
• Mostly for functions of 1 argument (ex: voltage vs time; gain vs frequency, …)
• Quickly pan/zoom using bindkeys/mouse bindings.

InspectDR repo (with link to sample plots):
GitHub - ma-laforge/InspectDR.jl: Fast, interactive Julia/GTK+ plots (+Smith charts +Gtk widget +Cairo-only images)

Listing of bindkeys:
InspectDR.jl/input_bindings.md at master · ma-laforge/InspectDR.jl · GitHub

1 Like

Dear Friend.
I really appreciate the time and energy you spent for writing and thinking about my problem.
I will check it

dear friend.
I use the code for simulating as you mention but the result seems incorrect,

Well, since your original `y` array used to have values of at least 0.00465423, whereas the plot is limited to `|values| < 4e-11`, I must have made a small mistake with my code cleanup suggestion.

For one, I’ve noticed I made a copy error here:

``````y = run!(model, sin.(2π*f .* t))
``````

I should have used `fsig` instead:

``````y = run!(model, sin.(2π*fsig .* t))
``````
1 Like

Thanks a million it worked . first I realized f should be something else. but I changed it to fs.