Main Content

Determine Fixed-Point Types for Complex Least-Squares Matrix Solve with Tikhonov Regularization

This example shows how to use the fixed.complexQRMatrixSolveFixedpointTypes function to analytically determine fixed-point types for the solution of the complex least-squares matrix equation


where A is an m-by-n matrix with mn, B is m-by-p, X is n-by-p, In=eye(n), 0n,p=zeros(n,p), and λ is a regularization parameter.

The least-squares solution is


but is computed without squares or inverses.

Define System Parameters

Define the matrix attributes and system parameters for this example.

m is the number of rows in matrices A and B. In a problem such as beamforming or direction finding, m corresponds to the number of samples that are integrated over.

m = 300;

n is the number of columns in matrix A and rows in matrix X. In a least-squares problem, m is greater than n, and usually m is much larger than n. In a problem such as beamforming or direction finding, n corresponds to the number of sensors.

n = 10;

p is the number of columns in matrices B and X. It corresponds to simultaneously solving a system with p right-hand sides.

p = 1;

In this example, set the rank of matrix A to be less than the number of columns. In a problem such as beamforming or direction finding, rank(A) corresponds to the number of signals impinging on the sensor array.

rankA = 3;

precisionBits defines the number of bits of precision required for the matrix solve. Set this value according to system requirements.

precisionBits = 32;

Small, positive values of the regularization parameter can improve the conditioning of the problem and reduce the variance of the estimates. While biased, the reduced variance of the estimate often results in a smaller mean squared error when compared to least-squares estimates.

regularizationParameter = 0.01;

In this example, complex-valued matrices A and B are constructed such that the magnitude of the real and imaginary parts of their elements is less than or equal to one, so the maximum possible absolute value of any element is |1+1i|=2. Your own system requirements will define what those values are. If you don't know what they are, and A and B are fixed-point inputs to the system, then you can use the upperbound function to determine the upper bounds of the fixed-point types of A and B.

max_abs_A is an upper bound on the maximum magnitude element of A.

max_abs_A = sqrt(2);  

max_abs_B is an upper bound on the maximum magnitude element of B.

max_abs_B = sqrt(2);

Thermal noise standard deviation is the square root of thermal noise power, which is a system parameter. A well-designed system has the quantization level lower than the thermal noise. Here, set thermalNoiseStandardDeviation to the equivalent of -50dB noise power.

thermalNoiseStandardDeviation = sqrt(10^(-50/10))
thermalNoiseStandardDeviation = 0.0032

The quantization noise standard deviation is a function of the required number of bits of precision. Use fixed.complexQuantizationNoiseStandardDeviation to compute this. See that it is less than thermalNoiseStandardDeviation.

quantizationNoiseStandardDeviation = fixed.complexQuantizationNoiseStandardDeviation(precisionBits)
quantizationNoiseStandardDeviation = 9.5053e-11

Compute Fixed-Point Types

In this example, assume that the designed system matrix A does not have full rank (there are fewer signals of interest than number of columns of matrix A), and the measured system matrix A has additive thermal noise that is larger than the quantization noise. The additive noise makes the measured matrix A have full rank.

Set σnoise=σthermal noise.

noiseStandardDeviation = thermalNoiseStandardDeviation;

Use fixed.complexQRMatrixSolveFixedpointTypes to compute fixed-point types.

T = fixed.complexQRMatrixSolveFixedpointTypes(m,n,max_abs_A,max_abs_B,...
T = struct with fields:
    A: [0x0]
    B: [0x0]
    X: [0x0]

T.A is the type computed for transforming [λInA] to R=QT[λInA] in-place so that it does not overflow.

ans = 


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 40
        FractionLength: 32

T.B is the type computed for transforming [0n,pB] to C=QT[0n,pB] in-place so that it does not overflow.

ans = 


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 40
        FractionLength: 32

T.X is the type computed for the solution X=[λInA]\[0n,pB], so that there is a low probability that it overflows.

ans = 


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 44
        FractionLength: 32

Use the Specified Types to Solve the Matrix Equation

Create random matrices A and B such that B is in the range of A, and rankA=rank(A). Add random measurement noise to A which will make it become full rank, but it will also affect the solution so that B is only close to the range of A.

[A,B] = fixed.example.complexRandomLeastSquaresMatrices(m,n,p,rankA);
A = A + fixed.example.complexNormalRandomArray(0,noiseStandardDeviation,m,n);

Cast the inputs to the types determined by fixed.complexQRMatrixSolveFixedpointTypes. Quantizing to fixed-point is equivalent to adding random noise [4,5].

A = cast(A,'like',T.A);
B = cast(B,'like',T.B);

Accelerate the fixed.qrMatrixSolve function by using fiaccel to generate a MATLAB executable (MEX) function.

fiaccel fixed.qrMatrixSolve -args {A,B,T.X,regularizationParameter} -o qrMatrixSolve_mex

Specify output type T.X and compute fixed-point X=A\B using the QR method.

X = qrMatrixSolve_mex(A,B,T.X,regularizationParameter);

Verify the Accuracy of the Output

Verify that the relative error between the fixed-point output and the output from MATLAB using the default double-precision floating-point values is small.


A_lambda = double([regularizationParameter*eye(n);A]);
B_0 = [zeros(n,p);double(B)];
X_double = A_lambda\B_0;
relativeError = norm(X_double - double(X))/norm(X_double)
relativeError = 1.1330e-05

Suppress mlint warnings in this file.


See Also

| |