home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / WINDOWS / DIVERSEN / MATHS171 / COSW.M < prev    next >
Text File  |  1993-03-23  |  1KB  |  62 lines

  1. function y=cosw(npoints, f0, df, ph0)
  2. %y=cosw(num_of_points, num_of_cycles, delta_cycles, initial_phase)
  3. %create frequency hopping cosine wave composed of segements of linear
  4. %FM cosine waves
  5. %
  6. %num_of_points - number of points in each segment
  7. %f0            - inital frequency
  8. %df            - frequency deviation
  9. %ph0           - initial phase
  10. %
  11. %Example: cosw(256, 2, 3) generates a linear FM signal
  12.  
  13. %       S.Halevy 7/31/92
  14. %       Copyright (c) 1992 by the MathWizards
  15.  
  16. if nargin < 1
  17.   error('insufficient arguments')
  18. end
  19. npoints=npoints(:);   % make sure it is a col vector
  20. [mp,np]=size(npoints);
  21.  
  22. if nargin < 4
  23.    ph0=zeros(mp,np);  % zero initial phase - radians
  24. else
  25.    ph0=ph0(:);
  26.    [m0,n0]=size(ph0);
  27.    if m0 ~= mp | n0 ~= np
  28.       error('initial phase - dimension error')
  29.    end
  30. end
  31.  
  32. if nargin < 3
  33.    df=zeros(mp,np);   % no frequency deviation
  34. else
  35.    df=df(:);
  36.    [m0,n0]=size(df);
  37.    if m0 ~= mp | n0 ~= np
  38.       error('frequency deviation - dimension error')
  39.    end
  40. end
  41.  
  42. if nargin < 2
  43.    f0=ones(mp,np);    % single cycle
  44. else
  45.    f0=f0(:);
  46.    [m0,n0]=size(f0);
  47.    if m0 ~= mp | n0 ~= np
  48.       error('cycles - dimension error')
  49.    end
  50. end
  51.  
  52. y=[];
  53. pi2=atan(1.0)*8;
  54. for i1=1:mp
  55.    n = npoints(i1);
  56.    t = (0:(n-1))/n;                  % time
  57.    ph1 = (f0(i1)+0.5*df(i1)*t).*t;   % phase
  58.    ph1 -= floor(ph1);                % reduce roundoff errors
  59.  
  60.    y=[y  cos(pi2*ph1+ph0(i1))];
  61. end
  62.