Basics of interpolation: is filter or upsample first?

I am studying interpolation filters. I'm under the impression that when talking about interpolating a signal, we filter and then upsample the signal.

BUT

In an article, Interpolation (Digital Filter Design Toolkit, is given a block scheme, where we upsample first and then filter.

The same explanation was given as an answer here:Interpolation vs Interpolation Filter?

I am confused. I created a simple example:

• Create a vector
1. Upsample then filter
2. Filter then upsample.

The output vectors were different.

Which one is correct? Filter + upsample or upsample + filter?

You wrote:

Which one is correct? Filter + upsample or upsample + filter?

The answer is actually neither. Lowpass filtering is part of upsampling, not an extra step. What is referred to as "expanding" in the diagram (and what you have called "upsampling") is just zero insertion. The first step in upsampling by a factor of L is to insert L-1 zeros between samples. The second step is to lowpass filter this "expanded" sequence to complete the interpolation.

From this it should be clear that you have to insert zeros before filtering, not after. Wikipedia has a fairly good article on this.

Edit:

What I wrote above concerns basic upsampling by an integer factor. What is possibly confusing you is that for fractional resampling (i.e, by a factor of L/M), there are more efficient ways to skin the cat than by upsampling by L followed by downsampling by M, since many of the samples calculated in the upsampling step are thrown away in the downsampling step. The more efficient method is known as polyphase interpolation.

To add to Gillespie's correct answer, it's worth knowing that in the literature of DSP the terminology used to describe "sample rate change" is often confusing. Here's some of the terminology that I've seen in the past:

Just know that "interpolation" is not a filter, but rather a two-step mathematical process (zero-stuffing followed by lowpass filtering).

• And when dsp is used for image processing, the same math is used for «image scaling». The fun part is to have an image-rejection filter in your image scaler :-) Jul 6, 2022 at 8:56

Suppose you have a signal at sampling rate $$F_s$$ and you want to upsample it by a factor $$N$$ to a new sampling rate $$NF_s$$.

The correct way is:

1. Expand it by inserting $$N-1$$ zeros between each sample: you get a signal at $$NF_s$$ and its spectra is a repetition of the original signal spectrum tiled over the frequency axis.

2. Apply a lowpass filter to remove frequencies above $$F_s/2$$

If you do it in the opposite order, and filter the original signal (sampled at $$F_s$$) first, then the filter cannot remove the duplicate spectra at frequencies above $$F_s/2$$, because it is applied before these spectra are created by expanding. So if you apply a filter before expanding, the spectrum after expanding will be a repetition of the filtered signal spectrum tiled over the frequency axis.

However, the way described above is not the most efficient way to do this. After inserting $$N-1$$ samples between each original sample, the signal contains a large proportion of zero samples, and their positions are known. Multiplying by zero is a waste of time and resources. So a proper interpolator does this:

1. Pretend to expand by inserting $$N-1$$ zeros between each sample. But it doesn't insert the zeros, in fact this step doesn't actually exist.

2. Convolve with the impulse response of a lowpass filter to remove frequencies above $$F_s/2$$, as if $$N-1$$ zeros had been inserted between each sample. This means starting at the correct offset in the impulse response that lines up with a sample that is not zeroed, then skipping the $$N-1$$ zeroed samples, to only compute the multiply/accumulate operations for the samples that were not virtually zeroed in the expanded signal.

That's why in this manner you don't get two separate blocks, it is done in one operation.