% Example of sampling
fs = 1000; % Sampling Rate
f = 60; % Frequency of sinusoid
T = 1; % length of time axis
N = 2^ceil(log2(fs*T)); % Transform length
%
t = [0:1/fs:T];
sinewave=sin(2*pi*f*t);
sq = infclip(sinewave);
%
clf;
signal = sq;
spectrum = fft(signal, N);
subplot(211)
plot(t,signal);
hold on
plot(t,signal,'or');
current_axis = axis;
current_axis(2) = .1;
current_axis(3:4) = 1.5*current_axis(3:4);
axis(current_axis);
subplot(212)
f_axis = [0:1/N:.5]*fs;
plot(f_axis, abs(spectrum(1:N/2+1)));
%
% Amplitude quantization
%
f = 64;
sinewave=sin(2*pi*f*t);
b=4;
levels=2^b;
q_sine = fix(levels/2*sinewave);
clf;
signal = sq;
spectrum = fft(q_sine, N);
subplot(211)
plot(t,q_sine);
hold on
plot(t,q_sine,'or');
current_axis = axis;
current_axis(2) = .1;
current_axis(3:4) = 1.5*current_axis(3:4);
axis(current_axis);
subplot(212)
f_axis = [0:1/N:.5]*fs;
semilogy(f_axis, abs(spectrum(1:N/2+1)));
grid
