Tunica/01.m

Z Wikiverzity

Tunica01.m – první náčrt programu z 2009-01-02

# tunica = TUNing & sCAnning pipe organ

# Input data: 
rawfilename  = 'PV081130_0102_05.raw.01';
skip_seconds = 5.5;
window_seconds = 7;
# window_seconds = 96;  # celý pedál
sampling_freq = 44100;	# Hz
sampling_interval = 1 / sampling_freq;  # seconds

# Some constants:
n_samples = window_seconds*sampling_freq

# Read input file:
rawfile = fopen (rawfilename, "r", "ieee-le");
fseek (rawfile, 4*skip_seconds*sampling_freq, SEEK_SET);
#for sample = 1:n_samples;
#   [signal, count] = fread (rawfile,  1, "int16");
#   fread (rawfile,  1, "int16");
#endfor
#stereo_signal = fread (rawfile, [n_samples,2], "int16"); # každý řádek matice = [left_channel, right_channel]
signal = fread (rawfile, n_samples, "int16", 2); # left channel only; the right one is skipped
fclose (rawfile);

grid("on");

# plot (signal);
# plot (signal, '.');

#pgram = periodogram(signal);
#plot (pgram, '.');

power = signal .^ 2;
#plot (power, '.');
#plot ([0:sampling_interval:window_seconds-sampling_interval] ,power, '.')

step_s = 0.1   
step = step_s * sampling_freq;  # samples = seconds * Hz
low_boundary = 1;
section = 1;

while(1)
  high_boundary = low_boundary + step;
  if (high_boundary > rows(signal)) break;
  endif
  intensity (section) = mean (power (low_boundary:high_boundary));
  low_boundary = high_boundary;
  section++;
endwhile

# plot ([step_s:step_s:window_seconds-step_s], intensity)
level = 10*log10(intensity/max(intensity));
plot ([step_s:step_s:window_seconds-step_s], level)