% chop_spec.m  Chop up the spectrum by zero freq bands

% Create square wave of 1's and 0's to multiply spectrum by.
block = [ones(1,50),zeros(1,350)];   % Create a block of ones and zeros.

% Repeat the block of ones and zeros for three seconds of sound.
comb = [ones(1,100),zeros(1,200),...
    repmat(block,1,24000/400)];

% Shorten comb to length of sound sample (3 sec @ 8000 samp/sec), in case it's too long.
comb = comb(1:24000);

% Another way to create the comb array would be to use a for loop:
comb_2 = [];     We first create an empty array to append to.
nblocks = 1:24000/400
for index = 1:num_blocks       % Each time thru loop, index = next col of array 1:nblocks
  comb_2 = [comb_2, block];   % Add another block to end of comb_2 each time thru loop.
end                           % Jump back to top of loop, get next value of index.
                              % Fall thru when value of index past last col of 1:nblocks
% Note that we didn't use index inside the loop in this case.  It just counted the
%  number of times to go thru the loop.  Usually we do use the value of the index in a
%  loop.

% Load snippet of sound.
load handel

% Shorten sound to 3 sec.
y = y(1:24000);

% Take Fast Fourier Transform (FFT) of sound.
Vi_k = fft(y);

% Zero out bands of frequencies in spectrum.
Vo_k = comb .* Vi_k';

% Take Inverse FFT.  Time domain signal must be made real.
vo_t = real(ifft(Vo_k));

% Put sound in y array for "listen" script.
y = vo_t;

% Play the sound.
sound(y)
