-1

I have a signal into which I want to introduce several offsets and delays, where offsets range from 0.5 to 5 and delays range from 1 to 7.

I'm providing an example signal here to demonstrate the problem I'm having, but the size of my real data is 1x1666520.

How do I introduce these changes to the signal?

Example code:

t  = [ 0 : 1 : 50];           % Time Samples
f  = 45;                      % Input Signal Frequency
Fs = 440;                     % Sampling Frequency
data = sin(2*pi*f/Fs*t)'; 

T.InputOffset = 5;
T.OutputOffset = 5;

addoffset = retrend(data);
Y = step(delay,data);

figure(); plot(t,addoffset,t,Y);
Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Peter
  • 161
  • 1
  • 11
  • Next time, please specify the error/problem you're getting in the body of the question. – Dev-iL Aug 15 '17 at 09:33
  • Thanks a lot and sure next time I will also attach the type of error that I am getting in question – Peter Aug 15 '17 at 09:36
  • Dev-iL can you please have a look at the latest issue. – Peter Aug 29 '17 at 13:41
  • This is not how Stack Overflow works. If you have a new problem, you should open a new question and provide a link to this one for reference. After you create the new question, your last edit should be rolled back. – Dev-iL Aug 29 '17 at 13:45
  • Dev-iL I thought that it will become a repeated question so thats why did not made a new qurrey. – Peter Aug 29 '17 at 13:47
  • When you make the new question, add the minimum code required to reproduce the problem ([mcve]). If you do that, it will not be considered a duplicate. – Dev-iL Aug 29 '17 at 13:51
  • Dev-iL i have made a new thread . Have a look at that one also .Link is as follows https://stackoverflow.com/questions/45941060/error-using-iddata-for-system-identification-toolbox – Peter Aug 29 '17 at 13:59

1 Answers1

1

When trying to run your example code, I'm getting this error:

Undefined function retrend for input arguments of type double.

The cause of this is that the retrend function, which is part of the System Identification Toolbox, requires a data object (iddata) as an input.

If you have the aforementioned toolbox, you can create a data object as in the example for retrend, then add a trend similarly to what you already tried.

To my understanding, adding a delay is trickier, because you need to maintain the same vector length. You can pad your vectors with some dummy values (such as NaN) in the correct direction.

Applied to your case we get:

function q45688607
%% Generate data:
t  = (0 : 1 : 50).';       % Time Samples
f  = 45;                   % Input Signal Frequency
Fs = 440;                  % Sampling Frequency
y = sin(2*pi*f/Fs*t); 
d_data = iddata(y, t, 1/Fs);

%% Add offset:
T = getTrend(d_data); 
% <detrend data if needed>
T.InputOffset = 5;
T.OutputOffset = 5;
afterOffset = retrend(d_data,T);

%% Add delay: 
delaySamples = 8; % Must be a non-negative value
afterDelay = iddata([NaN(delaySamples,1); d_data.OutputData],...
                    [d_data.InputData; NaN(delaySamples,1)], 1/Fs);    
%% Plot:
figure(); plot(d_data,afterOffset, afterDelay);

Yielding:

After adding a trend + offset

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • Thanks a lot Dev-iL This is the perfect answer which I was looking for just wondering if I want to make this for different sets of offset and delay values – Peter Aug 15 '17 at 09:35