1 | function **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 | |
---|

6 | bps = 16; % bits per sample |
---|

7 | sps = 960000; % sample rate [samples/s] |
---|

8 | |
---|

9 | codeWave=[]; |
---|

10 | |
---|

11 | **for** i=1:size(code,2) |
---|

12 | codeWave = [codeWave; bitGen(code(i),1)]; |
---|

13 | endfor |
---|

14 | |
---|

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; |
---|

34 | **wavwrite**(codeWave, sps, bps, audioFileName); |
---|