MATLAB:信号削波方法跳过数组索引? [英] MATLAB: signal clipping method skips array indexes?

查看:200
本文介绍了MATLAB:信号削波方法跳过数组索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我有一个矩形脉冲信号的基准线两侧的大致孤立的数据点。我现在想从脉冲结束到各自的方式裁剪的数据点,这些阵列(因为我仍然有信号的上升和下降的一些数据点)。

The problem: I have roughly isolated data points of the baselines either side of a square pulse signal. I now want to clip these arrays of data points from the 'pulse end' to their respective means (because I still have some data points from the rise and fall of the signal).

我的当前方法的结果似乎跳过数组索引

正如你可以看到我的方法在数组的末尾开始时和向后削波,但是好像评估从数组的开头数组索引时跳过的数据点似乎工作。

As you can see my method appears to work when starting at the end of an array and clipping backwards, but seems to skip data points when assessing array indexes starting from the beginning of the array.

的code:

baseline1=[1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,4;1:18];
baseline2=[4,3,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1;32:49];
%---------------------------------------------------
figure()
hold on
plot(baseline1(2,:),baseline1(1,:),'k')
plot(baseline2(2,:),baseline2(1,:),'k')
%---------------------------------------------------
%Clip baseline1
arrayMean = mean(baseline1(1,:));
x=size(baseline1,2);
meanCrossed = 0;
arrayClipped = baseline1;
for i=x:-1:1 
    if baseline1(1,i)>arrayMean && meanCrossed == 0
        arrayClipped(:,i)=[];
    else
        meanCrossed = 1;
    end
end
baseline1=arrayClipped;
%---------------------------------------------------
%Clip baseline2
arrayMean = mean(baseline2(1,:));
x=size(baseline2,2);
meanCrossed = 0;
arrayClipped = baseline2;
for i=1:x
    if baseline2(1,i)>arrayMean && meanCrossed == 0
        arrayClipped(:,i)=[];
    else
        meanCrossed = 1;
    end
end
baseline2=arrayClipped;
%---------------------------------------------------
plot(baseline1(2,:),baseline1(1,:),'g','LineWidth',2)
plot(baseline2(2,:),baseline2(1,:),'g','LineWidth',2)

谁能指教?

推荐答案

假设你想从大小4 4的矢量删除索引4,然后2消失,所以现在它的大小3.2消失,使得它尺寸2:

Say you want to delete indices 4 then 2 from a vector of size 4. 4 goes away, so now it's size 3. 2 goes away, making it size 2:

1 2 3 4
1 2 3
1 3

现在说要删除索引2,那么4.2消失了,所以现在它的大小3.现在我们删除索引4 ....等一下!

Now say you want to delete indices 2 then 4. 2 goes away, so now it's size 3. Now we delete index 4.... WAIT A SECOND!

1 2 3 4
1 3 4

索引4不存在,因为我们缩短的阵列。前身为第四元素的元素现在在指数3。

Index 4 doesn't exist, because we shortened the array. The element formerly known as the 4th element is now at index 3.

通过删除元素,你改变从该点向前的所有元素的索引。解决方案:保存所有的指数,你计算,并删除它们算账:

By deleting elements, you're changing the indexing of all elements from that point forward. Solution: save all the indices as you compute, and delete them all afterwards:

for ...
  clipped_indices(end+1) = i;
end

arrayClipped(:, clipped_indices) = [];

或者,更清洁和更快的实现,不要让 arrayClipped 可言。相反,做出正确的大小的所有的人的逻辑阵列和零他们为你找到裁剪的元素,则指数 baseline2 ,并在最后产生的逻辑阵列。

Or, for a cleaner and faster implementation, don't make arrayClipped at all. Instead, make an logical array of all ones of the correct size, and zero them as you find the elements to clip, then index baseline2 with the resulting logical array at the end.

这篇关于MATLAB:信号削波方法跳过数组索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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