如何在 Matlab 中找到 interp1 的正确采样率
how to find the correct sampling rate for interp1 in Matlab
我正在尝试为 interp1(或抽取或重新采样)找到正确的采样率,以绘制由 imfreehand 获得的轴中的多个点..
首先我绘制了一些东西(任何不是特定于正弦的东西)
bands=1:20;plot(bands,sin(bands));
hax=gca;
然后像这样在轴上用imfreehand画一些东西:
imfreehand('Closed',0);
我从 imfreehand 对象中提取数据部分 (大小 1x413) 然后我尝试用原始线的长度绘制它们但是缩放是错误的...
data=get(hfree);
xydata=get(data.Children(4));
% x=xydata.XData;
y=xydata.YData;
len=length(y);
x=1:len;
newlen=length(bands);
scale=(len-1)/(newlen-1);
xx=1:scale:len;
yy=interp1(x,y,xx,'spline');
line(1:length(yy),yy(1:length(yy)),...
'LineWidth',4,...
'Color',[.8 .8 .8],...
'Parent',hax);
有什么提示吗??
此外,建议的下采样结果相同..
for i=4:1:15 %just testing numbers
yy = downsample(y,i);
h=line(1:length(yy),yy(1:length(yy)),...
'LineWidth',1.2,...
'Color',[.8-i/100 .8-i/100 .8-i/100],...
'Parent',hax);
if length(bands)==length(yy)
set(h,'Color',[0 0 0], 'LineWidth',2);
end
end
有什么提示吗?? x2
我真傻,忘了在 interp 中正确缩放
len=length(y);
newlen=length(bands);
scale=ceil(len/newlen)
x1=x(1:scale:end)
y1=y(1:scale:end);
h=line(x1,y1,...
'LineWidth',1.2,...
'Color',[0 0 0],...
'Parent',hax);
yyy=interp1(x1,y1,bands,'pchip',nan)
h=line(1:20,yyy,...
'LineWidth',1.2,...
'Color',[0 1 1],...
'Parent',hax);
我正在尝试为 interp1(或抽取或重新采样)找到正确的采样率,以绘制由 imfreehand 获得的轴中的多个点..
首先我绘制了一些东西(任何不是特定于正弦的东西)
bands=1:20;plot(bands,sin(bands));
hax=gca;
然后像这样在轴上用imfreehand画一些东西:
imfreehand('Closed',0);
我从 imfreehand 对象中提取数据部分 (大小 1x413) 然后我尝试用原始线的长度绘制它们但是缩放是错误的...
data=get(hfree);
xydata=get(data.Children(4));
% x=xydata.XData;
y=xydata.YData;
len=length(y);
x=1:len;
newlen=length(bands);
scale=(len-1)/(newlen-1);
xx=1:scale:len;
yy=interp1(x,y,xx,'spline');
line(1:length(yy),yy(1:length(yy)),...
'LineWidth',4,...
'Color',[.8 .8 .8],...
'Parent',hax);
有什么提示吗??
此外,建议的下采样结果相同..
for i=4:1:15 %just testing numbers
yy = downsample(y,i);
h=line(1:length(yy),yy(1:length(yy)),...
'LineWidth',1.2,...
'Color',[.8-i/100 .8-i/100 .8-i/100],...
'Parent',hax);
if length(bands)==length(yy)
set(h,'Color',[0 0 0], 'LineWidth',2);
end
end
有什么提示吗?? x2
我真傻,忘了在 interp 中正确缩放
len=length(y);
newlen=length(bands);
scale=ceil(len/newlen)
x1=x(1:scale:end)
y1=y(1:scale:end);
h=line(x1,y1,...
'LineWidth',1.2,...
'Color',[0 0 0],...
'Parent',hax);
yyy=interp1(x1,y1,bands,'pchip',nan)
h=line(1:20,yyy,...
'LineWidth',1.2,...
'Color',[0 1 1],...
'Parent',hax);