source: orbit/octave/GenerateAudioCommand/dualIRLEDAudioGen.m @ 3322dad

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 3322dad was 0edc9d8, checked in by AzureViolin <zhanghaotz@…>, 7 years ago

generated working iPad init Code

  • Property mode set to 100644
File size: 1.3 KB
Line 
1function dualIRLEDAudioGen(code,audioFileName,sps,repeatTime,Multiplyer,flipOrNot)
2
3% code: array of 1s and 0s. 1 means bit "1", 0 means bit "0".
4% audioFileName: like 'audio.wav'.
5% Multiplyer: value around 1, to change "carrier" period.
6bps = 16;       % bits per sample
7%sps = 96000;     % sample rate [samples/s]
8shortT=floor(0.0008*sps/2);
9longT=floor(0.0016*sps/2);
10codeWave=[ones(longT,1);zeros(shortT,1);ones(longT,1);zeros(shortT,1)];
11
12% notice that the "code" here should be a 28 bit binary array.
13for i=1:size(code,2)
14        codeWave = [codeWave; dualBitGen(code(i),1,sps)];
15endfor
16
17codeWave=[codeWave; ones(longT,1)]; %last half period
18
19
20if(exist("flipOrNot","var"))
21        codeWave=-codeWave;
22endif
23
24fullCodeWave=[];
25for i=1:repeatTime
26        fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)];
27endfor
28
29
30caFreq = 19200;       % frequency of the tone [Hz]
31caNsecs = 10;      % number of seconds of the audio file
32caNsamples = sps*caNsecs;
33
34caTime = linspace(0, caNsecs, caNsamples);
35carrierWave = [ones(floor(sps/caFreq/2),1);-ones(floor(sps/caFreq/2),1)];
36
37
38caWaveRepeat=[];
39sizeCW=size(carrierWave,1);
40for i=1:ceil(size(fullCodeWave,1)/sizeCW)
41        caWaveRepeat=[caWaveRepeat;carrierWave];
42endfor
43
44
45
46fullCodeWave = fullCodeWave.*caWaveRepeat(1:size(fullCodeWave,1));
47wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.