1
这是一个关于数据结构的非常复杂的问题,我会尝试解释它尽可能简单非标量结构阵列
我有一个阵列signals
在多个信号,在此每一个元件是具有多个段的结构信号及其属性。
现在我有另一个功能,它过滤这个信号,并根据截止频率做一些计算。
无论何时调用此函数,我都想遍历所有fc
,并遍历所有信号和所有段。但问题是fc
仅在信号计算的,所以我有这样的事情:
classdef datHandle < handle
properties
error_norm = {};
final_error = {};
signals = {};
end
methods
function this = addsignal(this, varargin)
%signal segmentation is done here
end
function this = addfilter(this, varargin)
for i = 1:length(this.signals)% for each signal
this.error_norm = {};
fn = 1/((mean(diff(this.signals{i}(1).time)))*2);
fc = linspace(1,fn,(fn/0.5)); %calculate fc
this.tempaddfilt(fc,i)
end
this.final_error = [this.final_error;this.error_norm];
end
function this = tempaddfilt(this,varargin)
s = [];
f = ltiFilter.PT1(); % initiate filter class
fc = varargin{1}; % take fc
i = varargin{2}; % the exact signal
for a = 1:length(fc) % fc
q = 0;
w = 0;
for k = 1:length(this.segments{i}) % segment of ith signal
f.fc = fc(a);
filt_sig = f.eval(this.segments{i}(k).signal,this.segments{i}(k).signal(1)); %signal and the initial value of the signal
filt_sig = filt_sig';
s(1,i).main(k).seg_err(a) = std((filt_sig-this.segments{i}(k).ref)); % calculate the standard diviation of the signal
q = q+s(1,i).main(k).seg_err(a);
s(1,i).main(k).fc(a) = fc(a);
end
s(1,i).main(i).sig_err(a) = q;
w = w+s(1,i).main(i).sig_err(a);
end
s(1,1).main(1).filt_err(a) = w;
this.error_norm = [this.error_norm s];
end
end
end
测试脚本:
clear all
close all
filname = load('file');
signal1 = filname.signal; % current value
time1 = filname.time;
signal2 = filname.signal2; % current value
time2 = filname.time2;
f = ltiFilter.datHandle();
f.addsignal(signal1,time1,93);
f.addfilter()
我策划了final_norm
是这样的:
但我的算法不起作用,当我添加第二个信号。如果有人有更好的算法,欢迎任何建议。