  function C = segmentCleaned(F)
% F is a string that names a .wav file (including the suffix.)
% Prompts the user to enter the breakpoints and subsequently sets
% up a structure array C with the property that C(k).z
% is the array of sound values for the kth segment and C(k).rate
% is the associated sampling rate.
% 
% The sound data is first smoothed to reduce the spikiness.
% Based on a user-selected breakpoint, a "window" of lull, defined to 
% be data below a certain threshold value, is excluded from the sound 
% clips that are stored in the cell array.

% Read and display the file:
  [data,rate] = wavread(F);
  close all
  data= ReduceSpikes(data);
  plot(data)
  title('Enter n breakpoints left to right')
  hold on

% Enter the breakpoints...
  [x,y] = ginput;
  x = floor(x);
  
% Set threshold
  minVol= 0.1;
  
% Set up C...
  nSegments = length(x)-1
  for k=1:nSegments
      plot(x(k),0,'m.','MarkerSize',15)
      
      % Find the beginning of the kth segmetn
      i= x(k);
      while abs(data(i))<minVol
          i= i+1;
      end
      First= i-1;
      plot([First First], [-1 1], 'r-')
      
      % Find end of kth segment
      i= x(k+1);
      while abs(data(i))<minVol
          i= i-1;
      end
      Last =  i+1;
      plot([Last Last], [-1 1], 'g-')

      z = data(First:Last);
      C(k) = struct('rate',rate,'z',z);
 
  end  
  plot(x(length(x)),0,'m.','MarkerSize',15)
    
hold off    
