gpt4 book ai didi

matlab - 查找正向过零和负向过零

转载 作者:太空宇宙 更新时间:2023-11-03 19:37:56 24 4
gpt4 key购买 nike

我有一个信号,我想复制它:

1) 从过零开始变为正值

2)复制一定数量的点(比如8000)

3) 并在复制 8000 个点后继续添加点,直到找到下行部分的零交叉点。

我可以找到过零点,但我在知道如何判断零交叉点何时变为正值和/或零交叉点何时变为负值方面遇到了一些问题。我也无法在最后的 8000 分之后添加下一部分分数(所以问题#1 和问题#3 以粗体显示 我有问题)

注意:请记住我使用的信号是音频信号,因此它不会像一个简单的方程式那么好。

我附上了测试代码和一张图片。我正在使用 matlab/octave

clear all, clc, tic, clf;
n=16000
t=linspace(0,2*pi,n);
y=cos(6*t)+sin(4*t);

%find zero crossings
t1=y(1:n-1);
t2=y(2:n);
tt=t1.*t2;
indx=find(tt<0)

%1) start at first zero crossing going positive
%2) get 8000 pts
%3) and after the 8000 points continue appending points until a zero crossing going down section is found
new_y=y(indx(1,1):8000); %start at zero section found get 8000 pts
subplot(2,1,1);plot(y);title('Original Signal')
subplot(2,1,2);plot(new_y);title('New signal')

enter image description here

最佳答案

试试这个:

x = diff(sign(y));
indx_up = find(x>0);
indx_down = find(x<0);

这将为您提供交叉点及其方向。在您添加样本的循环中,只需测试当前点和最后一点的 x。如果为零,请继续。如果是肯定的,请添加您的 8000 点并返回测试。如果它是负面的,停止。

编辑:更正第一行代码中的拼写错误。

关于matlab - 查找正向过零和负向过零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16366417/

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