I am not sure I got your message correctly.
But for downsampling you might do one of 3 things:
- Upsample to an integer factor and then decimate.
- Use the Fourier Series equations.
- Apply low pass in frequency domain while keeping the symmetry.
If I get you right, you tried 3 (Which is what’s posted as a sample code in my answer).
I will add to my answer the code for the other 2.
But to answer your questions, let’s say the input has n
samples and you want to interpolate it to m < n
samples.
What you can do, as in (1) above is:
subSampleFctr = floor(numSamples / numSamplesO) + 1;
numSamplesO = subSampleFctr * numSamplesO;
The upsample to numSamplesO
and then decimate by vX = vX(1:subSampleFctr:numSamplesO);
.
Regarding your code.
My code supports Complex and Real signals.
When I know the output should be Real I use ifft(SincInterpolationDft(fft(vX), numSamplesOutput), 'symmetric');
. Since for real signals the Nyquist sample must be real you can either force specifically that sample or just on the inverse DFT use the symmetric property.
For the Nyquist sample (The one which I multiply by 0.5) taking only the real part is equivalent to what you did (You added a conjugate term).
The Fourier Series equation, for real signals, allows using half the data with cos()
instead of complex numbers. Yet it doesn’t have all the optimizations of the fft()
/ ifft()
so I’m not sure it will be faster.