我在 Matlab 中实现了一个上采样函数,但它现在并不完美,原因我不确定。这是我的代码:
U=5; %upsampling rate
N = U*length(x);
% Init
x_up = zeros(1,N);
% Zero-pad
ind=1;
for n=1:N
if mod(n,U)==0
x_up(n)=x(ind);
ind = ind+1;
end
end
%% Design a LP filter
tol = (1/U)/2;
[n,fo,mo,w] = firpmord([1/(2*U)-tol 1/(2*U)+tol],[1 0],[0.01,0.01]);
b = firpm(n,fo,mo,w);
x_up = [zeros(1,n),x_up]; %To avoid group-delay
x_up = conv(b,x_up,'full');
x_up(abs(x_up)<0.01)=0;
% Remove leading and tailing zeros
x_up = x_up(find(x_up,1,'first'):find(x_up,1,'last'));
x_up = x_up(1:N);
从理论的角度来看,对我来说一切都很好,但我怎样才能让我的上采样器完美呢?





