移动纵向window(移动平均线?)

moving longitudinal window (moving average?)

我有 12 个 y 和 x 的数据点:-180:30:179。绘制数据后,它看起来像锯齿形图案并且不平滑。为了平滑它,我应用了 30 度(即 +/-15 度)的移动纵向 window。我怎样才能一次将它向前移动一个度,以便纵向 window 像 [-15,15]、[-14,16]、[-13,17]、……这样变化?

到目前为止,这是我的代码

 %y=data %12datapoint 
 y=[90, 65, 60, 53, 70, 82, 65, 38, 44, 71, 77, 64];
 sum=0;                                                                    
 for x=-180:30:179
    for k=1:30
        sum=sum+y(x-15+k);
    end
    avg(x)=sum/30;
    sum=0;                                                                
  end

我可能想从字里行间读到太多。但听起来您并不是真的要移动平均线。这听起来有点像你想要你的 "zig-zag" 线平滑或 interpolated。如果这是正确的,你可以这样做:

y=[90, 65, 60, 53, 70, 82, 65, 38, 44, 71, 77, 64];
x = -180:30:179;

newX = -180:1:179; %Every degree
y_spline = interp1(x,y,-180:1:179,'spline');
y_pchip = interp1(x,y,-180:1:179,'pchip');

l(1) = plot(x,y,'Color',[0 0 1],'Marker','s');hold on
l(2) = plot(newX,y_spline,'r');
l(3) = plot(newX,y_pchip,'g');
grid on; legend(l,{'Orig','spline','pchip'});

选择插值方法...否则我可能会完全误读您的问题。