%sumofsin.m
%m-file to generate a waveform that is the sum of several sinusoids.

function [y,yplot,off,Amp,phase] = sumofsin(N,f1,t)
nosins=input('How many components do you wish? ');
off=input('What is the offset or mean value of the summed wave? ');
s=ones(nosins,N);

for i = 1:nosins,
  xs=num2str(i);
  disp(' ');
  disp(['Input the frequency, amplitude, and phase for component #',xs])
  disp(['(Remember to choose a frequency that is an integral multiple of f1.)'])
  f=input(['Enter wave frequency of this component (eg, 10*f1): ']);
  w1=2*pi*f;
  Amp=input('What is the amplitude of this component? ');
  phase=input('What is the phase shift (in degrees)? ');
  phs=phase*pi/180;
  s(i,1:N)=Amp*cos(w1*t - phs);
end

y=sum(s) + off;
yplot = [y(:); y(:)];



