How can I convert these matlab code to Python

17 views (last 30 days)
Pathorn Kitisupavatana
Pathorn Kitisupavatana on 31 Mar 2022
Answered: Shivam Singh on 4 Apr 2022
alpha = 0.05;
W = 3.5;
number_tab = 11;
data_length = 500;
noise_variance = 0.001;
channel_coeff = 0.5*(1+cos(2*pi/W.*(k-2)));
channel_coeff = [0, channel_coeff, 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)');

Answers (1)

Shivam Singh
Shivam Singh on 4 Apr 2022
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:




Community Treasure Hunt

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

Start Hunting!

Translated by