function y = sparsespec(x, numffts, spacing, window)
%y = sparsespec(x, numffts, spacing, window)
% this computes what I call a sparse spectogram.
% x is the data sample.
% numffts determines the number of ffts that we will compute, spaced
% evenly throughout the sample.
% spacing is the spacing within the fft.
%
% for example, we may have a 1028 sample size.
% if numffts = 5, spacing = 3, then the sample will be broken into 5 units
% to compute an fft, each being of size 15.
%
% a normal spectogram shifts its window by 1 for the next fft.
% this creates an output that requires n^2 blocks of data, which is way too
% much to store, and too much information to be useful (especially at high
% sampling frequencies).
%
% note that some infomation may be lost at the end
% you must make sure that the fftspacing is larger than the window
%
% I assume that the input vector is real-valued for plotting
%
% the columns of y are the ffts

len = length(x);
winlen = length(window);
fftspacing = floor(len/numffts);

y = zeros(winlen, numffts);

for i = 1:numffts
    start = (i-1)*fftspacing + 1; %this is the first element for this fft
    stop = start + spacing * winlen - 1;
    x1 = x(start:spacing:stop);
    x1 = window .* x1;
    y(:,i) = x1;
end

y = abs(fft(y));
last = ceil((winlen + 1)/2);
figure(1)
mesh(y(1:last,:));

figure(2)
imagesc(y(1:last,:));