I'm having 2 signals which have different sampling rates i.e., 1ms(A) and 4ms(B) and I've tried to upsample/downsample either of the signals based on the code snippet Resampling based on FFT which I believe is equivalent of what is descriped in How to resample audio using fft or dft
% FFTRESAMPLE Resample a real signal by the ratio p/q function y = fftResample(x,p,q) % --- take FFT of signal --- f = fft(x); % --- resize in the FFT domain --- % add/remove the highest frequency components such that len(f) = len2 len1 = length(f); len2 = round(len1*p/q); lby2 = 1+len1/2; if len2 < len1 % remove some high frequency samples d = len1-len2; f = f(:); f(floor(lby2-(d-1)/2:lby2+(d-1)/2)) = ; elseif len2 > len1 % add some high frequency zero samples d = len2-len1; lby2 = floor(lby2); f = f(:); f = [f(1:lby2); zeros(d,1); f(lby2+1:end)]; end % --- take the IFFT --- % odd number of sample removal/addition may make the FFT of a real signal % asymmetric and artificially introduce imaginary components - we take the % real value of the IFFT to remove these, at the cost of not being able to % reample complex signals y = real(ifft(f));
i.e., reimplemented the fftResample in C++ using FFTW libraries.
The problem is that the output is distorted because of the zero-padding. I'm relatively new to Singal processing and I would appreciate if users can help me understand:
if I'm using the right code snippet to upsample/downsample?
highlight the benefits of upsampling(A to 4ms) compared to downsampling(B to 1ms)?