mkSine.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. % IM = mkSine(SIZE, PERIOD, DIRECTION, AMPLITUDE, PHASE, ORIGIN)
  2. % or
  3. % IM = mkSine(SIZE, FREQ, AMPLITUDE, PHASE, ORIGIN)
  4. %
  5. % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)
  6. % containing samples of a 2D sinusoid, with given PERIOD (in pixels),
  7. % DIRECTION (radians, CW from X-axis, default = 0), AMPLITUDE (default
  8. % = 1), and PHASE (radians, relative to ORIGIN, default = 0). ORIGIN
  9. % defaults to the center of the image.
  10. %
  11. % In the second form, FREQ is a 2-vector of frequencies (radians/pixel).
  12. % Eero Simoncelli, 6/96.
  13. function [res] = mkSine(sz, per_freq, dir_amp, amp_phase, phase_orig, orig)
  14. %------------------------------------------------------------
  15. %% OPTIONAL ARGS:
  16. if (prod(size(per_freq)) == 2)
  17. frequency = norm(per_freq);
  18. direction = atan2(per_freq(1),per_freq(2));
  19. if (exist('dir_amp') == 1)
  20. amplitude = dir_amp;
  21. else
  22. amplitude = 1;
  23. end
  24. if (exist('amp_phase') == 1)
  25. phase = amp_phase;
  26. else
  27. phase = 0;
  28. end
  29. if (exist('phase_orig') == 1)
  30. origin = phase_orig;
  31. end
  32. if (exist('orig') == 1)
  33. error('Too many arguments for (second form) of mkSine');
  34. end
  35. else
  36. frequency = 2*pi/per_freq;
  37. if (exist('dir_amp') == 1)
  38. direction = dir_amp;
  39. else
  40. direction = 0;
  41. end
  42. if (exist('amp_phase') == 1)
  43. amplitude = amp_phase;
  44. else
  45. amplitude = 1;
  46. end
  47. if (exist('phase_orig') == 1)
  48. phase = phase_orig;
  49. else
  50. phase = 0;
  51. end
  52. if (exist('orig') == 1)
  53. origin = orig;
  54. end
  55. end
  56. %------------------------------------------------------------
  57. if (exist('origin') == 1)
  58. res = amplitude*sin(mkRamp(sz, direction, frequency, phase, origin));
  59. else
  60. res = amplitude*sin(mkRamp(sz, direction, frequency, phase));
  61. end