非标量结构数组

时间:2016-08-01 10:07:18

标签: matlab data-structures struct

这是关于数据结构的非常复杂的问题,我将尝试尽可能简单地解释它

我在数组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是这样的:

final norm

但是当我添加第二个信号时,我的算法不起作用。如果有人有更好的算法,欢迎任何建议。

1 个答案:

答案 0 :(得分:-1)

我不完全明白,您的数据结构是什么以及为什么每个信号被分成多个部分?你有基于帧的信号处理(块大块),还是有信号分割算法?

我认为你应该使用信号,过滤器和片段进行多个具有对象矢量化的类。

相关问题