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;
            a = ComputeSpectrum(a);
        case 'A'
            a.A = val;
            a = ComputeSpectrum(a);
        case 'T'
            a.T = val;
            a = ComputeSpectrum(a);
        case 'g'
            a.g = val;
        case 'n_phases'
            a.n_phases = val;
            phasea = 0;
            phaseb = 2*pi;
            
            %defaultStream = RandStream.getDefaultStream;
            %savedState = defaultStream.State;
            
            s = RandStream('mt19937ar','Seed', 5489);
            RandStream.setDefaultStream(s);
            a.phases = phasea + (phaseb-phasea).*rand(a.n_phases,1);

            a = ComputeSpectrum(a);
            %defaultStream.State = savedState;
        case 'spectrum'
            a.spectrum = val;
        case 'freq'
            a.freq = val;
            a.n_phases = length(val);
            phasea = 0;
            phaseb = 2*pi;
            s = RandStream('mt19937ar','Seed', 5489);
            RandStream.setDefaultStream(s);
            a.phases = phasea + (phaseb-phasea).*rand(a.n_phases,1);
        
        case 'beta'
            a.beta = val;
            
        case 'df'
            a.df = val;
            a.freq = a.df:a.df:a.fmax;
            a = ComputeSpectrum(a);          
        case 'fmax'
            a.fmax = val;
            a.freq = a.df:a.df:a.fmax;
            a = ComputeSpectrum(a);
        case 'tau'
            if(val > 0)
              a.tau = a.T/val;  %Sets number of periods to ramp up over.
            else
              a.tau = 0;
            end
        otherwise
            error('Invalid IncWave property')
    end
end