0
$\begingroup$

I implemented an interpolation method in C++ based on this equation

y(t) = x[n]*sinc((t-nT)/T)

where:
n - index of input signal,
x - input signal buffer,
t - is an actual time, 
nT - time of input samples,
T - period of input signal.

I calculated it on 33 samples:1+2*16. I tested it on Matlab and C++ on VS 2010. It works great on close frequencies (eg. 24kHz to 20kHz) but when I tested situation where the input signal is 24kHz and has a peak on 8kHz and then I wanted to interpolated it to 700Hz it gave me a peak at 300Hz so it is totally wrong. I expected that the main couse of this situation is that I did not use the cutoff frequency for low pass filter in this equation above. Seriously, I do not know how to add low pass filtration to my method.

Thanks for all your suggestions or advise.

$\endgroup$
  • 1
    $\begingroup$ Welcome to DSP.SE! Your question is a little unclear for me. You have discrete samples $x[n]$ that you want to turn into a continuous-time function $y(t)$. If that's the case, I would have thought you'd do: $y(t) = \sum_{n=0}^{N-1} x[n] {\rm sinc}((t-nT)/T)$ ? And I don't understand what you mean by I calculated it on 33 samples:1+2*16. $\endgroup$ – Peter K. Sep 29 '15 at 13:22
  • 1
    $\begingroup$ so i calculated i on the 16 in the past, 16 in the future and the closest to the current timestamp, do the window has 33. The rest, you understood correct. $\endgroup$ – eryk Sep 29 '15 at 13:28
  • $\begingroup$ Next questions: you say T - period of input signal but I would have called T the sampling period. I'm not sure how you interpolated it to 700Hz? Does that mean you set T=1/700? $\endgroup$ – Peter K. Sep 29 '15 at 13:33
  • $\begingroup$ T is a period in nanoseconds and here we have 10^9/24000 = 41667 ns, but of input signal not a cycle time of output $\endgroup$ – eryk Sep 29 '15 at 13:38
  • $\begingroup$ I interpolate it to 700kHz because I have a time domain in 700 Hz so the time t is buffer {0, 1s/700, 2s/700, 3s/700.. } and so on. $\endgroup$ – eryk Sep 29 '15 at 13:48
1
$\begingroup$

When you use interpolation to decrease the sample rate, you need to first low pass filter the signal to a bandwidth below the new FsNew/2. You can do this by using a wider Sinc kernel related to the new lower sample rate. e.g. intead of T in the denominator on the Sinc parameter in your interpolation kernel, use 1/FsNew.

$\endgroup$
  • $\begingroup$ OK thank you very much for your answer! You really understand my problem. I used equation y(t) = x[n]*sinc((t-nT)/T) and calculated T as a period of input signal (for 24kHz it should be 41667ns). When I tried calculated this period from output time domain (for 700 it is 1428571ns)it is going extremely wrong and then calculated spectrum shows wrong results at all. $\endgroup$ – eryk Oct 1 '15 at 7:27
2
$\begingroup$

I'm still not quite sure I understand what you're trying to achieve, but here's an example I cooked up in scilab.

The input is 33 points of a sine wave:

fs = 100; // 10kHz sampling rate
Tin = 1/fs; // Input sampling period
N = 16;
tin = [-N:N]; // Times of samples
f0 = 5;

x = sin(2*%pi*f0/fs*tin + 1.123791823)

clf
subplot(211)
plot(tin,x)

The sampling frequency is 100Hz, the frequency of the sine wave is 5 Hz.

Then, I try to interpolate this up to a sampling frequency of 700Hz using the sinc formula:

Tout = 1/700;
tout = -N:Tout:N;
y = zeros(1,length(tout))
for n = 1:length(tin)
    y =  y + x(n)*sinc(%pi*(tout-tin(n)))
end

plot(tout,y,'r:')
title('Input (blue line) and interpolated (red dotted line)')

subplot(212)
dx = splin(tin,x);
x_interp = interp(tout,tin,x,dx);
plot(tout,y-x_interp)
title('Error')

The results are as plotted below.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.