How can I convert these matlab code to Python

2 次查看(过去 30 天)
clear
alpha = 0.05;
W = 3.5;
number_tab = 11;
data_length = 500;
noise_variance = 0.001;
k=1:3;
channel_coeff = 0.5*(1+cos(2*pi/W.*(k-2)));
channel_coeff = [0, channel_coeff, 0];
rand('state',0);
input_data = sign(rand([1,data_length])-0.5);
desired_response = input_data;
received_seq = conv(input_data,channel_coeff);
received_seq = received_seq + noise_variance*randn(1,data_length+4);
start_zero = zeros(1,3);
received_seq = [start_zero received_seq];
equalizer_coeff = zeros(number_tab,1);
for i = 1:data_length-number_tab
predicted_data = received_seq(i:i+number_tab-1)*equalizer_coeff;
error = desired_response(i) - predicted_data;
equalizer_coeff = equalizer_coeff + (alpha*error*received_seq(i:i+number_tab-1)');
end
figure
stem(equalizer_coeff);

回答(1 个)

Shivam Singh
Shivam Singh 2022-4-4
Hello Pathorn,
It is my understanding that you want to convert your MATLAB code into Python code.
There is no direct tool available for such conversion. However, as of MATLAB 8.4 (R2014b) you can call MATLAB directly from Python using the MATLAB Engine for Python. You may use the following link for reference:
Another way is to use MATLAB Compiler + MATLAB Compiler SDK to let you build Python packages out of MATLAB code. Applications created using software components from MATLAB Compiler SDK can be shared royalty-free with users who do not need MATLAB. These applications use the MATLAB Runtime, a set of shared libraries that enables the execution of compiled MATLAB applications or components. Please refer to the links below for more detailed information on the implementation:

类别

Help CenterFile Exchange 中查找有关 Python Package Integration 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by