フィルターのクリア

HDL Coder Error: HDL code generation does not support variable-size matrix type.

5 ビュー (過去 30 日間)
SHUHENG
SHUHENG 2024 年 4 月 22 日
コメント済み: SHUHENG 2024 年 4 月 24 日
need help please!
I tried to use HDL CODER to convert my matlab code into verilog code,but failed in Workflow Advisor-HDL Code Generation.
This is partial code which shows error:
(H is a 16x16 complex matrix.)
SNR = [0:1:20];
ea=1;
es=ea*16;
sigma_n2 = es/snr;
snr = 10.^(SNR(1)/10);
complex_scalar = complex(sigma_n2/ea);
complex_eye = complex(eye(16));
temp = H*H' + complex_scalar*complex_eye;
temp2=H*H';
value = complex(zeros(16,16)); % 初始化为复数矩阵
tol = 1e-15;
MatrixB = complex(eye(16)); % 使用complex函数确保MatrixB是复数
Y = value;
array1 = complex(1:16);
for i=1:15
b=i;
% temp5=temp(b:16,b);
% temp4=real(temp5).^2 + imag(temp5).^2;
% abs_temp = sqrt(temp4);
temp_slice(1:16-b+1) = temp(b:16,b); % 获取切片
temp5(1:16-b+1,1) = temp_slice(1:16-b+1);
temp4(1:16-b+1,1) = real(temp_slice(1:16-b+1)).^2 + imag(temp_slice(1:16-b+1)).^2;
abs_temp(1:16-b+1,1) = sqrt(temp4(1:16-b+1,1));
[~, j] = max(abs_temp);
num1 = temp(i,:);
result=real(i);
temp(i,:) = temp(result,:);
temp(i,:) = num1;
% num1(1,i) = array1(1,i);
% array1(i) = array1(i);
% array1(1,i) = num1(1,i);
for j=i+1:16
%%%%%%%%%
% num1 = temp(j,i)/temp(i,i);
%%%%%%%%%
% coder.varsize('num1');
conj_temp=conj(temp(i,i));
numerator = temp(j,i)*conj_temp;
denominator =temp(i,i)*conj_temp;
result_real = real(numerator) / real(denominator);
result_imag = imag(numerator) / real(denominator);
temp6=0;
temp6=complex(temp6);
temp6=complex(result_real, result_imag);
%%%%%%%%%
temp(j,i) = temp6;
temp(j,i+1:16) = temp(j,i+1:16) - temp6*temp(i,i+1:16); //THIS shows errors
end
end
for i=1:16
Y(1,i) = MatrixB(array1(1),i);
for j=2:16
Y(j,i) = MatrixB(array1(j),i) - temp(j,1:j-1)*Y(1:j-1,i); //AND THIS ONE
end
%%%%%%%%%
% value(N,i) = Y(N,i)/temp(N,N);
%%%%%%%%%
conj_fenmu=conj(temp(16,16));
numerator=Y(16,i)*conj_fenmu;
denominator=temp(16,16)*conj_fenmu;
result_real = real(numerator) / real(denominator);
result_imag = imag(numerator) / real(denominator);
value(16,i)=complex(result_real, result_imag);
%%%%%%%%%
for j=16-1:-1:1
%%%%%%%%%
% value(j,i) = (Y(j,i) - temp(j,j+1:N)*value(j+1:N,i))/tempj,j);
%%%%%%%%%
fenzi=Y(j,i) - temp(j,j+1:16)*value(j+1:16,i);
conj_fenmu=conj(temp(j,j));
numerator =fenzi*conj_fenmu;
denominator =temp(j,j)*conj_fenmu;
result_real = real(numerator) / real(denominator);
result_imag = imag(numerator) / real(denominator);
value(j,i)=complex(result_real, result_imag);
end
end
The purpose of this code is to find the inverse matrix.Because inv() cant used in HDL CODER to calucate a complex matrix,so I have to do it by myself.I run it in HDL CODER,and in Workflow Advisor-HDL Code Generation,it shows several errors.
I dont know where these a0,b0,br,y,pre,pi matrix come from,i dont even define and use them.All of the matrices that I use have already been defined in terms of size.I have no idea why it shows error.Could someone help me please:(
I have uploaded my entire code

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 4 月 24 日
temp_slice(1:16-b+1) = temp(b:16,b); %

You do not declare temp_slice before use, so you are growing it within a loop, which requires dynamic memory allocation

  1 件のコメント
SHUHENG
SHUHENG 2024 年 4 月 24 日
I declare it in the full code
temp_slice = complex(zeros(16,1));
and i used disp(size(temp_slice)) to show the size of it in loops,every loop it shows 16×1.

サインインしてコメントする。

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by