2

This is a followup to a previous issue I was having.

I want to give an offset to a signal then add some delay in it and calculate RMSE for that but when taking difference I am having the following issue:

enter image description here

I would like to ask the following things:

  1. How can I solve the above problem?
  2. Will anybody please explain in simple words what iddata does - because I have studied different portals including MATLAB but remained unable to get a good concept.
  3. How can I store data of type iddata in cell for subtraction in the last part of my code?

Code with Problem :

 drv(1)=load('123.mat');

 t = drv(1).x;
 ref = drv(1).y;
 angle = drv(1).z;
 Fs = 1000;              
 t1 =t';
 ref1= ref';
 d_data = iddata(ref1, t1, 1/Fs);

 %% Add offset:
 x = 1;
 afterOffset1= {};
 for i = 100:10:130 
 T = getTrend(d_data); 
 % <detrend data if needed>
 T.InputOffset = i;
 T.OutputOffset = i;
 afterOffset = retrend(d_data,T);
 afterOffset1{x,1}= afterOffset;
 x= x+1 ;
 end 

 %% Add delay:
 y=20;
 afterDelay1= {};
 for i = 1:1:4
 % delaySamples = i; % Must be a non-negative value
 % afterDelay = iddata([NaN(delaySamples,1); d_data.OutputData],...
 %                     [d_data.InputData; NaN(delaySamples,1)], 1/Fs);
 afterOffset1{i}.Tstart = y;
 afterDelay1{i,1}= afterOffset1{i};
 y= y+10;
 end 
 %% Plot:
 n = size(afterDelay1,1);
 figure();
 for i=1:1:n
 subplot(2,2,i);

 plot(d_data);
 hold all
 plot(afterDelay1{i});
 end

 sig_diff = angle(1)-afterDelay1;
 square_error(i,:) = (sig_diff(i)).^2;
 mse(i,:)=  mean(square_error(i));
 rmse(i,:) = sqrt(mse(i));


 sig_diff = d_data_1 - afterDelay; %        <<<<<<<<<<<<<<<<<<<<<< Problem is here
 %     square_error = (sig_diff).^2;
 %     mse=  mean(square_error);
 %     rmse = sqrt(mse);
 end
Community
  • 1
  • 1
Peter
  • 161
  • 1
  • 11
  • rayryeng I have installed the system identification tool box . I have problem in this line sig_diff = angle(1)-afterDelay1; actually I want to subtract iddata from matrix this could be an issue. – Peter Aug 29 '17 at 16:14
  • Thanks a lot Dev-iL for editing my problem. – Peter Aug 29 '17 at 16:14
  • I misread the problem. Apologies. I've created an answer. – rayryeng Aug 29 '17 at 17:08

1 Answers1

1

You most likely want the OutputData attribute from the iddata object which is the output or y signal of your problem:

sig_diff = angle(1)-afterDelay1.OutputData;

Also note that this will give you a column vector, but your code later on assumes it's a row vector. You may want to transpose this data after you perform the above calculation before proceeding:

sig_diff = angle(1)-afterDelay1.OutputData;
sig_diff = sig_diff.';

In general, iddata is a function that creates an object that represents input and output time or frequency domain data. Take note that when you create an iddata object, the input matrix can potentially have multiple sources and so each column dictates a source. The same can be said for the output where each column dictates an output. Therefore, it is very important that you transpose your data prior to using this function to ensure that each signal is in a separate column, or just use a single column to represent one input / output.

Inside the object has a variety of attributes, including the sampling time or sampling frequency, the valid domain and range that the function takes on and finally accessing the input and output data. OutputData is one of these fields. I'd recommend looking at the documentation that talks about all of the attributes that you can access with iddata. OutputData is clearly defined here: https://www.mathworks.com/help/ident/ref/iddata.html

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • rayryeng . Thanks a lot it worked great for me and also thanks to you for ur explanation regarding iddata . Its good explanation for beginners like me with system identification tool box. – Peter Aug 29 '17 at 21:02
  • Just one question how outdata = afterDelay1.OutputData . When I use this command it converts 3D data into 2D i am confused how it is done as outdata should also contain 3D . Can you resolve my this confusion also please. Thanks in advance. – Peter Aug 29 '17 at 21:04
  • @Peter I'm not quite sure I follow. I didn't realize your input was 3D data. Could you give me more information on what your input and output data looks like? Better yet, I'd love it if you could upload a copy of your MAT file so I can see for myself. I can modify my post more easily as I will be able to run your code above. – rayryeng Aug 29 '17 at 21:07
  • First of all really sorry for a bit late reply. Actually I am unable to upload original data so thats why i tried to ask the qurrey by making an example .3D means or may be i am confused here as I have data of 166230*1*1 in afterDelay1 so how i will get 166230*1 in outdata when I perform this command outdata = afterDelay1.OutputData .Sorry for inconvenience in advance. – Peter Aug 30 '17 at 22:18
  • 1
    Trailing singleton dimensions on a matrix don't exist in MATLAB. Do you mean that it's a 1 x 1 x 166230 matrix? – rayryeng Aug 30 '17 at 22:39
  • 1
    rayryeng really sorry my mistake I got it. Thanks a lot for such a great help and support. – Peter Sep 05 '17 at 08:20