Matlab:插值误差 [英] Matlab:Interpolation Error
问题描述
对于上述曲线,我想通过将曲线分为19帧来执行基于帧的采样:
19帧:
4帧:每15秒时间间隔
2帧:30秒间隔时间间隔
2帧:60秒间隔时间间隔
11帧:每个200秒的时间间隔
我已经为帧分析写了以下插值函数。 c_t
是存储在上图中表示的信号的位置:
function c_i = Frame_analysis(a1,a2,a3,b1,b2,b3,td,tmax,k1,k2,k3)
t = 0:6:3000; %原始采样时间(以秒为单位)
t_i = [0:15:60,90:30:120,180:60:240,440:200:2240];%15秒间隔的前4帧的内插采样时间
K_1 =(k1 * k2)/(k2 + k3);
K_2 =(k1 * k3)/(k2 + k3);
%DV_free = k1 /(k2 + k3);
c_t = zeros(size(t));
ind =(t> td)& (t
c_t(ind)= conv(((t(ind)-td)./(tmax-td)*(a1 + a2 + a3)),(K_1 * exp( - (k2 + k3)* t(ind)+ K_2)),'same');
%Y_i = interp1(t,c_t(ind),t_i); %第一帧的插值
ind =(t> = tmax);
c_t(ind)= conv((a1 * exp(-b1 *(t(ind)-tmax))+ a2 * exp(-b2 *(t(ind)-tmax))) + a3 * exp(-b3 *(t(ind)-tmax)),(K_1 * exp( - (k2 + k3)* t(ind)+ K_2)),'same');
c_i = interp1(c_t(ind),t_i);%下一个consequtive框架的插值
figure;
plot(t_i,c_i);
轴([0 3000 -2000 80000]);
xlabel('Time [secs]');
ylabel('concentration [Mbq]');
title('我的信号');
%plot(t,c_tnp);
end
当我运行代码时,我已经获得了一个没有任何内插,从图中可以看出,如下所示:
我的代码中有哪些错误,我可以如何在第一张图中表示的输出曲线中获得更好的插值来获得不同的框架?
以下是我手动提供的输入值
Frame_analysis (2501,18500,65000,0.5,0.7,0.3,3,8,0.014,0.051,0.07)
这里有多个问题,由您决定如何解决这些问题。
这是我可以提供的:
-
您没有为绘图命令指定x坐标。可以这样做,但是,Matlab将使用向量的索引作为x轴。示例:如果您有
y = 1:2:6;
plot(y);
持有;
y = 1:1:6;
plot(y);
你会看到差异。
这适用于你的情况?您指定较高分辨率的矢量(t_i
,与t
相比),但在绘图命令中,您不提供这个新向量的x坐标。 -
您对
c_t
的定义提供非常小的值(按10 ^ -77
)。从t> 60,您的输出与0无关。
这样做会影响插值吗?
您指定间隔时间[0 60]
你想要的步长为15 - 这不会给你很多的解决方案:
您可能需要更改为:
t_i = [0:0.5:60,90:30:120,180:60:240,440:200:2240]
哪个会给你这个情节:
-
无论哪种情况,我都不明白为什么你选择了一个数据范围在60以上(一直到3000)为你要绘制的数据。这就解释了为什么你没有看到任何轴限值
axis([0 3000 -2000 80000]);
,远远超出了y值的范围, -
I would like to perform a frame based analysis on the following curve Which expresses the relation between time and concentration (x-axis: time in minutes; y-axis: concentration in Mbq):
For the above curve I would like to perform frame based sampling by splitting the curve into 19 frames:
19 frames:
4 frames : Each of 15 seconds time interval
2 frames : Each of 30 seconds time interval
2 frames : Each of 60 seconds time interval
11 frames : Each of 200 seconds time interval
I have written the following interpolation function for the frame analysis. c_t
is where my signal which was expressed in the figure above is stored:
function c_i = Frame_analysis(a1,a2,a3,b1,b2,b3,td,tmax,k1,k2,k3)
t= 0:6:3000; % The original sample time, in seconds
t_i =[0:15:60,90:30:120,180:60:240,440:200:2240];% The interpolated sample time for first 4 frames of 15 second interval
K_1 = (k1*k2)/(k2+k3);
K_2 = (k1*k3)/(k2+k3);
%DV_free= k1/(k2+k3);
c_t = zeros(size(t));
ind = (t > td) & (t < tmax);
c_t(ind)= conv(((t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');
% Y_i = interp1(t,c_t(ind), t_i); % Interpolation for first frame
ind = (t >= tmax);
c_t(ind)=conv((a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax))) + a3 * exp(-b3 * (t(ind) - tmax)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');
c_i = interp1(c_t(ind),t_i);% Interpolation for Next consequtive frames
figure;
plot(t_i,c_i);
axis([0 3000 -2000 80000]);
xlabel('Time[secs]');
ylabel('concentration [Mbq]');
title('My signal');
%plot(t,c_tnp);
end
When I run the code, I have obtained a curve without any interpolation as you can see from figure expressed below:
Where have I made a mistake in my code and how can I possibly perform a better interpolation for obtaining different frames in my Output curve expressed in first figure?
Following are the input values which i have provided manually
Frame_analysis(2501,18500,65000,0.5,0.7,0.3,3,8,0.014,0.051,0.07)
There are multiple issues here, and it will be up to you to decide how to address them.
This is what I can provide:
You do not specify an x-coordinate for your plot command. That can be done, however, Matlab will use the index of the vector for the x-axis. Example: if you have
y = 1:2:6; plot(y); hold on; y = 1:1:6; plot(y);
you'll see the difference.
How does this apply to your case? You specify a vector of higher resolution (t_i
, compared tot
), but in your plot command you do not provide this new vector for the x-coordinate.Your definition of
c_t
provides very very small values (on the order of10^-77
). And from t > 60, your output is indifferent from 0.
How does that effect your interpolation?
You specify that for the interval[0 60]
you want step-sizes of 15 - that does not give you a lot of resolution:You might want to change to something like:
t_i =[0:0.5:60,90:30:120,180:60:240,440:200:2240];
Which will give you this plot:
In either case, I do not understand why you chose a data range above 60 (all the way until 3000) for the data you are trying to plot. This explains why you do not see anything with your axis limits
axis([0 3000 -2000 80000]);
that by far exceed the range of y-values and obscures the non-zero data entries for small x.
这篇关于Matlab:插值误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!