source: orbit/octave/GenerateAudioCommand/flyCommand.m @ cb3655b

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

add comment to script

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[3322dad]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
[cb3655b]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.
[655a816]10if length(code)==5
[3322dad]11if code=='demo1'
[cb3655b]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
[3322dad]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
[a0b523e]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
[655a816]22endif
23
[a0b523e]24if (length(AndroidOriOS)==3)%'iOS'
[3322dad]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
[a0b523e]51elseif length(AndroidOriOS)==7 %'Android'
52
[cb3655b]53% number with _s suffix is in samples. Optimized with 44100 sampling rate.
[655a816]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;
[a0b523e]60
[cb3655b]61
62% PAY ATTENTION to the special starting and ending code of command.
[655a816]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
[a0b523e]64
65% notice that the "code" here should be a 28 bit binary array.
[cb3655b]66% function bitGenDirect will generate a complete digit in the form of sine wave of either "0" or "1"
[a0b523e]67for i=1:size(code,2)
68codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s,   longLOW_s,shortHIGH_s,shortLOW_s)];
69       
70endfor
71
[cb3655b]72
[a0b523e]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
[3322dad]85endif %if AndroidOriOS=='iOS'
86
87wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.