% simptable.m
%
% A simple example script to demonstrate how to create and use a sinusoidal
% wavetable.
%
% by Gary Scavone, McGill University.

clear
fs = 44100;
Ts = 1 / fs;

N = 512;
t = sin(2*pi*(0:N-1)/N);

M = 40000;
y = zeros(1, M);
ptr = 1;

for n = 1:M
  y(n) = t(ptr);
  ptr = ptr + 1;
  if ptr > N, ptr = 1; end
end

subplot(2, 1, 1)
plot( y )
xlabel('Time (samples)')

subplot(2, 1, 2)
f = fs*(0:M-1)/M;
plot( f, 20*log10(abs(fft(y))) );
xlim([0 5000])
grid
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)')