Matlab 中的离散化函数

发布于 2024-10-20 07:16:08 字数 259 浏览 1 评论 0原文

我有以下函数和一组值:

z(t):   {R → [-2,3] | z(t) = sin(0.5×π×t) + cos(2×π×t) + 1

t = [-1 : 0.001 : 1]

我需要使用采样周期 Ts=0.01 确定 z(n×Ts) = z(n),因此离散化的功能。

我尝试使用 d2d,但据我所知只能应用于 zpk 函数。

还有其他方法吗?

I have the following function and set of values:

z(t):   {R → [-2,3] | z(t) = sin(0.5×π×t) + cos(2×π×t) + 1

t = [-1 : 0.001 : 1]

I need to determine z(n×Ts) = z(n), using the sample period Ts=0.01, therefore discretizing the fucnction.

I tried using d2d, but for what I've understood can only be applied to zpk functions.

Is there any other way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-10-27 07:16:08

如果您想要信号的零阶保持近似,可以通过以下代码来完成:

Ts = 0.01;
t = -1:0.001:1;
n = t./Ts;

nSampled = nan(size(t));
nSampled(1:10:end) = n(1:10:end);

zCont = @(t)(sin(pi*t/2)+cos(2*pi*t)+1);
zZOH  = @(n,Ts)(zCont(floor(n).*Ts));
zDisc = @(n,Ts)(zCont(n.*Ts));

figure;
plot(t,zCont(t),'b','DisplayName','Continuous'); hold on;
plot(t,zZOH(n,Ts),'r','DisplayName','ZOH'); 
stem(t,zDisc(nSampled,Ts),'k','DisplayName','Discrete'); 
legend('show');

这将为您提供如附图所示的输出。在此处输入图像描述

您可以尝试使用 ceil() 或 round() 而不是 Floor() 来获得略有不同的行为。如果您只需要 n 整数值的样本,那就完全不同了,并且对于一般情况来说实现起来也有很大不同(由于浮点数的舍入误差)。但是:对于您的情况,只需像 nSampled 中那样对索引进行二次采样即可工作,因为二次采样因子为 10。对于非整数二次采样因子,这将无法正常工作。

If you want a zero order hold approximation of your signal, this can be done by following code:

Ts = 0.01;
t = -1:0.001:1;
n = t./Ts;

nSampled = nan(size(t));
nSampled(1:10:end) = n(1:10:end);

zCont = @(t)(sin(pi*t/2)+cos(2*pi*t)+1);
zZOH  = @(n,Ts)(zCont(floor(n).*Ts));
zDisc = @(n,Ts)(zCont(n.*Ts));

figure;
plot(t,zCont(t),'b','DisplayName','Continuous'); hold on;
plot(t,zZOH(n,Ts),'r','DisplayName','ZOH'); 
stem(t,zDisc(nSampled,Ts),'k','DisplayName','Discrete'); 
legend('show');

This will give you the output as in the attached figure.enter image description here

You can try to play with ceil() or round() instead of floor() to get slightly different behavior. If you only need samples at integer values of n, that is something different altogether and is quite different to achieve for the general case (due to roundoff error in floats). However: for your case it will work by simply subsampling the index as is done in nSampled as the subsampling factor is 10. For a non-integer subsampling factor, this will not work properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文