增加偏移量和延迟 [英] Adding offset and delay

查看:109
本文介绍了增加偏移量和延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个信号要引入几个偏移和延迟,其中偏移范围从0.55,延迟范围从17.

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 type double.

原因是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆