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

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

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

8 | shortT=floor(0.0008*sps/2); |
---|

9 | longT=floor(0.0016*sps/2); |
---|

10 | codeWave=[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. |
---|

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

14 | codeWave = [codeWave; dualBitGen(code(i),1,sps)]; |
---|

15 | endfor |
---|

16 | |
---|

17 | codeWave=[codeWave; ones(longT,1)]; %last half period |
---|

18 | |
---|

19 | |
---|

20 | **if**(exist(**"flipOrNot"**,**"var"**)) |
---|

21 | codeWave=-codeWave; |
---|

22 | endif |
---|

23 | |
---|

24 | fullCodeWave=[]; |
---|

25 | **for** i=1:repeatTime |
---|

26 | fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)]; |
---|

27 | endfor |
---|

28 | |
---|

29 | |
---|

30 | caFreq = 19200; % frequency of the tone [Hz] |
---|

31 | caNsecs = 10; % number of seconds of the audio file |
---|

32 | caNsamples = sps*caNsecs; |
---|

33 | |
---|

34 | caTime = linspace(0, caNsecs, caNsamples); |
---|

35 | carrierWave = [ones(floor(sps/caFreq/2),1);-ones(floor(sps/caFreq/2),1)]; |
---|

36 | |
---|

37 | |
---|

38 | caWaveRepeat=[]; |
---|

39 | sizeCW=size(carrierWave,1); |
---|

40 | **for** i=1:ceil(size(fullCodeWave,1)/sizeCW) |
---|

41 | caWaveRepeat=[caWaveRepeat;carrierWave]; |
---|

42 | endfor |
---|

43 | |
---|

44 | |
---|

45 | |
---|

46 | fullCodeWave = fullCodeWave.*caWaveRepeat(1:size(fullCodeWave,1)); |
---|

47 | **wavwrite**(fullCodeWave, sps, bps, audioFileName); |
---|