限制最小二乘回归的范围

Limit the range of least square regression

我想对一组数据 A(k1,k2) 进行回归,但是我想将其回归限制在 -K1<k1<K1-K2<k<K2 的范围内。 A是由60x60矩阵组成的图像相位,维度为MxN。从 A 的归一化频率区域的中心起 0.1N/2 进行最小二乘近似。

这是代码的一部分:

A=rand(60);
[m, n]=size(A);
[M,N] = meshgrid(1:m,1:n);
X = [M(:), N(:)];
B=regress(A(:), X);  %regression will be done on all the values of A, part where adjustment needed
hat=reshape(X*B,m,n);

您可以先 select 您要对其执行回归的矩阵子集:

% generate the full image
A_full=rand(60);
[m, n]=size(A_full);

% select the part you want, 
% it is not very clear to me if this is really the part you want, 
% but I think you will be able to change it to your needs
A=A_full(floor(m/2-0.1*m/2):ceil(m/2+0.1*m/2), floor(n/2-0.1*n/2):ceil(n/2+0.1*n/2)); 

% perform the regression on the selected part of A (like you did it)
[m, n]=size(A);
[M,N] = meshgrid(1:m,1:n);
X = [M(:), N(:)];
B=regress(A(:), X);  %regression will be done on all the values of A, part where adjustment needed
hat=reshape(X*B,m,n);