绘制两个具有不同采样率的函数 [英] Plotting two functions with different sample rate

查看:84
本文介绍了绘制两个具有不同采样率的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制两个函数:sin(x)和一个采样量化的sin(x).脚本很简单

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) < 0.5 ? floor(x) : ceil(x)
plot [0:16] [-8.5:8.5] f1(x) with lines,  round(f1(x)) with steps lt 2

问题是,我希望sin(x)平滑,并且采样间隔为1的量化sin(x)采样.问题是,我找不到这样做的任何选择.添加

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

几乎可以使用,但是sin(x)看起来不够平滑.有什么办法可以使它更好吗?

nearly works, but the sin(x) does not look smooth enough. Is there any way to make it better?

推荐答案

舍入f1()而不是f1()本身的变量,并使用floor()代替round()

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

如果使用round()而不是floor,则量化步长是"0.5步长"(0.5到1.5、1.5到2.5等),而不是"1步长".

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

这篇关于绘制两个具有不同采样率的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆