找到正的过零和负的过零 [英] Finding zero crossing that are going positive and zero crossing that are going negative

查看:127
本文介绍了找到正的过零和负的过零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要复制的信号:

I have a signal that I would like to copy when it:

1)从零交叉开始为正

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

2) copy a set number of points (like 8000)

3),并在复制8000个点之后继续追加点,直到找到零交叉下降部分.

我可以找到零交叉点,但是我在知道如何分辨零交叉点为正和/或零交叉点为负时遇到了一些问题.我也很难在末尾的8000点之后添加下一部分分数(因此,#1 和问题#3 用粗体显示我对此有疑问

I can find the zero crossing but I'm having some issues with knowing how to tell when there is a zero crossing going positive and/or a zero crossing going negative. I'm also having trouble with adding the next section of points after the 8000 points at the end (So question #1 and question #3 in bold I'm have issues with)

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

Note: please keep in mind the signal I'm using is an audio signal so it won't be as nice as a simple equation.

我已经将测试代码和图像一起附加了.我正在使用matlab/八度

I've attached the test code along with an image. I'm using 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')

推荐答案

尝试一下:

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

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

That will give you the crossing points and their direction. In your loop where you add samples, just test x for the current point and the last point. If it's zero, keep going. If it's positive, add on your 8000 points and go back to testing. If it's negative, stop.

更正了第一行代码中的错字.

Corrected typo in first code line.

这篇关于找到正的过零和负的过零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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