Linear Interpolation

這是一個簡單用Mtalab去做的linear interpolation的實驗

程式碼如下:
clear all;clc;close all;;
L=5;%插入的長度
N=10;%原始信號的長度
fs=10;%原始信號取樣頻率
t=0:1/fs:N/fs;%算出原始信號時間軸
x1=sinc(t);%產生取樣信號

%根據要的插入點數,先在插入的點上放0
x=[];
for i=1:length(x1)
x=[x x1(i) zeros(1,L-1)];
end
%計算插入0的信號,其對應的時間
t1=0:1/(L*fs):(N/fs)+(L-1)/(L*fs);

%產生linear interpolation filter h
h1=[((L-1)/L:-1/L:0) 0];
h=[h1(length(h1):-1:1) 1 h1];

%計算做convolution的長度與其對應的時間
L1=length(x)+length(h)-1;
t2=0:1/(L*fs):(L1-1)/(L*fs);
y=conv(x,h);
% stem(t2,y,'g');

%前L+1點不要並計算與其對應的時間
y2=y(7:L1);
L2=length(y2);
t3=0:1/(L*fs):(L2-1)/(L*fs);

stem(t,x1);hold on;
stem(t3,y2,'k')
stem(t1,x,'r');

留言

熱門文章