Clear Filters
Clear Filters

Non scalar struct array

1 view (last 30 days)
JA
JA on 1 Aug 2016
Edited: per isakson on 9 Aug 2016
This is very complicated problem about data structures, i will try and explain it as simple as possible.
I have multiple signals in a array
signals,
every element of this is a structure with multiple segments of the signal and it's attribute.
Now I have another function which filters this signal and does some calculation according to the cut off frequency.
Whenever this function is called, i want to loop through all fc, and through all signals and through all segments. But the problem is fc is calculated only in a signal, so i have something like this:
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.signals{i}) % segment of ith signal
f.fc = fc(a);
filt_sig = f.eval(this.signals{i}(k).signal,this.signals{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.signals{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
test script:
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()
I planned the final_norm to be something like this:
But my algorithm doesn't work, when i add 2nd signal. if anyone has better algorithm any suggestion is welcome.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!