Sinc Interpolation without using predefined function
Show older comments
I need to write a code that does linear interpolation. (without using interp1) My function has 3 inputs (n,x,n2). Vector n contains the sample points, and x contains the corresponding values, x(n). Vector n2 contains the coordinates of the query points. My code is this:
function y = sinc_interp(n,x,n2)
y = zeros(length(n2),1);
for i=1:length(n2)
y(i) = sum(x.*sinc(n2(i)- n));
end
end
I think the formula is ok (It is the Shannon formula). The problem is that for various input functions, it doesn't look good. For example:
a = 0.7;
N = 10;
n = 0:N;
x = n.*a.^n + 1;
n2 = linspace(0,10,1000);
figure(1)
plot(n2,n2.*a.^n2 + 1)
y3 = sinc_interp(n,x,n2);
figure(2)
plot(n2,y3)

Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!