Plotting two functions with different sample rate

后端 未结 1 1973
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 12:58

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         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 13:21

    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".

    floor

    round

    0 讨论(0)
提交回复
热议问题