function n = rebound(x,N) %n = rebound(x,N) % Finds noise margins of e.g. a clock signal % due to ringing on the inside of the signal. % The inside is important because this ringing % may cause false triggering of logic device. % Inputs: % 'x' the periodic signal of at least 1.5 cycles. % 'N' the period of 'x' in samples. % Output: % 'n' the vector containing the location in 'x' % of the peak(s) of ringing in the first % half-cycle. The size of 'n' is the number % of inflection points minus 2 present in the half % cycle. % Example: (5 inflection points, length(n)=2) % t = [0.5:0.01:2]; % a = 1-0.8*sin(t*5)-0.1*sin(3*t*5)-0.25*cos(5*t*5); % n = rebound(a,126); % plot(t,a,'b',t(n),a(n),'r*'); grid on; % % Now includes needed "findpeak.m" function in M-file. % Last edited by Colin Joye, 7/20/03 x1 = x/max(abs(x)); % normalize. xm = x-mean([max(x1) min(x1)]); % remove offset. xm = xm/max(abs(xm)); % normalize. xd = abs(diff(xm)); nh = findpeak(xd,ceil(N/2)); if length(nh)<2 | max(nh)>length(xd), nh=[1 2]; end xN = xd(nh(1):nh(2)); % one cycle. ff = diff(xN)>0; nx = find(diff(ff)>0); n = nx(2:2:(end-1)) + nh(1); %--------------------------- function k = findpeak(x,w) %k = findpeak(x,w) finds local periodic maxima % in signal 'x' by finding the location of the % peak every 'w' samples. % Input: % 'x' the signal vector. % 'w' is the window width in samples. % length(x) must greater than or equal to 'w' % Outputs: % 'k' the locations in vector 'x' of local maxima. % % Last edited by Colin Joye, 6/19/2002 n=0;f=0; k=find(max(x(1:w))==x(1:w)); k=k(1); while (w+n)<=length(x), n=n+w; r=(1+n):(w+n); if r(end)>length(x), r=(1+n):length(x); end if length(r)>0, f=n+find(max(x(r))==x(r)); k=[k f(1)]; end end % ----- End findpeak.m ---------- % ----- End rebound.m ----------