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

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

generated working iPad init Code

  • Property mode set to 100644
File size: 853 bytes
Line 
1function wave = halfCosineGen(dir,halfPeriod,zero,amp,sps,shift)
2
3% dir: 'u' means UP, 'd' means down.
4% halfPeriod: half period of cosine signal[us].
5% zero: zero level of cosine signal.
6% amp: amplitude of cosine signal, in percentage.
7% shift: shift cosine wave, with low sampling rate hopefully can change period when recover.
8halfPeriod=halfPeriod/1e6;
9
10bps = 16;       % bits per sample
11%sps = 960000;     % sample rate [samples/s]
12period = halfPeriod*2;   %period of [s]
13freq = floor(1./period);       % frequency of the tone [Hz]
14
15nsecs = halfPeriod;      % number of seconds of the audio file
16nsamples = sps*nsecs;
17
18time = linspace(0, nsecs, nsamples);
19if (dir== 'd')
20        wave = cos((time+shift)*2*pi*freq)'.*amp+zero;
21elseif (dir=='u')
22        wave = cos((time+halfPeriod+shift)*2*pi*freq)'.*amp+zero;
23endif
24
25%wavwrite(wave, sps, bps, 'audio.wav');
Note: See TracBrowser for help on using the repository browser.