# Differenz between interpolation and resampling

15 views (last 30 days)
Manuel on 5 Sep 2017
Commented: Manuel on 6 Sep 2017
Hi,
i have a data set of force values for an industrial upsetting machine. The data has an original sample rate FS=250kHz and a duration of 10sec. For data processing purposes i want to upsample the data to FS=1000kHz. I have read that the function "resample" also incorporates a FIR anti-aliasing filter. Is this the only differenz?
As my signal only containing frequencies up to 30kHz and lower, is there still the need of using the resample function with the FIR filter?
Furthermore i performed both functions (resample and interp) on my signal and the results were quite the same (as shown in the picture), except for the last part. Any ideas why both functions fail to resample the original signal correctly in the second section?
Here is my code:
time_fs250=linspace(0, 10-1/250000, 2500000)';
time_fs1000=linspace(0, 10-1/1000000, 10000000)';
force_resample=resample(force,4,1);
force_interpolate=interp(force,4);
plot(time_fs250,force,time_fs1000,force_resample,'g',time_fs1000,force_interpolate,'m');
legend('Original FS=250k', 'Resampled FS=1000k', 'Interpolated FS=1000k');
xlabel('time');
ylabel('force');
Greg Dionne on 5 Sep 2017
Alright, I'll take a look. You might be experiencing an artifact of the default FIR filter.

Greg Dionne on 5 Sep 2017
The default filter has 10 taps. If you increase it, you can reduce the amplitude of the ringing. The (P,Q,N,Beta) syntax might give you a better result (use a larger N). The example Resampling Uniformly Sampled Signals shows how to make a custom filter for signals that have lower bandwidth... since you verified that there was no content above 30kHz, I think this applies to you.
I tried to recreate an idealized version of your signal for comparison and the example code seemed to work fine on that. Try this on your original signal to see if it helps.
Fs = 250000;
force = ones(1,10*Fs);
force(1:2*Fs) = -100;
force(2*Fs:end) = 101000;
time_fs250=linspace(0, 10-1/250000, 2500000)';
time_fs1000=linspace(0, 10-1/1000000, 10000000)';
force_resample=resample(force,4,1,256,12);
force_interpolate=interp(force,4);
p=4;
q=1;
normFc = .98 / max(p,q);
order = 256 * max(p,q);
beta = 12;
lpFilt = firls(order, [0 normFc normFc 1],[1 1 0 0]);
lpFilt = lpFilt .* kaiser(order+1,beta)';
lpFilt = lpFilt / sum(lpFilt);
% multiply by p
lpFilt = p * lpFilt;
% resample and plot the response
force_customfilt = resample(force,p,q,lpFilt);
plot(time_fs250,force, ...
time_fs1000,force_resample,'g',...
time_fs1000,force_interpolate,'m',...
time_fs1000,force_customfilt,'r');
legend('Original FS=250k', ...
'Resampled FS=1000k', ...
'Interpolated FS=1000k', ...
'Custom Fs=1000k');
xlabel('time');
ylabel('force');
Manuel on 6 Sep 2017
Both solutions work absolutely fine! Thank you very much!