function [XX,YY]=plotspec(X,SR,N,FM)
% [XX,YY] = plotspec(X, SR, N, FM)            Plot the magnitude spectrum of X.
%	Use an N-point fft (defaults to 1024) and treat the maximum 
%	frequency as SR (defaults to 2pi). Only display frequencies up
%	to FM (defaults to SR/2)
%	XX and YY output the spectrum ; plot(XX,YY) reproduces it.
% dpwe 1994jun21.  Uses dB.m and built-ins 'fft', 'plot'.  After plotiir.m

% handle optional args
if(exist('SR')==0)
  SR = 2*pi;
end
if(exist('N')==0)
  N = 1024;
end
if(exist('FM')==0)
  FM = SR/2;
end

spec = fft(X, N)/N;

ff = (0:(N-1))*SR/N;
xx = 1:(N*FM/SR);
%plot(ff(xx),dB(spec(xx)));
XX=ff(xx);
%YY=dB(spec(xx));
YY=max(-100,20*log10(abs(spec(xx))));
plot(XX,YY);
