0
votes

I am working on a school project, which is a simulation of logical gates. I can implement and run the simulation with ease, but i need help with showing the output.

Right now, i print everything to the console, like this:

sample frequency: 50
###############################################

        IN      NOT(1)  OUT
        IN1:0   IN1:3   IN1:5
        IN2:0   IN2:0   IN2:0
        OUT:3   OUT:5   OUT:0
0       1       -1      -1
50      1       -1      -1
100     1       0       0
150     0       0       0
200     1       1       1
250     1       0       0
300     1       0       0
350     1       0       0  (IN = 1, delay is 1 so we can see
400     0       0       0  the correct output of NOT element in line 400 <-> 350 + 1*50)
450     1       1       1
500     1       0       0
550     1       0       0
600     1       0       0
650     0       0       0
700     0       1       1
750     1       1       1
800     1       0       0
850     1       0       0
900     1       0       0
950     1       0       0
1000    1       0       0

on the left, there is the simulation time (step). In each step, the values are printed out and new set of inputs is generated.

where there is -1, this means undefined output.

The 3rd row ( IN NOT(1) OUT ) means that there are 3 elements, 1 input, 1 NOT gate and an output. The value in brackets means the delay of the element, so an element with delay value of X will show the correct output after X*sample_freq (excluding the 0 time).

The rows after mean:

IN1 - the index of the node that is read as input 1

IN2 - the index of the node that is read as input 2

OUT - the index of the output node

In this situation, the IN is giving its output to node #3. The NOT element reads its input from node #3 and gives some output to node #5. The overall output of this system is the OUT element, which reads from #5.

Here is the file that specifies the topology:

3 (number of elems)
IN 0 0 3 (no inputs for input element obviously)
NOT 3 0 5 (reads from #3 and outputs to #5)
OUT 5 0 0 (reads from #5 and this is the end point of the system)

There can obviously be more elements, IN's and OUT's, but lets stick to this for the sake of simplicity.

And what i want to see as the result is: X-axis tells the simulation time (0 - 1000, step is 50), y axis tells the output value of each element in the system and the elements write their output one above the other, see this picture as an example.

Can you tell me how to create this kind of gnuplot script, that transforms the output of my application into the desired plot?

Thank you!

1

1 Answers

0
votes

ok, I have found a solultion myself, here it is:

first, I had to transform the output of the app a bit, so that it looks like this:

 0   1   2   4
 49  1   2   4
 50  1   2   4
 99  1   2   4
 100 0   2   4
 149 0   2   4
 150 0   3   5
 199 0   3   5
 200 1   3   5
 249 1   3   5
 250 1   2   4
 299 1   2   4
 300 0   2   5
 349 0   2   5
 350 1   3   5
 399 1   3   5
 400 0   2   4
 449 0   2   4
 450 1   3   5
 499 1   3   5

the extra sim time steps make the edges look almost square, I also separated each column by 2 (added 0 to column #2, added 2 to column #3, added 4 to column #4 and so on), so that it is drawn one above each other and the simple command to plot this is:

plot 'out.txt' using 1:2 with lines, 'out.txt' using 1:3 with lines, 'out.txt' using 1:4 with lines

plus some set xtics, set ytics and other cosmetic stuff

now I have to deal with naming the lines with the names of the elements and voila.