📄 delay.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Property of Freescale
% Freescale Confidential Proprietary
% Freescale Copyright (C) 2005 All rights reserved
% ------------------------------------------------------------------------
% $RCSfile: delay.m.rca $
% $Date: Sun Oct 22 03:19:41 2006 $
% Target: Matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 802.16-2004 OFDMA PHY - Continuous time delay
%
% Description: y = delay(x,t0,fs,OutLen) introduces a continuous
% time delay to the input vector x.
%
% Output:
% y => Matrix of delayed versions of input vector, x. One
% column for each delay specified in the vector, t0.
% A transient is present at the begining of each
% output column lasting for 5+floor(t0*fs) samples.
% The algorithm exhibits a low pass response but preserves
% 50% of the input Nyquist bandwidth. It is recommended
% that the input signal use a 2X oversample rate for
% this reason.
%
% Inputs:
% x => Input vector.
% t0 => Vector of delays in seconds to be introduced into
% the input vector. Positive and negative delays are
% supported. Delays can also be zero.
% fs => Sample rate in Hz.
% OutLen => Optional parameter that specifies the length of
% the output vector. Defaults to the length of x.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y=delay(x,t0,fs,OutLen)
thresh = 1e-6;
if nargin==3
OutLen=length(x);
end
% Make the input vector a column.
[R C]=size(x);
if R==1,
x=transpose(x);
end
for k=1:length(t0),
% Convert time delay in seconds to sample periods
n0=-t0(k)*fs;
frac_n0=n0-round(n0);
int_n0=round(n0);
% Implement integer delay
x2=x;
if int_n0<=0
x2=[zeros(-int_n0,1); x(1:length(x)+int_n0)];
elseif int_n0>0
x2=[x(1+int_n0:length(x)); zeros(int_n0,1)];
end
% Implement fractional delay
if 0
%if abs(frac_n0) > thresh,
% Raised cosine shape in the frequency domain
n=[-5+frac_n0:1:5+frac_n0];
B=1/3;
fsT=2*(1-B);
h=sinc(n/fsT).*cos(pi*B*n/fsT)./(1-(2*B*n/fsT).^2);
h=h/sum(h);
temp=filter(h,1,[x2; zeros(5,1)]);
% Remove transient from the begining (filter delay)
size(y);
size(temp);
y(:,k)=temp(6:end);
else
y(:,k)=x2;
end
end
% Set desired length
TailLen=OutLen-size(y,1);
if TailLen >= 0
y=[y; zeros(TailLen,size(y,2))];
else
y=y(1:OutLen,:);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -