《DSP using MATLAB》Problem 2.7
1、代码:
function [xe,xo,m] = evenodd_cv(x,n) % % Complex signal decomposition into even and odd parts % ---------------------------------------------------- % [xe,xo,m] = evenodd_cv(x,n) % % %if any(imag(x) = 0) % error('x is a real sequence'); %end m = -fliplr(n); m1 = min([m,n]); m2 = max([m,n]); m = m1:m2; nm = n(1)-m(1); n1 = 1:length(n); x1 = zeros(1,length(m)); x1(n1+nm) = x; x = x1; xe = 0.5*(x + conj(fliplr(x))); xo = 0.5*(x - conj(fliplr(x)));
2、代码
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.7.2 \n\n'); [v, d] = version; fprintf(' MATLAB Version: %20s\n\n', v); fprintf(' Released Date: %17s\n\n', d); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Today is %7s, and Now is %20s \n\n', wkd2, time_stamp); %% ------------------------------------------------------------------------ n = [0:10]; x = 10 * exp( (-0.1+j*0.2*pi) * n ); [xe,xo,m] = evenodd_cv(x,n); figure('NumberTitle', 'off', 'Name', 'Problem 2.7 x(n)') set(gcf,'Color',[1,1,1]) % 改变坐标外围背景颜色 subplot(2,1,1); stem(n, real(x)); title('x sequence Real Part'); xlabel('n'); ylabel('Real[x(n)]') ; % axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(n, imag(x)); title('x sequence Imag Part'); xlabel('n'); ylabel('Imag[x(n)]'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.7 xe(m)') set(gcf,'Color',[1,1,1]) subplot(2,1,1); stem(m,real(xe)); title('Real Part of Even Sequence'); xlabel('m'); ylabel('Real[xe(m)]'); %axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(m,imag(xe)); title('Imag Part of Even Sequence'); xlabel('m'); ylabel('Imag[xe(m)]'); %axis([-10,10,0,1.2]) grid on figure('NumberTitle', 'off', 'Name', 'Problem 2.7 xo(m)') set(gcf,'Color','white') subplot(2,1,1); stem(m,real(xo)); title('Real Part of Odd Sequence'); xlabel('m'); ylabel('Real[xo(m)]'); %axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(m,imag(xo)); title('Imag Part of Odd Sequence'); xlabel('m'); ylabel('Imag[xo(m)]'); %axis([-10,10,0,1.2]) grid on % ----------------------------------------- % xe(-m) % ----------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 2.7 xe(-m)') set(gcf,'Color',[1,1,1]) subplot(2,1,1); stem(m,real(fliplr(xe))); title('Real Part of xe(-m)'); xlabel('m'); ylabel('Real[xe(-m)]'); %axis([-10,10,0,1.2]) grid on subplot(2,1,2); stem(m,imag(fliplr(xe))); title('Imag Part of xe(-m)'); xlabel('m'); ylabel('Imag[xe(-m)]'); %axis([-10,10,0,1.2]) grid on % ------------------------------------------------------ % xo(-m) % ------------------------------------------------------ figure('NumberTitle', 'off', 'Name', 'Problem 2.7 xo(-m)') set(gcf,'Color',[1,1,1]) subplot(2,1,1); stem(m,real(fliplr(xo))); title('Real Part of xo(-m)'); xlabel('m'); ylabel('Real[xo(-m)]'); grid on subplot(2,1,2); stem(m,imag(fliplr(xo))); title('Imag Part of xo(-m)'); xlabel('m'); ylabel('Imag[xo(-m)]'); grid on
运行结果:
牢记:
1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。