# Better understanding of downsampling (decimation) and upsampling (interpolation)

I suggest to limit, (or at lest to start by), 1D signals. Of course if someone wants to extend they are welcome.

For example, in some lectures it is mentioned that

• an ideal 1D interpolator is an upsampler (by the wanted factor, e.g. 2) in cascade with an ideal lowpass filter i.e. an sinc.

• Decimation would be to opposite. A convolution with a filter (sinc?) then a downsampler (by the wanted factor e.g. 2).

In Matlab, given a sine wave at a given frequency for example, how would you proceed to downsample it to a lower frequency? And could you make the link with aliasing ?

I have started to do the following, "manually" coded:

    %Working with audio frequencies, for example,
%to listen the results with audioread() function afterwards
Fs=8000;%sampling frequency
t=0:(1/Fs):1;
f=4000;
x=sin(2*pi*f*t);
x_dwnsamp=zeros(length(x));
%decimate x to see what happends wrt aliasing
decimation_step=2;
for i=1:decimation_step:length(x)
x_dwnsamp(i)=x(i);
end
figure;
subplot(1,2,1);
plot(abs(fft(x)));
subplot(1,2,2);
plot(abs(fft(x_dwnsamp)));


This was an attempt to resample the signal x which is just at the Nyquist freq. (4KHz) fora sampling freq. of 8KHz.

Second, the code just inserts zeros alternatively. It doesn't downsample (means remove those samples altogether). This means, it is still sampled with original sampling frequency (8kHz) but now with alternate zeros. And what is the effect of alternate zeros in signal? It creates a replica of spectrum. Also, in the code, the signal frequency is exactly half of sampling frequency, which causes sampling to happen at zero crossings. You can plot the signal $$x$$ and see.
In the code, I changed $$f$$ to 3000, and can see 2 peaks at 3000Hz and 5000 ($$fs - f$$)Hz. For the downsampled signal, apart from original signal, there is 2 peaks corresponding to replicated spectrum.