# Choosing right cut-off frequency for a LP filter in upsampler

I'm implementing a upsample function in Matlab but it's not perfect right now,for reasons I'm not sure. Here is my code:

U=5; %upsampling rate
N = U*length(x);

% Init
x_up = zeros(1,N);

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);


And these are the results:

From theory perspective, everything looks like fine to me but how can I make my upsampler perfect?

• Is there a reason you are using firpmord() instead of simply using a $sinc()$ filter? Commented Jan 21, 2020 at 13:40
• @havakok not actually, i'll try with sinc. Commented Jan 21, 2020 at 15:02
• I usually use MATLAB's designfilt tool. I think you'd find it pretty helpful for this Commented Jan 21, 2020 at 18:42

This first slide shows how images are created through zero-insert. The digital spectrum is already periodic, zero insert just extends the sampling rate without changing the periodicity or original shape of the spectrum-- so when we interpolate by 4 for example as done here, the images that were originally around $$F_s$$, $$2F_s$$ become part of our spectrum in the first Nyquist zone at $$F_s/4$$ and $$F_s/2$$. These must be filtered out to complete the interpolation.