% timeseries4test.m
% Test of spectrum.m using timeseries4.m
%
% CCK 2017-Feb-09 ported to Matlab (now runs in both Matlab & Octave).

M=1000;  % Number of chunks
N=1024;  % Chunk size
dt = 0.25; % To agree with timeseries4.m
SNR=10;
timeseries4(M, N, SNR);
dt = 0.25;

fileID = fopen("datafile.bin","r");
signal = fread(fileID, M*N, "float", "ieee-be");
time = dt*(0:(M*N - 1));
figure(1)
hold off
plot(time(1:2*N), signal(1:2*N), "-b")
xlabel('time (s)')
ylabel('signal (V)')

figure(2)
hold off
[spec, frequency] = spectrum("datafile.bin", M*N/2, dt);
semilogy(frequency, spec,'r')
hold on
[spec, frequency] = spectrum("datafile.bin", N, dt);
plot(frequency, spec,'b')
xlabel('frequency (Hz)')
ylabel('power spectrum')
axis([0,frequency(end),min(spec),max(spec)*10])