Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

matlab - Adding offset and delay

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...