Sinc Interpolation without using predefined function
이전 댓글 표시
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)

채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
