Changeset a0b523e in orbit


Ignore:
Timestamp:
11/29/12 08:17:10 (7 years ago)
Author:
AzureViolin <zhanghaotz@…>
Branches:
master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
Children:
0401409, 655a816
Parents:
3322dad
Message:

flyOrbit.m can now generate arbitry control code for play from laptop. update read.me

Location:
octave/GenerateAudioCommand
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • octave/GenerateAudioCommand/codeAudioGen.m

    r6aa182f ra0b523e  
    55 
    66bps = 16;       % bits per sample 
    7 sps = 960000;     % sample rate [samples/s] 
     7sps = 480000;     % sample rate [samples/s] 
    88 
    99codeWave=[]; 
    1010 
    1111for i=1:size(code,2) 
    12         codeWave = [codeWave; bitGen(code(i),1)]; 
     12        codeWave = [codeWave; bitGen(code(i),1,sps)]; 
    1313endfor 
    1414 
    15 %special wave form for carrier 
    16 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:n 
    30         cWaveRepeat=[cWaveRepeat; carrierWave]; 
    31 endfor 
    32  
    33 codeWave(1:n*sizeCW,2)+=cWaveRepeat; 
    3415wavwrite(codeWave, sps, bps, audioFileName); 
    3516 
  • octave/GenerateAudioCommand/dualIRLEDAudioGen.m

    r0edc9d8 ra0b523e  
    66bps = 16;       % bits per sample 
    77%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 
     10shortLOW=floor(0.0008*sps/2)+1; 
     11shortHIGH=floor(0.0008*sps/2)-1; 
     12longHIGH=floor(0.0016*sps/2)-1; 
     13longLOW=floor(0.0016*sps/2)+2; 
     14codeWave=[ones(longHIGH,1);zeros(shortLOW,1);ones(longHIGH,1);zeros(shortLOW,1)]; 
    1115 
    1216% notice that the "code" here should be a 28 bit binary array. 
    1317for i=1:size(code,2) 
    14         codeWave = [codeWave; dualBitGen(code(i),1,sps)]; 
     18        codeWave = [codeWave; dualBitGenDirect(code(i),shortHIGH,shortLOW,longHIGH,longLOW)]; 
    1519endfor 
    1620 
    17 codeWave=[codeWave; ones(longT,1)]; %last half period 
     21codeWave=[codeWave; ones(longHIGH,1)]; %last half period 
    1822 
    1923 
     
    2428fullCodeWave=[]; 
    2529for i=1:repeatTime 
    26         fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)]; 
     30        fullCodeWave=[fullCodeWave; codeWave; zeros(4049,1)]; 
    2731endfor 
    2832 
    2933 
    30 caFreq = 19200;       % frequency of the tone [Hz] 
    31 caNsecs = 10;      % number of seconds of the audio file 
    32 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 endfor 
    43  
    44  
    45  
    46 fullCodeWave = fullCodeWave.*caWaveRepeat(1:size(fullCodeWave,1)); 
    4734wavwrite(fullCodeWave, sps, bps, audioFileName); 
  • octave/GenerateAudioCommand/flyCommand.m

    r3322dad ra0b523e  
    1212elseif code=='demo2' 
    1313        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 endif 
    1514 
    16 if (AndroidOriOS=='iOS') 
     15elseif 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 
     17elseif 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 
     21if (length(AndroidOriOS)==3)%'iOS' 
    1722longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample] 
    1823longLOW=729;longLOW_s=floor(longLOW*sps/1e6); 
     
    4146%fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))]; 
    4247 
    43 elseif AndroidOrioS=='Android' 
     48elseif length(AndroidOriOS)==7 %'Android' 
     49 
     50longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-4;%longHIGH[us]  longHIGH_s[sample] 
     51longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3); 
     52shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-2; 
     53shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1; 
     54 
     55codeWave=[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. 
     58m=0; 
     59n=0; 
     60for i=1:size(code,2) 
     61codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s,   longLOW_s,shortHIGH_s,shortLOW_s)]; 
     62if code(i)==1 
     63        n=n+1; 
     64elseif code(i)==0 
     65        m=m+1; 
     66endif 
     67 
     68if n==115  
     69        n=0; 
     70        codeWave=[codeWave;0]; 
     71endif 
     72if m==101 
     73        m=0; 
     74        codeWave=[codeWave;0]; 
     75endif 
     76         
     77endfor 
     78 
     79codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)];  %last half period 
     80 
     81if(flipOrNot=='flip') 
     82    codeWave=-codeWave; 
     83endif 
     84 
     85fullCodeWave=[]; 
     86for i=1:repeatTime 
     87            fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; 
     88endfor 
     89 
     90 
    4491endif %if AndroidOriOS=='iOS' 
    4592 
  • octave/GenerateAudioCommand/flyOrbit.m

    r3322dad ra0b523e  
    66bps = 16;       % bits per sample 
    77%sps = 96000;     % sample rate [samples/s] 
    8  
     8if length(AndroidOriOS)==3 %iOS 
    99fullCodeWave=[flyCommand(code,space,'temp1.wav',sps,2,AndroidOriOS,flipOrNot);initCodeGen('temp2.wav');flyCommand(code,space,'temp3.wav',sps,repeatTime,AndroidOriOS,flipOrNot)]; 
    1010 
     11elseif length(AndroidOriOS)==7 %Android 
     12fullCodeWave=[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 
     14endif 
     15 
     16sizeCode=size(fullCodeWave,1); 
     17time=linspace(0,sizeCode/sps,sizeCode); 
     18fullCodeWave = [fullCodeWave sin(time*2*pi*440)']; 
     19 
    1120wavwrite(fullCodeWave, sps, bps, audioFileName); 
  • octave/GenerateAudioCommand/halfSineGenDirect.m

    r0edc9d8 ra0b523e  
    1414 
    1515 
    16 time = linspace(0, halfPeriod, halfPeriod_in_samples); 
     16time = linspace(1/sps, halfPeriod, halfPeriod_in_samples); 
    1717if (dir== 'u')  
    1818        wave = sin(time*2*pi*freq)'.*amp+zero; 
  • octave/GenerateAudioCommand/read.me

    r0edc9d8 ra0b523e  
    11This script suppose to generate Audio wave to talk to UPRtek's IR dongle and produce IR signal to control helicopter. 
    22this is an unfinished script, without complete documentation. 
     3Author:hz@puzzlbox.info, Puzzlebox LLC 
    34Released under GPLv2. 
    45================= 
    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); 
     61) open terminal; 
     72) switch to this path; 
     83) run octave; 
     94) type these commands: 
     10 
     11for laptop (not android yet) 
     12        flyOrbit('demo4',4049,'flyOrbitlaptop.wav',48000,100,'Android','flip'); 
     13for iPad 
     14        flyOrbit('demo4',4049,'flyOrbitiPad.wav',48000,100,'iOS','notF'); 
     15 
     16 
     175) 
     18note 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         
    11205 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  
     1This script suppose to generate Audio wave to talk to UPRtek's IR dongle and produce IR signal to control helicopter. 
     2this is an unfinished script, without complete documentation. 
     3Author:hz@puzzlbox.info 
     4Released under GPLv2. 
     5================= 
     61) open terminal; 
     72) switch to this path; 
     83) run octave; 
     94) type these commands: 
     10 
     11for laptop (not android yet) 
     12        flyOrbit('demo4',4049,'flyOrbitlaptop.wav',48000,100,'Android','flip'); 
     13for iPad 
     14        flyOrbit('demo4',4049,'flyOrbitiPad.wav',48000,100,'iOS','notF'); 
     15 
     16 
     175) 
     18note 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         
     205 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.