source: orbit/octave/GenerateAudioCommand/halfSineGenDirect.m @ cb3655b

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since cb3655b was cb3655b, checked in by dorabot <dorabot@…>, 8 years ago

add comment to script

  • Property mode set to 100644
File size: 858 bytes
Line 
1function wave = halfSineGenDirect(dir,halfPeriod_in_samples,zero,amp,sps)
2
3% dir: 'u' means UP, 'd' means down.
4% halfPeriod: half period of sine signal[us].
5% zero: zero level of cosine signal.
6% amp: amplitude of cosine signal, in percentage.
7
8halfPeriod=halfPeriod_in_samples/sps;
9
10bps = 16;       % bits per sample
11%sps = 960000;     % sample rate [samples/s]
12period = halfPeriod*2;   %period of [s]
13freq = floor(sps/(halfPeriod_in_samples*2));       % frequency of the tone [Hz]
14
15%linspace is an octave function that generates a sequence with certain step.
16time = linspace(1/sps, halfPeriod, halfPeriod_in_samples);
17if (dir== 'u')
18        wave = sin(time*2*pi*freq)'.*amp+zero;%'u' indicates above zero line
19elseif (dir=='d')
20        wave = sin((time+halfPeriod)*2*pi*freq)'.*amp+zero;%'d' indicates below zero line
21endif
22
23%wavwrite(wave, sps, bps, 'audio.wav');
Note: See TracBrowser for help on using the repository browser.