⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evenodd.m

📁 很多matlab的源代码
💻 M
字号:
function [e,o,n] = evenodd(x,t)
% EVENODD Even and odd parts of a signal.
%         
%         [E,O,T] = EVENODD(X,tn) generates the even and odd part of X
%	  tn is the CT or DT time index for x
%	  E, O are the even and odd parts of x over a symmetric duration T
%         If tn is not given, X is assumed to start at tn=0 at unit intervals.
%         If no ouput arguments are specified, the results are plotted
%	  NOTE: if sampling spacing=1, a DT signal is assumed for line plots
%
%         EVENODD (with no input arguments) invokes the following example:
%
%           % Plot x=tri((t-1)/2) and its even and odd parts
%           >>t=-1:.05:5;
%           >>y=tri((t-1)/2);
%           >>evenodd(y,t) 



% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998


if nargin==0, help evenodd,disp('Strike a key to see results of the example')
pause,t=-1:.05:5;y=tri((t-1)/2);evenodd(y,t);return,end

l=length(x);
if nargin<2,t=0:l-1;end
ts=t(2)-t(1);n0=max(abs(t));
n1=0:ts:n0+0.0001*ts;
n2=-fliplr(n1(2:length(n1)));
n=[n2 n1];
%n=-n0:ts:n0;
ln=length(n);
[mx,nx]=size(x);if nx==1,x=x.';end
xn=0*n;

i1=find(abs(n-t(1))<ts/1000);
%i2=find(abs(n-t(l))<ts/1000);
%xn(i1:i2)=x;
xn(i1:i1+l-1)=x;
xf=fliplr(xn);e=(xn+xf)/2;o=(xn-xf)/2;
if nx==1,e=e(:);o=o(:);n=n(:);end


%%%%%%%% Fix even part if signal is CT and causal signal %%%%%%%%%%%%%%%%%
if ts ~= 1
   i=find(abs(x)>100*eps);ind=i(1);
   if ~isempty(i)
         i1=i(1);i2=i(length(i));
%       if n1(i1)<=0 | n1(i2)>=0
       if n(i1)<=0 | n(i2)>=0
          i=find(abs(n)<100*eps);
             if ~isempty(i)
%                e(i)=0.5*e(i);
%                 e(i)=0.5*(e(i-1)+e(i+1));  
                if abs(0.5*x(ind)) > abs(0.5*(e(i-1)+e(i+1)))
                 e(i)=0.5*x(ind);
                  else
                 e(i)=0.5*(e(i-1)+e(i+1));
                end    
             end
       end
   end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



if nargout==0
vx=matverch;
if vx < 4, eval('clg');else,eval('clf');end

dt=0;if abs(ts-1)<100*eps,dt=1;end
yl=max([abs(max(x)) abs(min(x))]);
s=1.2*[-n0 n0 -yl yl];
subplot(221),axis(s),
if dt==0,plot(n,xn),else, dtplot(n,xn,'o');end
axis(s),axesn,title('Given signal  =  x')
subplot(222),axis(s),
if dt==0,plot(n,e),else, dtplot(n,e,'o');end
axis(s),axesn,title('Even part  =  xe'),
subplot(223),axis(s),
if dt==0,plot(n,o),else, dtplot(n,o,'o');end
axis(s),axesn,title('Odd part  =  xo');
subplot(224),axis(s),
if dt==0,plot(n,xn),else, dtplot(n,xn,'o');end
axis(s),axesn,title('Sum  xe+xo  =  x')
if vx<4,pause,end
subplot,hold off
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -