中易网

谁有MATLAB种interp函数源程序啊?

答案:1  悬赏:0  
解决时间 2021-01-30 20:19
谁有MATLAB种interp函数源程序啊?
最佳答案
哈哈。

MATLAB 2009b的interp文件

function [odata,b] = interp(idata,r,l,cutoff)
%INTERP Resample data at a higher rate using lowpass interpolation.
% Y = INTERP(X,R) resamples the sequence in vector X at R times
% the original sample rate.The resulting resampled vector Y is
% R times longer, LENGTH(Y) = R*LENGTH(X).
%
% A symmetric filter, B, allows the original data to pass through
% unchanged and interpolates between so that the mean square error
% between them and their ideal values is minimized.
% Y = INTERP(X,R,L,CUTOFF) allows specification of arguments
% L and CUTOFF which otherwise default to 4 and .5 respectively.
% 2*L is the number of original sample values used to perform the
% interpolation.Ideally L should be less than or equal to 10.
% The length of B is 2*L*R+1. The signal is assumed to be band
% limited with cutoff frequency 0 < CUTOFF <= 1.0.
% [Y,B] = INTERP(X,R,L,CUTOFF) returns the coefficients of the
% interpolation filter B.
%
% See also DECIMATE, RESAMPLE, UPFIRDN.

% Author(s): L. Shure, 5-14-87
% L. Shure, 6-1-88, 12-15-88, revised
% Copyright 1988-2004 The MathWorks, Inc.
% $Revision: 1.7.4.5 $$Date: 2007/12/14 15:05:11 $

% References:
% "Programs for Digital Signal Processing", IEEE Press
% John Wiley & Sons, 1979, Chap. 8.1.

if nargin < 3
l = 4;
end
if nargin < 4
cutoff = .5;
end
if l < 1 || r < 1 || cutoff <= 0 || cutoff > 1
error(generatemsgid('InvalidRange'),'Input parameters are out of range.')
end
if abs(r-fix(r)) > eps
error(generatemsgid('MustBeInteger'),'Resampling rate R must be an integer.')
end
if 2*l+1 > length(idata)
s = int2str(2*l+1);
error(generatemsgid('InvalidDimensions'),['Length of data sequence must be at least ',s, 10,...
'You either need more data or a shorter filter (L).']);
end

% ALL occurrences of sin()/() are using the sinc function for the
% autocorrelation for the input data.They should all be changed consistently
% if they are changed at all.

% calculate AP and AM matrices for inversion
s1 = toeplitz(0:l-1) + eps;
s2 = hankel(2*l-1:-1:l);
s2p = hankel([1:l-1 0]);
s2 = s2 + eps + s2p(l:-1:1,l:-1:1);
s1 = sin(cutoff*pi*s1)./(cutoff*pi*s1);
s2 = sin(cutoff*pi*s2)./(cutoff*pi*s2);
ap = s1 + s2;
am = s1 - s2;
ap = inv(ap);
am = inv(am);

% now calculate D based on INV(AM) and INV(AP)
d = zeros(2*l,l);
d(1:2:2*l-1,:) = ap + am;
d(2:2:2*l,:) = ap - am;

% set up arrays to calculate interpolating filter B
x = (0:r-1)/r;
y = zeros(2*l,1);
y(1:2:2*l-1) = (l:-1:1);
y(2:2:2*l) = (l-1:-1:0);
X = ones(2*l,1);
X(1:2:2*l-1) = -ones(l,1);
XX = eps + y*ones(1,r) + X*x;
y = X + y + eps;
h = .5*d'*(sin(pi*cutoff*XX)./(cutoff*pi*XX));
b = zeros(2*l*r+1,1);
b(1:l*r) = h';
b(l*r+1) = .5*d(:,l)'*(sin(pi*cutoff*y)./(pi*cutoff*y));
b(l*r+2:2*l*r+1) = b(l*r:-1:1);

% use the filter B to perform the interpolation
[m,n] = size(idata);
nn = max([m n]);
if nn == m
odata = zeros(r*nn,1);
else
odata = zeros(1,r*nn);
end
odata(1:r:nn*r) = idata;
% Filter a fabricated section of data first (match initial values and first derivatives by
% rotating the first data points by 180 degrees) to get guess of good initial conditions
% Filter length is 2*l*r+1 so need that many points; can't duplicate first point or
% guarantee a zero slope at beginning of sequence
od = zeros(2*l*r,1);
od(1:r:(2*l*r)) = 2*idata(1)-idata((2*l+1):-1:2);
[od,zi] = filter(b,1,od); %#ok
[odata,zf] = filter(b,1,odata,zi);
odata(1:(nn-l)*r) = odata(l*r+1:nn*r);

% make sure right hand points of data have been correctly interpolated and get rid of
% transients by again matching end values and derivatives of the original data
if nn == m
od = zeros(2*l*r,1);
else
od = zeros(1,2*l*r);
end
od(1:r:(2*l)*r) = 2*idata(nn)-(idata((nn-1):-1:(nn-2*l)));
od = filter(b,1,od,zf);
odata(nn*r-l*r+1:nn*r) = od(1:l*r);
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
面对爱砸东西的女朋友怎么佃
皮肤容易晒曝皮怎么办?
SAI咋调整语言
国外生活小窍门大合集,太有用了,不知道歪果
为什么说租金控制是毁灭一个城市的最好办法
冬季恋歌 歌词
现在的公司债必须是上市公司才能发行吗,一般
富阳区文居街13号怎么走
优酷可以看哪些青春校园韩剧
怎么催货代回传SO
北京交通大学通信类考研
never give up! never lose heart! keep
schizochytrium sp是什么意思
为什么两个微信号不同,发上朋友圈的另一个会
安全法实施条例第五十二条中无交通信号灯无警
推荐资讯
夏北幼儿园(佛山南海区)地址有知道的么?有点
人生没有目标,就象
小博士教育(菏泽成武县)地址有知道的么?有点
经常刻录光盘会不会损坏电脑?
现在还能买到20年前奥迪双钻的四驱车吗,淘宝
三八妇女节送女客户什么花好
开通绿钻 在手机的QQ音乐下载歌曲 需要流量吗
求助.新浪sae上,配置thinkphp去掉index.php
access中查询语文数学外语三门平均分
∫(cosx)²(cosx)²dx等于多少
女生送男生糖果是什么意思?
找个弟弟玩
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?