lplot.m 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. % lplot(VEC, XRANGE)
  2. %
  3. % Plot VEC, a vector, in "lollipop" format.
  4. % XRANGE (optional, default = [1,length(VEC)]), should be a 2-vector
  5. % specifying the X positions (for labeling purposes) of the first and
  6. % last sample of VEC.
  7. % Mark Liberman, Linguistics Dept, UPenn, 1994.
  8. function lplot(x,xrange)
  9. if (exist('xrange') ~= 1)
  10. xrange = [1,length(x)];
  11. end
  12. msize = size(x);
  13. if ( msize(2) == 1)
  14. x = x';
  15. elseif (msize(1) ~= 1)
  16. error('First arg must be a vector');
  17. end
  18. if (~isreal(x))
  19. fprintf(1,'Warning: Imaginary part of signal ignored\n');
  20. x = abs(x);
  21. end
  22. N = length(x);
  23. index = xrange(1) + (xrange(2)-xrange(1))*[0:(N-1)]/(N-1);
  24. xinc = index(2)-index(1);
  25. xx = [zeros(1,N);x;zeros(1,N)];
  26. indexis = [index;index;index];
  27. xdiscrete = [0 xx(:)' 0];
  28. idiscrete = [index(1)-xinc indexis(:)' index(N)+xinc];
  29. [mn,mx] = range2(xdiscrete);
  30. ypad = (mx-mn)/12; % MAGIC NUMBER: graph padding
  31. plot(idiscrete, xdiscrete, index, x, 'o');
  32. axis([index(1)-xinc, index(N)+xinc, mn-ypad, mx+ypad]);
  33. return