Changeset a0b523e in orbit for octave/GenerateAudioCommand
- Timestamp:
- 11/29/12 08:17:10 (8 years ago)
- Branches:
- master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
- Children:
- 0401409, 655a816
- Parents:
- 3322dad
- Location:
- octave/GenerateAudioCommand
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
octave/GenerateAudioCommand/codeAudioGen.m
r6aa182f ra0b523e 5 5 6 6 bps = 16; % bits per sample 7 sps = 960000; % sample rate [samples/s]7 sps = 480000; % sample rate [samples/s] 8 8 9 9 codeWave=[]; 10 10 11 11 for i=1:size(code,2) 12 codeWave = [codeWave; bitGen(code(i),1 )];12 codeWave = [codeWave; bitGen(code(i),1,sps)]; 13 13 endfor 14 14 15 %special wave form for carrier16 carrierWave=[halfPeriodGen('u',30,-0.353,0.723);17 halfPeriodGen('d',22,-0.015,0.384);18 halfPeriodGen('u',31,0.261,0.661);19 halfPeriodGen('d',28,0.392,0.530);20 halfPeriodGen('u',25,0.246,0.384);21 halfPeriodGen('d',32,-0.092,0.723);22 halfPeriodGen('u',25,-0.430,0.384);23 halfPeriodGen('d',26,-0.515,0.469)];24 codeWave=[codeWave codeWave].*0.5;25 26 sizeCW=size(carrierWave,1);27 cWaveRepeat=[];28 n=floor(size(codeWave,1)/sizeCW);29 for i=1:n30 cWaveRepeat=[cWaveRepeat; carrierWave];31 endfor32 33 codeWave(1:n*sizeCW,2)+=cWaveRepeat;34 15 wavwrite(codeWave, sps, bps, audioFileName); 35 16 -
octave/GenerateAudioCommand/dualIRLEDAudioGen.m
r0edc9d8 ra0b523e 6 6 bps = 16; % bits per sample 7 7 %sps = 96000; % sample rate [samples/s] 8 shortT=floor(0.0008*sps/2); 9 longT=floor(0.0016*sps/2); 10 codeWave=[ones(longT,1);zeros(shortT,1);ones(longT,1);zeros(shortT,1)]; 8 9 10 shortLOW=floor(0.0008*sps/2)+1; 11 shortHIGH=floor(0.0008*sps/2)-1; 12 longHIGH=floor(0.0016*sps/2)-1; 13 longLOW=floor(0.0016*sps/2)+2; 14 codeWave=[ones(longHIGH,1);zeros(shortLOW,1);ones(longHIGH,1);zeros(shortLOW,1)]; 11 15 12 16 % notice that the "code" here should be a 28 bit binary array. 13 17 for i=1:size(code,2) 14 codeWave = [codeWave; dualBitGen (code(i),1,sps)];18 codeWave = [codeWave; dualBitGenDirect(code(i),shortHIGH,shortLOW,longHIGH,longLOW)]; 15 19 endfor 16 20 17 codeWave=[codeWave; ones(long T,1)]; %last half period21 codeWave=[codeWave; ones(longHIGH,1)]; %last half period 18 22 19 23 … … 24 28 fullCodeWave=[]; 25 29 for i=1:repeatTime 26 fullCodeWave=[fullCodeWave; codeWave; zeros( sps/20,1)];30 fullCodeWave=[fullCodeWave; codeWave; zeros(4049,1)]; 27 31 endfor 28 32 29 33 30 caFreq = 19200; % frequency of the tone [Hz]31 caNsecs = 10; % number of seconds of the audio file32 caNsamples = sps*caNsecs;33 34 caTime = linspace(0, caNsecs, caNsamples);35 carrierWave = [ones(floor(sps/caFreq/2),1);-ones(floor(sps/caFreq/2),1)];36 37 38 caWaveRepeat=[];39 sizeCW=size(carrierWave,1);40 for i=1:ceil(size(fullCodeWave,1)/sizeCW)41 caWaveRepeat=[caWaveRepeat;carrierWave];42 endfor43 44 45 46 fullCodeWave = fullCodeWave.*caWaveRepeat(1:size(fullCodeWave,1));47 34 wavwrite(fullCodeWave, sps, bps, audioFileName); -
octave/GenerateAudioCommand/flyCommand.m
r3322dad ra0b523e 12 12 elseif code=='demo2' 13 13 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 14 endif15 14 16 if (AndroidOriOS=='iOS') 15 elseif code=='demo3' 16 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 17 elseif code=='demo4' 18 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 19 endif 20 21 if (length(AndroidOriOS)==3)%'iOS' 17 22 longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample] 18 23 longLOW=729;longLOW_s=floor(longLOW*sps/1e6); … … 41 46 %fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))]; 42 47 43 elseif AndroidOrioS=='Android' 48 elseif length(AndroidOriOS)==7 %'Android' 49 50 longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-4;%longHIGH[us] longHIGH_s[sample] 51 longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3); 52 shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-2; 53 shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1; 54 55 codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_s,0,1,sps);0]; %starting 5 half period 56 57 % notice that the "code" here should be a 28 bit binary array. 58 m=0; 59 n=0; 60 for i=1:size(code,2) 61 codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s, longLOW_s,shortHIGH_s,shortLOW_s)]; 62 if code(i)==1 63 n=n+1; 64 elseif code(i)==0 65 m=m+1; 66 endif 67 68 if n==115 69 n=0; 70 codeWave=[codeWave;0]; 71 endif 72 if m==101 73 m=0; 74 codeWave=[codeWave;0]; 75 endif 76 77 endfor 78 79 codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period 80 81 if(flipOrNot=='flip') 82 codeWave=-codeWave; 83 endif 84 85 fullCodeWave=[]; 86 for i=1:repeatTime 87 fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; 88 endfor 89 90 44 91 endif %if AndroidOriOS=='iOS' 45 92 -
octave/GenerateAudioCommand/flyOrbit.m
r3322dad ra0b523e 6 6 bps = 16; % bits per sample 7 7 %sps = 96000; % sample rate [samples/s] 8 8 if length(AndroidOriOS)==3 %iOS 9 9 fullCodeWave=[flyCommand(code,space,'temp1.wav',sps,2,AndroidOriOS,flipOrNot);initCodeGen('temp2.wav');flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 10 10 11 elseif length(AndroidOriOS)==7 %Android 12 fullCodeWave=[flyCommand(code,space,'temp1,wav',sps,20,AndroidOriOS,flipOrNot);initCodeGenAndroid('temp2.wav');zeros(1,1);flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 13 14 endif 15 16 sizeCode=size(fullCodeWave,1); 17 time=linspace(0,sizeCode/sps,sizeCode); 18 fullCodeWave = [fullCodeWave sin(time*2*pi*440)']; 19 11 20 wavwrite(fullCodeWave, sps, bps, audioFileName); -
octave/GenerateAudioCommand/halfSineGenDirect.m
r0edc9d8 ra0b523e 14 14 15 15 16 time = linspace( 0, halfPeriod, halfPeriod_in_samples);16 time = linspace(1/sps, halfPeriod, halfPeriod_in_samples); 17 17 if (dir== 'u') 18 18 wave = sin(time*2*pi*freq)'.*amp+zero; -
octave/GenerateAudioCommand/read.me
r0edc9d8 ra0b523e 1 1 This script suppose to generate Audio wave to talk to UPRtek's IR dongle and produce IR signal to control helicopter. 2 2 this is an unfinished script, without complete documentation. 3 Author:hz@puzzlbox.info, Puzzlebox LLC 3 4 Released under GPLv2. 4 5 ================= 5 1 open terminal; 6 2 switch to this path; 7 3 run octave; 8 4 type these commands: 9 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 1]; 10 finalCodeAudioGen(code,'audioCommand.wav',44100,10); 6 1) open terminal; 7 2) switch to this path; 8 3) run octave; 9 4) type these commands: 10 11 for laptop (not android yet) 12 flyOrbit('demo4',4049,'flyOrbitlaptop.wav',48000,100,'Android','flip'); 13 for iPad 14 flyOrbit('demo4',4049,'flyOrbitiPad.wav',48000,100,'iOS','notF'); 15 16 17 5) 18 note that 'demo4' can be replaced with any code arrya like [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 1] 19 11 20 5 first parameter is the code you want to produce as an audio file. 12 second parameter is the output file name. 13 3rd parameter is the sample rate (sample per second) 14 4th parameter is how many times you want to repeat the code. Since this script is not optimised at all, set this parameter higher than 20 is not recomanded, unless you have a lot time to wait or your computer is super super fast. Otherwise you need to copy and paste the sound wave in Audacity several times to get a long enough audio file. 21 second parameter is the space between two command codes [unit:samples]. 22 3rd is the output file name. 23 4th is the sample rate (sample per second) 24 5th is how many times you want to repeat the code. 100 will generate a signal about 13 seconds long. 25 6th is option between iOS style code or Android style code. 26 7th when you use Android sytle code you need to flip the code that generated. This parameter will soon be obsolete in later version. -
octave/GenerateAudioCommand/read.me~
r6aa182f ra0b523e 1 This script suppose to generate Audio wave to talk to UPRtek's IR dongle and produce IR signal to control helicopter. 2 this is an unfinished script, without complete documentation. 3 Author:hz@puzzlbox.info 4 Released under GPLv2. 5 ================= 6 1) open terminal; 7 2) switch to this path; 8 3) run octave; 9 4) type these commands: 10 11 for laptop (not android yet) 12 flyOrbit('demo4',4049,'flyOrbitlaptop.wav',48000,100,'Android','flip'); 13 for iPad 14 flyOrbit('demo4',4049,'flyOrbitiPad.wav',48000,100,'iOS','notF'); 15 16 17 5) 18 note that 'demo4' can be replaced with any code arrya like [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 1] 19 20 5 first parameter is the code you want to produce as an audio file. 21 second parameter is the space between two command codes [unit:samples]. 22 3rd is the output file name. 23 4th is the sample rate (sample per second) 24 5th is how many times you want to repeat the code. 100 will generate a signal about 13 seconds long. 25 6th is option between iOS style code or Android style code. 26 7th when you use Android sytle code you need to flip the code that generated. This parameter will soon be obsolete in later version.
Note: See TracChangeset
for help on using the changeset viewer.