【发布时间】:2016-11-28 12:06:40
【问题描述】:
我有一个算法可以根据一些参数对信号进行斩波并将其存储在一个结构中。
代码:
classdef Container < handle
properties
segments = struct('signal', {}, 'time', {});
end
methods
function this = addsignal(this, varargin)
interval = diff(varargin{2});
[~, locations] = findpeaks(interval,'THRESHOLD',0.7)
edges = [0; locations; numel(varargin{1})+1]; %note that 0 and one past the end is on purpose
newsegments = struct('signal', cell(numel(edges)-1, 1), 'time', cell(numel(edges)-1, 1), 'error', []);
%this loop works for no peaks, 1 peak and more than one peak (because of the 0 and numel+1)
for edgeidx = 1 : numel(edges) - 1
newsegments(edgeidx).signal = varargin{1}((edges(edgeidx)+1 : edges(edgeidx+1)-1));
newsegments(edgeidx).time = varargin{2}(edges(edgeidx)+1 : edges(edgeidx+1)-1);
end
this.segments = [this.segments; newsegments]; %and append structure
end
这就是我调用这个函数的方式:
file1 = 'file'
signal1 = file1.yaxis
time1 = file1.xaxis
file" = 'file'
signal2 = file2.yaxis
time2 = file2.xaxis
f = ltifilter.container(); % ltifilter is a package
f.addsignal(signal1,time1);
f.addsignal(signal2,time2);
f.addsignal(signal3,time3);
当我使用所有信号调用时,segments 结构将组合所有信号的所有斩波段,无法说明哪个段属于哪个信号,我想将这些段映射到它的父信号,例如这:
任何建议都会有所帮助
【问题讨论】:
-
你是否真的用输入'signal1'来调用它,这是你想要存储在结构中的名称吗?
-
是的,类似的。
-
编辑了我的代码,以显示信号是如何导入的。
标签: matlab mapping hashtable signal-processing flags