dtft.m

来自「DTFT计算源代码」· M 代码 · 共 28 行

M
28
字号
%- discrete input signal entered as a vector
%- a scalar number indicating the position n=0 of the input vector
%- an w vector where X(w) will be calculated

function eceDTFT(inputsigna,startingpoint,w)
n=0:(length(inputsigna)-1);
n=n+startingpoint;       % define the variable n for DTFT, the series x(n) begin with n=startingpoint
xn=inputsigna;           % define the input signal
Xw=xn*exp(-j*n'*w)       % DTFT
magx=abs(Xw);            % magnitude of X(w)
angx=angle(Xw);          % angle of X(w)
realx=real(Xw);          % real part of X(w)
imagx=imag(Xw);          % imaginary part of X(w)
subplot(2,2,1);plot(w,magx); % plot magnitude of X(w)
grid;
xlabel('w');title('magnitude of X(w)');ylabel('magnitude');
subplot(2,2,2);plot(w,angx);  % plot angle of X(w)
grid;
xlabel('w');title('angle of X(w)');ylabel('angle');
subplot(2,2,3);plot(w,realx);  % plot real part of X(w)
grid;
xlabel('w');title('real part of X(w)');ylabel('ReX(w) ');
subplot(2,2,4);plot(w,imagx);  % plot imaginary part of X(w)
grid;
xlabel('w');title('imaginary part of X(w)');ylabel('ImX(w) ') ;
En=abs(xn)*(abs(xn))'   % the energy of the signal in time domain
Ew= sum(Xw.*conj( Xw))/(2.*pi) % the energy of the signal in the frequency domain  

⌨️ 快捷键说明

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