function a = set(a,varargin)
% SET Set IncWave properties and return the updated object
propertyArgIn = varargin;
while length(propertyArgIn) >= 2,
   prop = propertyArgIn{1};
   val = propertyArgIn{2};
   propertyArgIn = propertyArgIn(3:end);
   switch prop
   case 'Type'
      a.Type = val;
   case 'A'
      a.A = val; 
   case 'T'
      a.T = val;
   case 'g'
      a.g = val;  
   case 'n_phases'
      a.n_phases = val; 
      phasea = 0;
      phaseb = 2*pi;
      
     %defaultStream = RandStream.getDefaultStream;
     %savedState = defaultStream.State;
     
     
      a.phases = phasea + (phaseb-phasea).*rand(a.n_phases,1);
      
      %defaultStream.State = savedState;
   case 'spectrum'
       a.spectrum = val;
   case 'freq'
       a.freq = val;
       a.n_phases = length(val); 
       phasea = 0;
       phaseb = 2*pi;   
       a.phases = phasea + (phaseb-phasea).*rand(a.n_phases,1);
      
   case 'beta'
       a.beta = val;    
       
   case 'df'
       a.df = val;
   case 'fmax'
       a.fmax = val;
   otherwise
      error('Invalid IncWave property')
   end
end