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

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

add octave script

  • Property mode set to 100644
File size: 893 bytes
Line 
1function codeAudioGen(code,audioFileName)
2
3% code: array of 1s and 0s. 1 means bit "1", 0 means bit "0".
4% audioFileName: like 'audio.wav'.
5
6bps = 16;       % bits per sample
7sps = 960000;     % sample rate [samples/s]
8
9codeWave=[];
10
11for i=1:size(code,2)
12        codeWave = [codeWave; bitGen(code(i),1)];
13endfor
14
15%special wave form for carrier
16carrierWave=[halfPeriodGen('u',30,-0.353,0.723);
17halfPeriodGen('d',22,-0.015,0.384);
18halfPeriodGen('u',31,0.261,0.661);
19halfPeriodGen('d',28,0.392,0.530);
20halfPeriodGen('u',25,0.246,0.384);
21halfPeriodGen('d',32,-0.092,0.723);
22halfPeriodGen('u',25,-0.430,0.384);
23halfPeriodGen('d',26,-0.515,0.469)];
24codeWave=[codeWave codeWave].*0.5;
25
26sizeCW=size(carrierWave,1);
27cWaveRepeat=[];
28n=floor(size(codeWave,1)/sizeCW);
29for i=1:n
30        cWaveRepeat=[cWaveRepeat; carrierWave];
31endfor
32
33codeWave(1:n*sizeCW,2)+=cWaveRepeat;
34wavwrite(codeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.