升采样的正确方法是什么? [英] What is the correct method to upsample?

查看:565
本文介绍了升采样的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个75 Hz的采样数组,我想以128 Hz的频率存储它们.如果它是64 Hz和128 Hz,这非常简单,那么我会将所有样本加倍.但是,如果采样率不是彼此的一小部分,正确的方法是什么?

I have an array of samples at 75 Hz, and I want to store them at 128 Hz. If it was 64 Hz and 128 Hz it was very simple, I would just double all samples. But what is the correct way if the samplerates are not a fraction of eachother?

推荐答案

如果要避免过滤,则可以:

When you want to avoid Filtering then you can:

  1. 将信号作为一组连接的内插三次曲线处理

,但是这一点与使用线性插值相同.如果不了解信号和用途的更多信息,就无法构造valid系数(而不会破坏信号精度),例如,如何在此处构造这种立方外观:

but this point is the same as if you use linear interpolation. Without knowing something more about your signal and purpose you can not construct valid coefficients (without damaging signal accuracy) for example of how to construct such cubic look here:

是我使用的系数.我认为即使对于您的目的来说也足够了,您可以尝试一下.如果要进行自定义插值,请点击此处:

in bullet #3 inside that link are coefficients I use. I think there are sufficient even for your purpose so you can try them. If you want to do custom interpolation look here:

创建函数,可以从采样开始的给定时间返回信号中的点

所以做类似的事情

double signal(double time);

其中,time是从开始采样开始的时间,以[s]为单位.在此函数中,计算您需要访问的4个样本.

where time is time in [s] from start of sampling. Inside this function compute which 4 samples you need to access.

ix = floor(time*75.0);

为您提供曲线起点样本索引.三次需要四个点,曲线前一个,而后一个....因此对于内插三次点p0,p1,p2,p3,请使用样本ix-1,ix,ix+1,ix+2.因此,计算三次系数a0,a1,a2,a3并计算三次曲线参数t(我使用范围<0,1>)

gives you curve start point sample index. Cubic need 4 points one before curve and one after ... so for interpolation cubic points p0,p1,p2,p3 use samples ix-1,ix,ix+1,ix+2. Compute cubic coefficients a0,a1,a2,a3 and compute cubic curve parameter t (I use range <0,1>) so

t=(time*75.0); t-=floor(t);

  • 绿色-实际曲线段
  • aqua-实际曲线段控制点= 75.0 Hz采样
  • 红色-曲线参数插值参数t
  • 灰色-实际时间

抱歉,我忘记绘制实际的输出信号点,它应该是绿色和灰色的交点

sorry I forgot to draw the actual output signal point it should be the intersection of green and gray

只需执行时间为1/128 s的循环遍历采样数据

类似这样的东西:

double time,duration=samples*75.0,dt=1.0/128.0;
double signal128[???];
for (time=0.0,i=0;time<duration;i++,time+=dt)
 signal128[i]=signal(time);

samples是通过75.0 Hz采样的采样中的输入信号阵列大小

samples are the input signal array size in samples sampled by 75.0 Hz

[notes]

  • for/duration可以在整数上完成...
  • 将信号数据类型更改为您所需的
  • signal(time)内部,您需要处理边缘情况(信号的开始和结束)
  • 因为在第一个采样之前和最后一个采样之后,信号中没有定义点.您可以复制它们或镜像下一个点(镜像更好).
  • 这整个事情可以更改为连续处理而无需缓冲区,只需要记住信号中的最后4个点即可,因此您可以在RT中执行此操作.粗略地说,您将延迟2-3个75.0 Hz采样...并且将所有这些放在一起,无论如何,您会发现这是一个FIR滤波器:)
  • 如果您需要保留更多的点,则先求导添加更多的点...
  • for/duration can be done on integers ...
  • change signal data type to what you need
  • inside signal(time) you need to handle edge cases (start and end of signal)
  • because you have no defined points in signal before first sample and after last sample. You can duplicate them or mirror next point (mirror is better).
  • this whole thing can be changed to process continuously without buffers just need to remember 4 last points in signal so you can do this in RT. Of coarse you will be delayed by 2-3 75.0 Hz samples ... and when you put all this together you will see that this is a FIR filter anyway :)
  • if you need to preserve more then first derivation add more points ...

这篇关于升采样的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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