Plotting two functions with different sample rate
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(x) &l开发者_运维问答t; 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, I want the sin(x) to be smooth and the sampled an quantized sin(x) sampled at intervals of 1. The problem is, I can't find any option to do so. Adding
set sample 21
nearly works, but the sin(x) does not look smooth enough. Is there any way to make it better?
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".
精彩评论