2
\$\begingroup\$

I am currently working on a project on MATLAB, and I need to use interpolation and decimation on various low pass, band pass and high pass filters with sampling frequencies of 10kHz. There was no problem with interpolating my LP and BP filters. But trying to interpolate a HP filter by a factor of 4 gave me a resulting filter whose response is similar to that of a band pass filter. The figures below show my filters' response by using the freqz(.) command.

The High Pass Filter, Interpolated by a Factor of 4

The Filter Before Interpolation

I used an anti-imaging filter in the form of an 8th order Chebyshev Type I filter, but I feel like I need to use another type of filter. But I don't know what to do. My code pieces are as following.

function [interp, y] = Interpolation(x, L)

    len = length(x);
    y = zeros(1,len*L);

    y((0:len-1)*L+1) = x; % Spreading the values of x 

    [n, d] = cheby1(8, 0.5, 1/L); % Anti-imaging filter

    interp = filter(n, d, y);
end

Code to run in the command window:

[int, y] = Interpolation(fltH, 4);
freqz(y, 1, 512)
figure
freqz(fltH, 1, 512)

Any help is appreciated.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Interpolation means inserting zeroes every other samples, which is what you're doing with the y(...)=x line. After that you're appplying a lowpass filtering, which is why you get a bandpass from a highpass. But that's not needed, since the interpolation process doesn't add high frequency content, it preserves all the information of the original filter. So all you need to do is the equivalent of this:

M = 20;
wc = 0.37;
N = 4;
k = [-M:M];
h = -wc*sinc(wc*k);
h(M + 1) = 1 - wc;
g = zeros(1,(2*M + 1)*N);
g([0:2*M]*N + 1) = h;
plot(20*log10(abs(fft(h, 1024))(1:512)), "", 20*log10(abs(fft(g, 1024))(1:512)))

Where I used some arbitrary highpass, and this is what it plots:

interpolated highpass

If what you expected was to have a flat passband all the way to Nyquist, you can't, since that's what the interpolation does: it shrinks the spectrum relative to the original response, and comes with frequency folding. Your filtering removed the higher image, but it can't restore the passband (it doesn't make sense to filter it out and expect a miracle restoration).

The only solution is to recalculate the filter, because that would imply the Nyquist is just like the original, which means the impulse response needs to be calculated relative to the Nyquist, which means a new wc can only be given by a new sinc(). And for that you'll need to use wc/N and a range from [-M*N:M*N], thus a length 4x as much. If that's too much, try an IFIR, which will reduce the total order, but will add a bit more delay.

\$\endgroup\$
3
  • \$\begingroup\$ This is a well detailed and clear explanation. Thank you. The only thing which confused me in this code is appending an M+1th element to h. I noticed that the filter shows a band pass characteristic instead of a high pass one if I delete that line of code. I would be grateful if you could explain that one as well. Thanks a lot again. \$\endgroup\$ Commented Apr 19, 2022 at 8:39
  • 1
    \$\begingroup\$ @AlperenDemirkilit If you mean this part, h(M + 1) = 1 - wc;, that's preparing the highpass filter (pkg signal fails to compile for me, so I can't use fir1()). Remember that a lowpass is defined as h[]=sinc(), whereas a highpass is h[]=-sinc() with h[0]=1-wc (for the non-causal filter). Try plotting a=wc*sinc(wc*k) versus h from above, and you'll see the differences. And, given the way Octave (mimicking Matlab) applies the indexing, by starting from 1, not 0, the midpoint of h[] is not M, but M+1. \$\endgroup\$ Commented Apr 19, 2022 at 9:31
  • \$\begingroup\$ Now it is all crystal clear, I really cannot describe how much this helps me. Thank you so much! \$\endgroup\$ Commented Apr 19, 2022 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.