---
# System prepended metadata

title: Untitled

---

## FluxMed User Manual

To start off, please use the link provided below to watch a short video about the FluxMed process of data recording and data extraction. 

FluXMed comes with two software extensions. One is called FluxMed View and another one is FluxMed Review. Why they come as a sepaarte package is beyond my understanding of rationality so bear with me as I take you throught this process step-by-step :) 
### Step 0: set-up the equipment 
> The set-up consists of FluxMed flowmeter unit, flow sensor, and computer with FluxMed View and FluxMed Review extensions. The oxygen tank is used to simulate air flow through the FluxMed flow sensor. Please take a look at this short video I made to show the overview of the set-up and process: https://drive.google.com/file/d/1tt0QGbP7T1yw5L1x9P1raoAYv-MaVhuT/view?usp=sharing

![](https://i.imgur.com/MxxicV8.jpg)

![](https://i.imgur.com/Y9ByxPI.jpg)


### Step 1: Starting data collection
> Starting the FluxMed View window to record the flow/pressure and other parameters of interest.  

![FluxMed View](https://i.imgur.com/0H5Z7xM.jpg)

> Data recording example as seen during our test experiement. 

![Data recording example](https://i.imgur.com/685uXAs.jpg)

### Step 2: Saving files

> At the end of the experiement/test you can save your files as .flux format only. That is perhaps the biggest limitation because in order to read or convert .flux files to .txt you need to open them in the FluxReview extension. Yeah, its fun :)

### Step 3: FluxReview: opening and reading .flux files

> So when you get to your FluxReview application you can load up the .flux file and then save it in a differebnt format. Generally, it is a .txt file. 

![.flux files](https://i.imgur.com/3HKxqr2.jpg)

![FluxMed Review](https://i.imgur.com/tdNNnE0.jpg)

### Step 4: Exporting .txt files 
> There are two options for file export. You can export Parameters and Signals. Paramters folder will have the notations of all recorded paaremeters (and is quite redundant for analysis). Signals will have all your recorded data a bunch of things that were not recorded and are unnecessary for analysis. 

![Flux Review exporting files to .txt](https://i.imgur.com/TwOAwos.jpg)

![Exported files signal/parameters](https://i.imgur.com/SzwNTKm.jpg)

### Step 5: Review of Parameters and Signals .txt files 

> Example Parameters file in .txt format. 

![Parameters.txt](https://i.imgur.com/QyKOgtQ.jpg)

> Example Signals file in .txt format

![Signal.txt](https://i.imgur.com/PpupfPs.jpg)

### Step 5: Excell file .txt upload 

> After eporting your ,txt files you can now proceed to Excell and load your .txt data file to a more manageable format. Generally speaking, the first few rows of each signals.txt file are irrelevant as we need to see only the name of the signal (i.e. Flow l/min, Pav) and the coresponding values. 

Thoughts: I think in an idea world having you rdata saved as a .csv file as an output from the FluxView application would be most helpful. Bypassing the need to open .flux and converting it to .txt to then convert it to .csv or .xls takes a lot of time and effort. Anythign that can be done to bypass these steps would be of huge benefit to society! 
Thank you! 


NOTES: Try export with marked data to see if we can break down the recording session with markers. 

Get Alan older FluxMed model and CD to download the program FluxMed View and Review. 

## .flux File Conversion
The following code was developed in an effort to streamline the .flux to .csv file conversion process, allowing for multiple files to be converted at once without opening them individually in FluxReview.

Initially we didn't have access to FluxMed's .flux file data loading software, so the script was first developed as a [.txt to .csv/.xlsx file converter](https://github.com/alanzalewski/txt-file-converter), using python. After FluxMed gave us access to that software (in the form of a Matlab library) it was possible to develop a .flux to .csv conversion script capable of processing multiple files at once. This was first coded in Matlab and then in Octave. Though Octave is a free alternative to Matlab and is therefore very similar, the two are not identical, and certain modifications had to be made. These include:
* using the fprintf() and csvwrite() functions to write data to the output file instead of the writematrix() function
* avoiding instances of the string() function as this is not yet implemented in Octave.

### Usage
The steps below detail how to use the Octave version of the conversion software.

#### Step 0: Get Octave
> Octave can be downloaded for free [here](https://www.gnu.org/software/octave/download). 

#### Step 1: Get the required files
> The conversion code can be found on [Github](https://github.com/alanzalewski/flux-file-converter), specifically the file titled fluxconvert.m. (You can also find the earlier matlab version there under matlab-fluxconvert.m, though I don't recommend using going through the trouble of Matlab just to use it.)

> The FluxMed conversion software can be downloaded [here](https://universityhealthnetwork-my.sharepoint.com/:f:/g/personal/alan_zalewski_uhnresearch_ca/EkeUTc27VAhNnTyAHv5tsG0Bks03EcpDPxoVC4OR_umgBw?e=aiyUFZ). Make sure to keep the fluxconverter.m file in the same folder as the FluxMed conversion software (i.e. Matlab Library).

#### Step 2: Running the conversion software
> Open the fluxconverter file in Octave and run it. Alternatively, a console command like
```
octave fluxconvert.m
```
> should work too. It isn't necessary to specify the desired files in the command line as the program uses manual selection, which includes selecting multiple files at once. 
> 
> A window will pop up allowing you to browse through your computer and select the .flux file(s) you'd like to convert. (Note that it may take several minutes to convert them all, depending on the number of files selected and the amount of data within them.)


### How fluxconvert.m works
Below is a step-by-step description of how the conversion occurs, though there is a gap in knowledge given I didn't develop the FluxMed .flux file data loading software myself.

> First the code below opens a file selection window that extracts the name and path from the file(s) selected by the user. Multiselect is on so multiple files can be selected if desired, but the user is limited to files with a .flux extension
``` 
[file,path] = uigetfile('*.flux','MultiSelect','on');
```
> Then the amount of files is stored in a variable called amnt. If more than one file has been selected, Octave stores the file names in a cell array, whose length corresponds to the amount of files selected. If only one file has been selected, however, Octave stores the name as a char, which means that if the class of the file variable is a char, the amount of files is equal to 1.
```
if class(file) == 'char'
    amnt = 1;
else
    amnt = length(file);
endif
```
> The program then uses amnt in a for loop to iterate through each selected file. Several tasks are performed within this loop:

>First the file extension of each file is changed from .flux to .csv, while keeping the same file name, and loadFluxFileSignal is called from the FluxMed file conversion software to load all the data from the file into a struct called data.
```
for m=1:amnt
    if class(file) == 'char'
        csvfile = strcat(file(1:end-5),".csv");
        file = strcat(path,file);
        data = loadFluxFileSignal(file,1);
    else
        csvfile = strcat(file{m}(1:end-5),".csv");
        file{m} = strcat(path,file{m});
        data = loadFluxFileSignal(file{m},1);
    endif
```
> Second, the data from the file is separated into each recorded variable (i.e. time, flow (F), airway pressure (Paw), etc) and reshaped by transposing each variable into columns. The amount of data points is stored in a variable called len.
```
    F = transpose(data.F);
    V = transpose(data.V);
    Paw = transpose(data.Paw);
    Pes = transpose(data.Pes);
    Pgas = transpose(data.Pgas);
    CO2 = transpose(data.CO2);
    Time = transpose(data.Time);
    Ptpulm = transpose(data.Ptpulm);
    Ptdiaf = transpose(data.Ptdiaf);
    V2 = transpose(data.V2);
    
    len = length(F);
```
> A csv file is then opened and the header is formatted to match a typical .flux signals file after it has been converted to .txt format.
```
    fid = fopen(csvfile, "w");
    
    fprintf(fid,'%s\n',"FluxView - FluxMed acquisition system")
    fprintf(fid,'%s\n',"Signal file")
    fprintf(fid,'%s, %f\n',"Serial Number:", data.header.serialNumber)
    fprintf(fid,'%s, %f, %s, %f\n',"SW version:", data.header.softwareVersion, "File version:", data.header.fileVersion)
    fprintf(fid,'%s, %s\n',"Sampling rate:", "256 Hz")
    fprintf(fid,'%s, %s, %s, %s, %s, %s, %s, %s, %s\n',"Time", "Flow", "Volume", "Paw", "Pes", "Ptpulm", "Pga", "Ptdiaf", "CO2")
    fprintf(fid,'%s, %s, %s, %s, %s, %s, %s, %s, %s\n',"Sec", "l/min", "ml", "cmH2O", "cmH2O", "cmH2O", "cmH2O", "cmH2O", "mmHg")
```
> Then another for loop runs through the extracted data and appends it to the csv file line by line. Finally, the csv file is closed and the main for loop is ended.
```
    for n=1:len
        % appending the data row by row
        csvwrite(fid,[Time(n),F(n),V2(n),Paw(n),Pes(n),Ptpulm(n),Pgas(n),Ptdiaf(n),CO2(n)],'-append');  
    endfor
    
    fclose(fid);
endfor
```