source: orbit/octave/GenerateAudioCommand/finalCodeAudioGen.m @ 22d5a76

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

add octave script

  • Property mode set to 100644
File size: 1.2 KB
Line 
1function finalCodeAudioGen(code,audioFileName,sps,repeatTime)
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
7%sps = 96000;     % sample rate [samples/s]
8
9codeWave=[halfSineGen('u',800,0,1,sps);halfSineGen('d',400,0,1,sps);halfSineGen('u',800,0,1,sps);halfSineGen('d',400,0,1,sps)];
10
11for i=1:size(code,2)
12        codeWave = [codeWave; bitGen(code(i),1,sps)];
13endfor
14
15fullCodeWave=[];
16for i=1:repeatTime
17        fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)];
18endfor
19
20%special wave form for carrier
21carrierWave=[halfPeriodGen('u',30*1.215,-0.353,0.723,sps);
22halfPeriodGen('d',22*1.215,-0.015,0.384,sps);
23halfPeriodGen('u',31*1.215,0.261,0.661,sps);
24halfPeriodGen('d',28*1.215,0.392,0.530,sps);
25halfPeriodGen('u',25*1.215,0.246,0.384,sps);
26halfPeriodGen('d',32*1.215,-0.092,0.723,sps);
27halfPeriodGen('u',25*1.215,-0.430,0.384,sps);
28halfPeriodGen('d',26*1.215,-0.515,0.469,sps)];
29
30fullCodeWave=[fullCodeWave fullCodeWave].*0.5;
31
32sizeCW=size(carrierWave,1);
33cWaveRepeat=[];
34n=floor(size(fullCodeWave,1)/sizeCW);
35for i=1:n
36        cWaveRepeat=[cWaveRepeat; carrierWave];
37endfor
38
39fullCodeWave(1:n*sizeCW,2)+=cWaveRepeat;
40wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.