I want to plot two functions: sin(x) and a sampled and quantized sin(x). The script is simple
set xtic 1
set ytic 1
f1(x) = sin(x/16*2*pi)*8
round(x) = x - floor
Round the variable of f1()
not f1()
itself and use floor()
instead of round()
plot [0:16] [-8.5:8.5] f1(x) with lines, f1(floor(x)+0.0) with steps lt 2
also, set a lot of samples to keep the quantized plot properly aligned:
set samples 1000
If you use round()
instead of floor
the quantization steps are "0.5 steps" (0.5 to 1.5, 1.5 to 2.5 etc) instead of "1 steps".