📄 interpol.m
字号:
function yy = interpol(f,ty,n,r)
% INTERPOL Signal Interpolation.
%
% Y = INTERPOL(F,TY,N,R) interpolates signal F to N-fold sequence
% TY = interpolation algorithm which can be one of the following:
% 'c'(onstant, 'l'(inear), 's'(inc), 'r'(aised cosine), 'd'(ft), 'z'(ero)
% R = additional parameter if TY = 'r' (DEFAULT: R = 0.5)
% Y = interpolated signal with N times length(F) [Default: N = 4]
%
% Plots interpolated signal vs index if NO OUTPUT ARGUMENT SPECIFIED
%
% INTERPOL (with no input arguments) invokes the following example:
%
% % Generate a coarse sine wave at 0.2s intervals and interpolate to
% % 4 times its length using sinc interpolation
% >>ta = 0:0.2:1;
% >>xa = sin(pi*ta);
% >>interpol(xa,'sinc') % N=4 is default
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin==0,help interpol,disp('Strike a key to see results of the example')
pause,ta=0:.2:1;xa=sin(pi*ta);interpol(xa,'sinc');return,end
if nargin<4,r=0.5;end,
if nargin<3,n=4;end,
if nargin<2,ty='z';end
if n==1,y=f;return,end %Trivial case
r=r-5.5*eps;ty=ty(1);
n0=n-1;[mm,nn]=size(f);m=max(mm,nn);
if mm==1,f=f(:);end
if n0 < 1, error('interpolation factor must be a positive integer'),end
l=n*m;x=zeros(l,1);x(1:n:l)=f;
if ty=='c',d=0;t=0:1/n:1;xi=ones(1,n);end %xi=rect(t-.5);
if ty=='l',d=n;t=-1:1/n:1;xi=tri(t);end
if ty=='s',d=m*n;t=-m:1/n:m;xi=sinc(t);end
if ty=='r',d=m*n;t=-m:1/n:m;xi=sinc(t).*cos(pi*r*t)./(1-4*r*r*t.*t);end
if ty=='d'
i=fix(m/2)+1;a=fft(f);a=[a(1:i);zeros(n0*m,1);a(i+1:m)];
if rem(m,2)==0,
a(i)=a(i)/2;a(i+m*n0)=a(i);end,y=n*real(ifft(a));
elseif ty=='z'
y=[f.';zeros(n0,m)];y=y(:);
else
y=conv(x,xi);y=y(d+1:d+m*n);
end
y=y.*(abs(y)>50*eps);
if mm==1,y=y.';end
if nargout==0,subplot
vx=matverch;
if vx < 4, eval('clg');else,eval('clf');end
l1=(0:l-1)';dtplot(l1,y,'o'),hold on,
plot(0:n:l-1,f,'*'),axesn,hold off
else,
yy=y;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -