source: orbit/octave/GenerateAudioCommand/finalCodeAudioGen.m @ 0edc9d8

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

generated working iPad init Code

  • Property mode set to 100644
File size: 1.7 KB
Line 
1function finalCodeAudioGen(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]
8
9longHIGH=875;
10longLOW=729;
11shortHIGH=458;
12shortLOW=333;
13
14codeWave=[halfSineGen('u',longHIGH,0,1,sps);zeros(floor(shortLOW*sps/1e6),1);halfSineGen('u',longHIGH,0,1,sps);zeros(floor(shortLOW*sps/1e6),1)]; %starting 5 half period
15
16% notice that the "code" here should be a 28 bit binary array.
17for i=1:size(code,2)
18        codeWave = [codeWave; bitGenHDMI(code(i),1,sps)];
19endfor
20
21codeWave=[codeWave; halfSineGen('u',longHIGH,0,1,sps)]; %last half period
22
23if(exist("flipOrNot","var"))
24        codeWave=-codeWave;
25endif
26
27fullCodeWave=[];
28for i=1:repeatTime
29        fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)];
30endfor
31
32%Multiplyer=1;
33shift=0;
34%special wave form for carrier
35carrierWave=[halfCosineGen('u',30*Multiplyer,-0.353,0.723,sps,shift);
36halfCosineGen('d',22*Multiplyer,-0.015,0.384,sps,shift);
37halfCosineGen('u',31*Multiplyer,0.261,0.661,sps,shift);
38halfCosineGen('d',28*Multiplyer,0.392,0.530,sps,shift);
39halfCosineGen('u',25*Multiplyer,0.246,0.384,sps,shift);
40halfCosineGen('d',32*Multiplyer,-0.092,0.723,sps,shift);
41halfCosineGen('u',25*Multiplyer,-0.430,0.384,sps,shift);
42halfCosineGen('d',26*Multiplyer,-0.515,0.469,sps,shift)];
43
44fullCodeWave=[fullCodeWave fullCodeWave].*1;
45carrierWave=carrierWave.*0.8;%double the amplitude of CodeWave
46
47sizeCW=size(carrierWave,1);
48cWaveRepeat=[];
49n=floor(size(fullCodeWave,1)/sizeCW);
50for i=1:n
51        cWaveRepeat=[cWaveRepeat; carrierWave];
52endfor
53
54fullCodeWave(1:n*sizeCW,2)+=cWaveRepeat;
55wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.