⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resamp.m

📁 英文书《Digital Signal Processing with Examples in MATLAB》附带的MATLAB实例
💻 M
字号:
function y=resamp(x,Ly)
% y=resamp(x,Ly)
% 
% Creates a resampled vector, y, of vector x.
% Ly is the length of y. The original sampling frequency, fx,
% is increased or decreased to fy=fx*Ly/Lx.
%
% When Ly>Lx, the x and y spectra are the same. Interpolation
% is in the frequency domain.
% When Ly<Lx, interpolation is in the time domain.
% See also: resconst

% Check for errors.
[M,N]=size(x);
if Ly<=1,                               %assure Ly>1
    error('In resamp, Ly must be >1.');
elseif M~=1 & N~=1,                      %assure x is a vector
    error('In resamp, x must be a vector');
end

Lx=length(x);

% First case: Ly>Lx. See (3.27) in the text.
if Ly>Lx,
    X=row_vec(fft(x));
    m=ceil((Lx+1)/2);
    if(mod(Lx,2)==1),                               % If Lx is odd, m=(Lx+1)/2
        Y=[X(1:m),zeros(1,Ly-Lx),X(m+1:Lx)];
    else                                            % If Lx is even, m=(Lx+2)/2
        H=X(m)/2;
        Y=[X(1:m-1),H,zeros(1,Ly-Lx-1),H,X(m+1:Lx)];
    end
    y=(Ly/Lx)*real(ifft(Y));
% Second case: Ly<=Lx.  Sampling rate is reduced.
else
    y=zeros(1,Ly);
    t=linspace(1,Lx,Ly);
    for i=1:Ly,
        t0=floor(t(i));
        t1=ceil(t(i));
        y(i)=x(t0)+(t(i)-t0)*(x(t1)-x(t0));         % Linear interp.
    end
end
if N==1,
    y=y';                                           %y =column vector
end
return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -