rcosFn.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. % [X, Y] = rcosFn(WIDTH, POSITION, VALUES)
  2. %
  3. % Return a lookup table (suitable for use by INTERP1)
  4. % containing a "raised cosine" soft threshold function:
  5. %
  6. % Y = VALUES(1) + (VALUES(2)-VALUES(1)) *
  7. % cos^2( PI/2 * (X - POSITION + WIDTH)/WIDTH )
  8. %
  9. % WIDTH is the width of the region over which the transition occurs
  10. % (default = 1). POSITION is the location of the center of the
  11. % threshold (default = 0). VALUES (default = [0,1]) specifies the
  12. % values to the left and right of the transition.
  13. % Eero Simoncelli, 7/96.
  14. function [X, Y] = rcosFn(width,position,values)
  15. %------------------------------------------------------------
  16. % OPTIONAL ARGS:
  17. if (exist('width') ~= 1)
  18. width = 1;
  19. end
  20. if (exist('position') ~= 1)
  21. position = 0;
  22. end
  23. if (exist('values') ~= 1)
  24. values = [0,1];
  25. end
  26. %------------------------------------------------------------
  27. sz = 256; %% arbitrary!
  28. X = pi * [-sz-1:1] / (2*sz);
  29. Y = values(1) + (values(2)-values(1)) * cos(X).^2;
  30. % Make sure end values are repeated, for extrapolation...
  31. Y(1) = Y(2);
  32. Y(sz+3) = Y(sz+2);
  33. X = position + (2*width/pi) * (X + pi/4);