my_interp.m

来自「通信系统仿真时使用的插值程序」· M 代码 · 共 47 行

M
47
字号
function [x_v,xx,yy]=my_interp(y_v,x_vect,y_vect,interp_method)
% y_v= 0.1 , 0.01 etc. BLER value
% x_v = Ior/Ioc value (dB) which we wanted
% y_vect= BLER data come from the simulatin result
% x_vect=SNR (Ior/Ioc) value which we set during the simulation 
% interp_method: interpolation method which you want to use 
%     0->  'linear'   - linear interpolation
%     1->  'nearest'  - nearest neighbor interpolation
%     2->  'spline'   - piecewise cubic spline interpolation (SPLINE)
%     3->  'pchip'    - piecewise cubic Hermite interpolation (PCHIP)
%     4->  'cubic'    - same as 'pchip'
%     5->  'v5cubic'  - the cubic interpolation from MATLAB 5, which does not
%                    extrapolate and uses 'spline' if X is not equally spaced.
%  
% liudong , 2002/10/18
% 

    switch interp_method
    case 0
        m_str=['linear'];
    case 1
        m_str=['nearest'];
    case 2
        m_str=['spline'];
    case 3
        m_str=['pchip']; 
    case 4
        m_str=['cubic']; 
    case 5
        m_str=['v5cubic']; 
    end     
    
   
    x1_vect=sort(x_vect);
    y1_vect=sort(y_vect);
    xx=[min(x1_vect):0.1:max(x1_vect)*2];
    y1=interp1(x1_vect,y1_vect,xx,m_str);
    yy=y1(length(y1):-1:1);
    [p1,p2]=min(abs(abs(yy)-y_v));
    if abs(yy(p2))>y_v & abs(yy(p2+1))>y_v
       x_v= (xx(p2)+xx(p2+1))/2;
    else 
       x_v=xx(p2);
    end
    
    
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?