Changeset cb3655b in orbit
- Timestamp:
- 12/04/12 19:47:09 (9 years ago)
- Branches:
- master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
- Children:
- f323fb4
- Parents:
- dccf843
- Location:
- octave/GenerateAudioCommand
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
octave/GenerateAudioCommand/bitGenDirect.m
ra0b523e rcb3655b 4 4 % num: how many certain bit to generate. 5 5 % audioFileName: like 'audio.wav'. 6 6 % last four parameter: pass period of sine wave here. 7 7 longHIGH=875; 8 8 longLOW=729; -
octave/GenerateAudioCommand/flyCommand.m
r655a816 rcb3655b 7 7 %sps = 96000; % sample rate [samples/s] 8 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. 9 10 if length(code)==5 10 11 if code=='demo1' 11 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 rotating throttle12 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 12 13 elseif code=='demo2' 13 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 … … 50 51 elseif length(AndroidOriOS)==7 %'Android' 51 52 53 % number with _s suffix is in samples. Optimized with 44100 sampling rate. 52 54 longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-3;%longHIGH[us] longHIGH_s[sample] 53 55 longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3)+1; … … 55 57 shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1+2; 56 58 57 58 59 shortLOW_ss=floor(shortLOW*sps/1e6)+2; 59 60 61 62 % PAY ATTENTION to the special starting and ending code of command. 60 63 codeWave=[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 61 64 62 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" 63 67 for i=1:size(code,2) 64 68 codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s, longLOW_s,shortHIGH_s,shortLOW_s)]; 65 69 66 70 endfor 71 67 72 68 73 codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period -
octave/GenerateAudioCommand/flyOrbit.m
rf22b7ab rcb3655b 3 3 % code: array of 1s and 0s. 1 means bit "1", 0 means bit "0". 4 4 % audioFileName: like 'audio.wav'. 5 % space: space between codes [u s]5 % space: space between codes [uS] 6 6 bps = 16; % bits per sample 7 7 %sps = 96000; % sample rate [samples/s] 8 9 space=floor(space*48000/1e6); 8 %repeatTime: the number of same commands you want to generate 9 %AndroidOriOS: 'Android' 'iOS' generates two different style of codes 10 %flipOrNot: 'flip' 'notF' some android device needs a flipped signal. 11 space=floor(space*48000/1e6);% turn uS into samples 10 12 11 13 if length(AndroidOriOS)==3 %iOS … … 14 16 elseif length(AndroidOriOS)==7 %Android 15 17 16 if AndroidOriOS=='Android' 17 fullCodeWave=[flyCommand(code,space,'temp1,wav',sps,4,AndroidOriOS,flipOrNot);initCodeGenAndroid('temp2.wav',sps);zeros(1,1);flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 18 elseif AndroidOriOS=='Command' 18 if AndroidOriOS=='Android'%generate android style command with init 19 20 %Android style command consists of 4(any number larger than 2) command, init code, and certain repeat of command. 21 %function initCodeGenAndroid can generate init 22 %function flyCommand can generate command 23 fullCodeWave=[flyCommand(code,space,'temp1.wav',sps,4,AndroidOriOS,flipOrNot);initCodeGenAndroid('temp2.wav',sps);zeros(1,1);flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 24 elseif AndroidOriOS=='Command'%generate command only 19 25 fullCodeWave=[flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 20 26 endif -
octave/GenerateAudioCommand/halfSineGenDirect.m
ra0b523e rcb3655b 2 2 3 3 % dir: 'u' means UP, 'd' means down. 4 % halfPeriod: half period of cosine signal[us].4 % halfPeriod: half period of sine signal[us]. 5 5 % zero: zero level of cosine signal. 6 6 % amp: amplitude of cosine signal, in percentage. … … 13 13 freq = floor(sps/(halfPeriod_in_samples*2)); % frequency of the tone [Hz] 14 14 15 15 %linspace is an octave function that generates a sequence with certain step. 16 16 time = linspace(1/sps, halfPeriod, halfPeriod_in_samples); 17 17 if (dir== 'u') 18 wave = sin(time*2*pi*freq)'.*amp+zero; 18 wave = sin(time*2*pi*freq)'.*amp+zero;%'u' indicates above zero line 19 19 elseif (dir=='d') 20 wave = sin((time+halfPeriod)*2*pi*freq)'.*amp+zero; 20 wave = sin((time+halfPeriod)*2*pi*freq)'.*amp+zero;%'d' indicates below zero line 21 21 endif 22 22 -
octave/GenerateAudioCommand/initCodeGenAndroid.m
rf22b7ab rcb3655b 6 6 bps = 16; % bits per sample 7 7 8 9 %all numbers start with '_' is measured in uS with audacity. 8 10 _longHIGH=1000; %[us] 9 11 _longLOW=2000; … … 14 16 _space=84354; 15 17 18 %turn everything into samples based on sps. Modifyer is optimized when sps=44100Hz 16 19 longHIGH=floor(_longHIGH*sps/1e6)-1; 17 20 longLOW=floor(_longLOW*sps/1e6)+1; … … 22 25 space=floor(_space*sps/1e6); 23 26 27 %initWave stores the init code we will finnaly generate 28 %function halfSineGenDirect can generate the upper or lower half of a sine wave based on how many samples are included in a "half-period" sine wave. 24 29 initWave=[halfSineGenDirect('u',longHIGH,0,1,sps);zeros(longLOW,1);halfSineGenDirect('u',longHIGH,0,1,sps);zeros(longLOW,1);halfSineGenDirect('u',longHIGH,0,1,sps);halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u',shortHIGH,0,1,sps)]; 25 30 26 initWave2=[initWave;halfSineGenDirect('d',shortLOW,0,1,sps)]; 27 initWave=[initWave;halfSineGenDirect('d',mediumLOW,0,1,sps)]; 31 initWave2=[initWave;halfSineGenDirect('d',shortLOW,0,1,sps)];%inits 4,5,6 32 initWave=[initWave;halfSineGenDirect('d',mediumLOW,0,1,sps)];%inits 1,2,3 28 33 29 34
Note: See TracChangeset
for help on using the changeset viewer.