% coswave.m - Generates a cosine wave: 8000 samples, 1 s, 200 Hz
% (when played at 8000 samples/s)
length = 8000;
freq = 0.025;
% i.e. 200 Hz / 8000 Hz
arg = 2 * pi * freq;
Out = round(32000 * cos(1:length * arg));
% SIGNAL_OUT.M
% Write a signal in variable "Out" to a raw binary file
file_out = input('Please enter the name of the output signal file: ','s');
fid_out = fopen(file_out,'w');
fwrite(fid_out,Out,'integer*2');
status = fclose(fid_out);
% Convert a raw binary signal to a wav file
unix('sox -r 8000 -b 16 -e signed-integer -c 1 cosine.raw cosine.wav')
% ALTERNATIVELY
% wavwrite (y, fs, nbits,
filename)
wavwrite (Out, 16000, 16, 'cosine.wav')