Hi,
I am trying to convert a code written in Matlab scripting box to a Python.
in MATLAB there are Initialize and uninitialize.m files, specially the Initialize part where it defines the variables, however in the python tutorial(signal average.py) it says no need of initialize/uninitilaze and there are no examples for those. So do I define the variables just in the process file it self?
As in if I'm converting 3 files of MATLAB scripting box(initialize, process, uninitialize), Should I put them all in one process file when it comes to python box?
Thanks
DJ
Below is the code that I'm trying to convert:
tuto2_FFT_filter_Process.m
% -------------------------------
% Author : Laurent Bonnet (INRIA)
% Date : 25 May 2012
%
function box_out = tuto2_FFT_filter_Process_CurMax(box_in)
for i = 1: OV_getNbPendingInputChunk(box_in,1)
if(~box_in.user_data.is_headerset)
% The output is the input + noise, only on first channel
% The output is the input + noise, only on first channel
box_in.outputs{1}.header = box_in.inputs{1}.header;
box_in.outputs{1}.header.nb_channels = 1;
box_in.outputs{1}.header.channel_names = {'FFT'};
box_in.user_data.is_headerset = 1;
% We print the header in the console
disp('Input header is :')
box_in.inputs{1}.header
disp('Output header is :')
box_in.outputs{1}.header
end
% we increment the matrix count
box_in.user_data.nb_matrix_processed = box_in.user_data.nb_matrix_processed + 1;
[box_in, start_time, end_time, matrix_data] = OV_popInputBuffer(box_in,1);
%%%% PLAY HERE %%%%
DecRatio = 0.97;
MaxDat_Ocipt = max(matrix_data(1:4));
MaxDat_Front = max(matrix_data(5:8));
MaxDat_All = max(matrix_data);
Sum_b = sum(sum(matrix_data));
box_in.user_data.CurMax = DecRatio*box_in.user_data.CurMax;
if MaxDat_All > box_in.user_data.CurMax
box_in.user_data.CurMax = MaxDat_All;
end
Power = matrix_data./box_in.user_data.CurMax;
Power = max(Power);
box_in.user_data.CM_1 = DecRatio*box_in.user_data.CM_1;
if MaxDat_Ocipt > box_in.user_data.CM_1
box_in.user_data.CM_1 = MaxDat_Ocipt;
end
Power_OC = matrix_data(1:4)./box_in.user_data.CM_1;
Power_OC = max(Power_OC);
box_in.user_data.CM_2 = DecRatio*box_in.user_data.CM_2;
if MaxDat_Front > box_in.user_data.CM_2
box_in.user_data.CM_2 = MaxDat_Front;
end
Power_FR = matrix_data(5:8)./box_in.user_data.CM_2;
Power_FR = max(Power_FR);
box_in.user_data.CM_3 = DecRatio*box_in.user_data.CM_3;
if Sum_b > box_in.user_data.CM_3
box_in.user_data.CM_3 = Sum_b;
end
SUM_b = sum(sum(matrix_data))./box_in.user_data.CM_3;
SUM_b = max(SUM_b);
Cur_Val = [Power,MaxDat_Ocipt,MaxDat_Front,MaxDat_All,box_in.user_data.CurMax,SUM_b,Power_OC,Power_FR];
box_in = OV_addOutputBuffer(box_in,1,start_time,end_time,Cur_Val);
end
box_out = box_in;
end
Matlab to Python scripting box convert
-
- Posts: 775
- Joined: Tue Dec 04, 2012 3:53 pm
- Location: INRIA Rennes, FRANCE
Re: Matlab to Python scripting box convert
Hello Deejay, it definitely should be possible to initialize() and uninitialize() in Python! See here,
http://openvibe.inria.fr/tutorial-using ... -openvibe/
Happy hacking,
Jussi
http://openvibe.inria.fr/tutorial-using ... -openvibe/
Happy hacking,
Jussi
Re: Matlab to Python scripting box convert
Hi,
indeed, you do not need initialize/uninitialize files in python.
However, the python scripting box still requires you to do something similar; classes created to be used with python box requires you to define an initialize/uninitialize function.
You can see examples of that in python's box tutorials.
Hope that helps,
indeed, you do not need initialize/uninitialize files in python.
However, the python scripting box still requires you to do something similar; classes created to be used with python box requires you to define an initialize/uninitialize function.
You can see examples of that in python's box tutorials.
Hope that helps,
Re: Matlab to Python scripting box convert
Thanks so much for the responses, Jussi, I read that many times and couldn't find any, that's when I come to forum haha.
Thanks, I see, I've been trying to use the signal average.py example, and I guess defining part at the top acts as the initialize, and so on.tgaugry wrote:gaugry