source: orbit/arduino/puzzlebox_orbit_A_HMRMFM/processLogicdata.m @ 7e55322

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 7e55322 was 7e55322, checked in by AzureViolin <zhanghaotz@…>, 10 years ago

successfully regenerated IR code, with octave program help analysing raw data

  • Property mode set to 100644
File size: 2.1 KB
Line 
1function processLogicdata (csvLogicdataFileName, innerCodeName, outerCodeName, rawOuterCodeName)
2%process one data at a time
3
4% Decode IR remote signal data collected by Salease or compatible logic
5% analyser, read .csv file and process with Octave.
6% by:AzureViolin azureviolin.com
7
8
9data=load(csvLogicdataFileName); %need to delete file header manually
10
11sizedata=size(data);
12%calculate the time period between two data points.
13X=data(2:end,1);
14X1=data(1:sizedata-1,1);
15DIFF=X-X1;%the time periods
16
17Y_outer=DIFF>1e-2;%logic array of outer IR code
18Index_outer=find(Y_outer);%index of outer IR code
19Z_outer=DIFF(Index_outer);%time period of outer IR code
20
21DIFF_inner=DIFF(Index_outer(2):Index_outer(3));% get the 2nd segment of difference of inner codes
22X_inner=X1(Index_outer(2):Index_outer(3)+1);% get the 2nd segment of inner codes
23Y_inner=(DIFF_inner>1e-4)&(DIFF_inner<1e-2);% filter, get index
24Z_inner=DIFF_inner(find(Y_inner));%time period of inner codes
25
26%last digit in INNER
27INNER_last_digit=X_inner(Index_outer(3)-Index_outer(2)+1)-X_inner(find(Y_inner)(end)+1);%get inner code HIGH
28%if inner code HIGH  is 7.1542e-4, then its LOW lasts for  7.591e-4
29if INNER_last_digit-7.1542e-4<1e-5
30        Z_inner=[Z_inner;7.591e-4];
31endif
32%gets minimum repeat segment from raw output
33raw_outer=(floor(Z_outer*1e2)(2:end));
34slength=1;
35notFound=1;
36
37while(notFound)
38        notFound=0;
39        for j=1:(floor(length(raw_outer)/slength)-1)
40                for i = 1 : slength
41                        if raw_outer(i)!=raw_outer(j*slength+i)
42                                %fprintf('first segment =');
43                                %raw_outer(i:slength)'
44                                %fprintf('/n %d th segment =',j);
45                                %raw_outer(j*slength+1:j*slength+slength)'
46                                notFound=1;
47                                break;
48                        endif
49                endfor
50        endfor
51        %fprintf('/n not found while segment length = %d \n', slength);
52        slength=slength+1;
53endwhile
54
55slength=slength-1;%get rid of the one unwanted digit
56
57%fprintf('found when segment length = %d \n minimum segment is \n', slength);
58%output
59INNER=floor(Z_inner*1e4)';
60OUTER=raw_outer(1:slength)';
61RAW_OUTER_T=raw_outer';
62%write file
63save (outerCodeName,'OUTER');
64save (innerCodeName,'INNER');
65save (rawOuterCodeName,'RAW_OUTER_T');
66endfunction;
Note: See TracBrowser for help on using the repository browser.