source: orbit/octave/GenerateAudioCommand/flyCommand.m @ 33cfd5c

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 33cfd5c was cb3655b, checked in by dorabot <dorabot@…>, 7 years ago

add comment to script

  • Property mode set to 100644
File size: 3.1 KB
Line 
1function fullCodeWave=flyCommand(code,space,audioFileName,sps,repeatTime,AndroidOriOS,flipOrNot)
2
3% code: array of 1s and 0s. 1 means bit "1", 0 means bit "0".
4% audioFileName: like 'audio.wav'.
5% space: space between codes [samples]
6bps = 16;       % bits per sample
7%sps = 96000;     % sample rate [samples/s]
8
9% 4 demo codes here for testing. you can either put a matrix as the first parameter, or just use 'demo1' ~ 'demo4' for testing purpose.
10if length(code)==5
11if code=='demo1'
12        code=[1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0];%minimum  throttle to make propeller rotating
13elseif code=='demo2'
14        code=[1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0];%maximum throttle
15
16elseif code=='demo3'
17        code=[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 0];%minimum throttle
18elseif code=='demo4'
19        code=[1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 ];%test for Untitled 04
20        endif
21
22endif
23
24if (length(AndroidOriOS)==3)%'iOS'
25longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample]
26longLOW=729;longLOW_s=floor(longLOW*sps/1e6);
27shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)+1;
28shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6);
29
30codeWave=[halfSineGenDirect('u',longHIGH_s,0,1,sps);zeros(shortLOW_s,1);halfSineGenDirect('u',longHIGH_s,0,1,sps);zeros(shortLOW_s,1)]; %starting 5 half period
31
32% notice that the "code" here should be a 28 bit binary array.
33for i=1:size(code,2)
34        codeWave = [codeWave; bitGenHDMI(code(i),1,sps,longHIGH_s,longLOW_s,shortHIGH_s,shortLOW_s)];
35endfor
36
37codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period
38
39if(flipOrNot=='flip')
40        codeWave=-codeWave;
41endif
42
43fullCodeWave=[];
44for i=1:repeatTime
45        fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)];
46endfor
47
48
49%fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))];
50
51elseif length(AndroidOriOS)==7 %'Android'
52
53% number with _s suffix is in samples. Optimized with 44100 sampling rate.
54longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-3;%longHIGH[us]  longHIGH_s[sample]
55longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3)+1;
56shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-3;
57shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1+2;
58
59shortLOW_ss=floor(shortLOW*sps/1e6)+2;
60
61
62% PAY ATTENTION to the special starting and ending code of command.
63codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps);    halfSineGenDirect('d',shortLOW_ss+2,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_ss+3,0,1,sps)]; %starting 5 half period
64
65% notice that the "code" here should be a 28 bit binary array.
66% function bitGenDirect will generate a complete digit in the form of sine wave of either "0" or "1"
67for i=1:size(code,2)
68codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s,   longLOW_s,shortHIGH_s,shortLOW_s)];
69       
70endfor
71
72
73codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)];  %last half period
74
75if(flipOrNot=='flip')
76    codeWave=-codeWave;
77endif
78
79fullCodeWave=[];
80for i=1:repeatTime
81            fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)];
82endfor
83
84
85endif %if AndroidOriOS=='iOS'
86
87wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.