【问题标题】:Non scalar struct array非标量结构数组
【发布时间】:2016-12-06 08:58:47
【问题描述】:

这是一个非常复杂的数据结构问题,我会尽量简单地解释一下

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

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

【问题讨论】:

    标签: matlab data-structures struct


    【解决方案1】:

    我不完全明白,你的数据结构是什么,为什么每个信号都分成段?是否有基于帧的信号处理(逐块),或者有用于信号分割的算法?

    我认为你应该沿着信号、过滤器和段创建不止一个类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2014-09-17
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多