Ric*_*k T 5 matlab signal-processing octave
我有一个信号,我想复制它:
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')
Run Code Online (Sandbox Code Playgroud)

cra*_*gim 14
试试这个:
x = diff(sign(y));
indx_up = find(x>0);
indx_down = find(x<0);
Run Code Online (Sandbox Code Playgroud)
那将为您提供交叉点及其方向.在添加样本的循环中,只需测试当前点和最后一个点的x.如果它为零,继续前进.如果它是积极的,加上你的8000点并返回测试.如果它是否定的,请停止.
编辑:更正了第一个代码行中的拼写错误.