# How to convert matlab code to python?

6 views (last 30 days)
AN JAEJU on 16 Sep 2021
Answered: Kiran Felix Robert on 21 Sep 2021
I wanna convert this code to python, but i fail to do it as I am very new to Matlab.
Is there anyway to do it in automatic way?
------------------------------------------------
function ST=stran(h)
% Compute S-Transform without for loops
%%% Coded by Kalyan S. Dash %%%
%%% IIT Bhubaneswar, India %%%
[~,N]=size(h); % h is a 1xN one-dimensional series
nhaf=fix(N/2);
odvn=1;
if nhaf*2==N;
odvn=0;
end
f=[0:nhaf -nhaf+1-odvn:-1]/N;
Hft=fft(h);
%Compute all frequency domain Gaussians as one matrix
invfk=[1./f(2:nhaf+1)]';
W=2*pi*repmat(f,nhaf,1).*repmat(invfk,1,N);
G=exp((-W.^2)/2); %Gaussian in freq domain
% End of frequency domain Gaussian computation
% Compute Toeplitz matrix with the shifted fft(h)
HW=toeplitz(Hft(1:nhaf+1)',Hft);
% Exclude the first row, corresponding to zero frequency
HW=[HW(2:nhaf+1,:)];
% Compute Stockwell Transform
ST=ifft(HW.*G,[],2); %Compute voice
st0=mean(h)*ones(1,N);
ST=[st0;ST];
end

Kiran Felix Robert on 21 Sep 2021
Hi AN JAEJU,
Have a look at the Python Package Integration to package MATLAB code to a Python Application.