Reputation: 1
For a university assignment, I have to interpolate some points that I had previously sampled from a wave. It works as long as I interpolate them with the interp1
function.
My teacher wants us to interpolate it using the sinc
function, so I googled it and the mathworks documentation says I should do this:
rng default
t = 1:10;
x = randn(size(t))';
ts = linspace(-5,15,600);
[Ts,T] = ndgrid(ts,t);
y = sinc(Ts - T)*x;
plot(t,x,'o',ts,y)
xlabel Time, ylabel Signal
legend('Sampled','Interpolated','Location','SouthWest')
legend boxoff
It works, but since I have to interpolate points that are in a reduced domain I modified the code to try and interpolate points that are in the range from 0
to 1
:
rng shuffle
t = 0:0.1:1;
x = randn(size(t))';
ts = linspace(-1,2,600);
[Ts,T] = ndgrid(ts,t);
y = sinc(Ts - T)*x;
plot(t,x,'o',ts,y)
xlabel Time, ylabel Signal
legend('Sampled','Interpolated','Location','SouthWest')
legend boxoff
And it just doesn't work properly, I get this from the above:
Could you please tell me what am I doing wrong, or if sinc
only works in "big" domains?
Upvotes: 0
Views: 4405
Reputation: 11064
You should also scale your sinc function in the time direction to fit your data:
dt = 0.1;
y = sinc((Ts - T)/dt)*x;
Explanation
Because you want to interpolate between your data point, you should be sure that the interpolation function (f
) of the other data points is zero at the current data point:
f(k*dt) = 0 for all integers k != 0
It is known that
sinc(k) = 0 for all integers k != 0
Therefore your interpolation function should be
f(t) = sinc(t/dt);
Upvotes: 5