gpt4 book ai didi

c - 如何使用循环缓冲区将信号移动 90 度

转载 作者:行者123 更新时间:2023-11-30 16:42:57 25 4
gpt4 key购买 nike

我正在尝试使用 Control Studio V6.02 中编写 C 代码来对 DSP (TMSF28335) 进行编程。

在这个项目中,我需要对传感器测量的交流信号进行 90 度相位偏移。建议我使用循环缓冲器来进行这样的相移。但不幸的是,我不太熟悉如何用C语言编写循环缓冲区。根据这个概念,我知道缓冲区的“头部”应该是输入信号(测量的交流信号),“尾部”是移位的输入信号,用作循环缓冲区的输出信号。

系统采样时间设置为3.84599989e-5(s),一个周期为0.02(s)(50 Hz)。因此,一个周期的 1/4 构成 (0.02/4)/3.84599989e-5=130 个样本。换句话说,我需要延迟 130 个样本。

如果您能告诉我如何用 C 语言为我的 Controller 编写循环缓冲区,以便我可以进行相位延迟,我将不胜感激。

最佳答案

您需要的是称为延迟线的循环缓冲区的特殊实现。这是一个简单的(快速但肮脏,而且有些天真的)实现。

请注意,只有当输入频率恒定时,这才能为您提供固定的相移。

typedef short Sample;  //  change to whatever your sample data is...

#define DELAY (130)

struct DelayLine // <- make sure you initialize the entire struct
{ // with zeroes before use !
Sample buffer[DELAY + 1];
int next;
};

Sample tick(DelayLine* effect, Sample sampleIn)
{
// call for each sample received, returns the signal after delay

int nextOut = effect->next + DELAY; // note that this delay could be anything
// shorter than the buffer size.
if (nextOut >= DELAY + 1) // <-- but not this one!!!
nextOut -= DELAY + 1;

effect->buffer[effect->next] = sampleIn;

if (++(effect->next) >= DELAY + 1)
effect->next = 0;

return effect->buffer[nextOut];
}

关于c - 如何使用循环缓冲区将信号移动 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45629403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com