OpenViBE forum

The OpenViBE community
It is currently Fri Dec 15, 2017 9:25 pm

All times are UTC

Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Apr 06, 2017 5:02 pm 

Joined: Thu Mar 09, 2017 9:38 pm
Posts: 6

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 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?


Below is the code that I'm trying to convert:

% -------------------------------
% 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)
% 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 :')
disp('Output header is :')

% 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;
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;
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;
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;
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);
box_out = box_in;

Reply with quote  
PostPosted: Mon Apr 10, 2017 7:28 am 

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 601
Location: INRIA Rennes, FRANCE
Hello Deejay, it definitely should be possible to initialize() and uninitialize() in Python! See here, ... -openvibe/

Happy hacking,

Reply with quote  
PostPosted: Mon Apr 10, 2017 7:34 am 

Joined: Thu Feb 09, 2017 10:17 am
Posts: 65

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,

Reply with quote  
PostPosted: Tue May 02, 2017 9:14 pm 

Joined: Thu Mar 09, 2017 9:38 pm
Posts: 6
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.

tgaugry wrote:
Thanks, I see, I've been trying to use the signal example, and I guess defining part at the top acts as the initialize, and so on.

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Americanized by Maƫl Soucaze.