source: orbit/octave/GenerateAudioCommand/halfSineGen.m @ 71aa88f

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

add octave script

  • Property mode set to 100644
File size: 739 bytes
Line 
1function wave = halfSineGen(dir,halfPeriod,zero,amp,sps)
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
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== 'u')
20        wave = sin(time*2*pi*freq)'.*amp+zero;
21elseif (dir=='d')
22        wave = sin((time+halfPeriod)*2*pi*freq)'.*amp+zero;
23endif
24
25%wavwrite(wave, sps, bps, 'audio.wav');
Note: See TracBrowser for help on using the repository browser.