2016-08-01 65 views
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是這樣的:

final norm

但我的算法不起作用,當我添加第二個信號。如果有人有更好的算法,歡迎任何建議。

回答

-1

我不完全理解,你的數據結構是什麼,以及爲什麼每個信號都被分成多個段?你有沒有基於幀的信號處理(塊大塊),還是有一個信號分割算法?

我認爲你應該沿信號,濾波器和片段製作多個對象矢量化類。