Construction of two functions with different sampling rates

I want to build two functions: sin (x) and selective 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(x) < 0.5 ? floor(x) : ceil(x)
plot [0:16] [-8.5:8.5] f1(x) with lines,  round(f1(x)) with steps lt 2

The problem is that I want sin (x) to be smooth and select the quantized sin (x) counted at intervals of 1. The problem is that I cannot find any way to do this. Adding

set sample 21

almost works, but sin (x) doesn't look smooth enough. Is there any way to make this better?

+5
source share
1 answer

Denote the variable f1()not f1()and use floor()insteadround()

plot [0:16] [-8.5:8.5] f1(x) with lines,  f1(floor(x)+0.0) with steps lt 2

also set many samples to keep the quantized graph aligned correctly:

set samples 1000

round() floor, "0,5 " ( 0,5 1,5, 1,5 2,5 ..) "1 ".

floor

round

+7

All Articles