增加偏移量和延迟 [英] Adding offset and delay
问题描述
我有一个信号要引入几个偏移和延迟,其中偏移范围从0.5
到5
,延迟范围从1
到7
.
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
.
我在此处提供示例信号来演示我遇到的问题,但实际数据的大小为1x1666520.
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?
示例代码:
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);
推荐答案
尝试运行示例代码时,出现此错误:
When trying to run your example code, I'm getting this error:
类型为
double
的输入参数的未定义函数retrend
.
Undefined function
retrend
for input arguments of typedouble
.
原因是 retrend
函数是系统标识工具箱的一部分,它需要数据对象(iddata
)作为输入.
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.
据我所知,添加一个延迟比较棘手,因为您需要保持相同的向量长度.您可以在正确的方向上用一些虚拟值(例如NaN
)填充向量.
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);
屈服:
这篇关于增加偏移量和延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!