1、代码
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 5.17 '); banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ------------------------------------------------------------------------------------- % X(k) is 10-point DFTs of real-valued sequence x(n) % X(k) = [10, -2+3j, 3+4j, 2-3j, 4+5j, 12, 4-5j, 2+3j, 3-4j, -2-3j] % N = 10 k=[0:9] % 1 y(n) = x((2-n))10 % ------------------------------------------------------------------------------------- k1 = [0:9]; Xk_DFT = [10, -2+3j, 3+4j, 2-3j, 4+5j, 12, 4-5j, 2+3j, 3-4j, -2-3j]; N1 = length(Xk_DFT); % length is 10 magXk_DFT = abs( [ Xk_DFT ] ); % DFT magnitude angXk_DFT = angle( [Xk_DFT] )/pi; % DFT angle realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.17.1 X(k), DFT of x(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(k1, magXk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of x(n), N=10'); grid on; subplot(2,2,3); stem(k1, angXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('angle(k)'); title('angle DFT of x(n), N=10'); grid on; subplot(2,2,2); stem(k1, realXk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of x(n), N=10'); grid on; subplot(2,2,4); stem(k1, imagXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of x(n), N=10'); grid on; [xn] = real(idft(Xk_DFT, N1)); % real-valued sequence n = [0 : N1-1]; % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ % 1st way to get y(n)-----circular shifft % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xn_cirfold = xn(mod(-n,N1)+1); m = 2; % shift yn1 = cirshftt(xn_cirfold, m, length(xn)); Xfk_DFT = dft(xn_cirfold, N1); magXfk_DFT = abs( [ Xfk_DFT ] ); % DFT magnitude angXfk_DFT = angle( [Xfk_DFT] )/pi; % DFT angle realXfk_DFT = real(Xfk_DFT); imagXfk_DFT = imag(Xfk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.17.1 X((-k)), DFT of x((-n))') set(gcf,'Color','white'); subplot(2,2,1); stem(k1, magXfk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of x((-n)), N=10'); grid on; subplot(2,2,3); stem(k1, angXfk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('angle(k)'); title('angle DFT of x((-n)), N=10'); grid on; subplot(2,2,2); stem(k1, realXfk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of x((-n)), N=10'); grid on; subplot(2,2,4); stem(k1, imagXfk_DFT); axis([0, 10, -5, 5.05]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of x((-n)), N=10'); grid on; % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ % 2ed way to get y(n)-----IDFT of Y(k) % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ k1 = [0:9]; Yk_DFT = exp(-j*2*pi*(2*k1)/10) .* Xk_DFT(mod(-k1, N1)+1); N1 = length(Yk_DFT); % length is 10 magYk_DFT = abs( [ Yk_DFT ] ); % DFT magnitude angYk_DFT = angle( [Yk_DFT] )/pi; % DFT angle realYk_DFT = real(Yk_DFT); imagYk_DFT = imag(Yk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.17.1 DFT(k) of y(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(k1, magYk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of y(n), N=10'); grid on; subplot(2,2,3); stem(k1, angYk_DFT); xlabel('k'); ylabel('angle(k)'); title('angle DFT of y(n), N=10'); grid on; subplot(2,2,2); stem(k1, realYk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of y(n), N=10'); grid on; subplot(2,2,4); stem(k1, imagYk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of y(n), N=10'); grid on; [yn2] = real(idft(Yk_DFT, N1)); n = [0 : N1-1]; figure('NumberTitle', 'off', 'Name', 'P5.17.1 x(n) & y(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(n, xn); xlabel('n'); ylabel('x(n)'); title('x(n), IDFT of X(k)'); grid on; subplot(2,2,2); stem(n, yn1); xlabel('n'); ylabel('y(n)'); title('y(n) by circular shift x((2-n))_N N=10'); grid on; subplot(2,2,3); stem(n, xn_cirfold); xlabel('n'); ylabel('x((-n))'); title('x((-n)) N=10'); grid on; subplot(2,2,4); stem(n, yn2); xlabel('n'); ylabel('y(n)'); title('y(n) by IDFT of Y(k)'); grid on;
运行结果:
4、代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 5.17 '); banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ------------------------------------------------------------------------------------- % X(k) is 10-point DFTs of real-valued sequence x(n) % X(k) = [10, -2+3j, 3+4j, 2-3j, 4+5j, 12, 4-5j, 2+3j, 3-4j, -2-3j] % N = 10 k=[0:9] % 4 y(n) = x(n) Circular-Conv x((-n))10 % ------------------------------------------------------------------------------------- k1 = [0:9]; Xk_DFT = [10, -2+3j, 3+4j, 2-3j, 4+5j, 12, 4-5j, 2+3j, 3-4j, -2-3j]; N1 = length(Xk_DFT); % length is 10 magXk_DFT = abs( [ Xk_DFT ] ); % DFT magnitude angXk_DFT = angle( [Xk_DFT] )/pi; % DFT angle realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.17.4 X(k), DFT of x(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(k1, magXk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of x(n), N=10'); grid on; subplot(2,2,3); stem(k1, angXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('angle(k)'); title('angle DFT of x(n), N=10'); grid on; subplot(2,2,2); stem(k1, realXk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of x(n), N=10'); grid on; subplot(2,2,4); stem(k1, imagXk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of x(n), N=10'); grid on; [xn] = real(idft(Xk_DFT, N1)); % real-valued sequence n = [0 : N1-1]; % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ % 1st way to get y(n)-----circular % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xn_cirfold = xn(mod(-n,N1)+1); yn1 = circonvt(xn, xn_cirfold, N1); % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ % 2ed way to get y(n)-----IDFT of Y(k) % +++++++++++++++++++++++++++++++++++++++++++++++++++++++ k1 = [0:9]; Xfk_DFT = dft(xn_cirfold, N1); Yk_DFT = Xk_DFT .* Xfk_DFT; N1 = length(Yk_DFT); % length is 10 magYk_DFT = abs( [ Yk_DFT ] ); % DFT magnitude angYk_DFT = angle( [Yk_DFT] )/pi; % DFT angle realYk_DFT = real(Yk_DFT); imagYk_DFT = imag(Yk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.17.4 DFT(k) of y(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(k1, magYk_DFT); xlabel('k'); ylabel('magnitude(k)'); title('magnitude DFT of y(n), N=10'); grid on; subplot(2,2,3); stem(k1, angYk_DFT); xlabel('k'); ylabel('angle(k)'); title('angle DFT of y(n), N=10'); grid on; subplot(2,2,2); stem(k1, realYk_DFT); xlabel('k'); ylabel('real (k)'); title('real DFT of y(n), N=10'); grid on; subplot(2,2,4); stem(k1, imagYk_DFT); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('k'); ylabel('imag (k)'); title('imag DFT of y(n), N=10'); grid on; [yn2] = real(idft(Yk_DFT, N1)); n = [0 : N1-1]; figure('NumberTitle', 'off', 'Name', 'P5.17.4 x(n) & y(n)') set(gcf,'Color','white'); subplot(2,2,1); stem(n, xn); xlabel('n'); ylabel('x(n)'); title('x(n), IDFT of X(k)'); grid on; subplot(2,2,2); stem(n, yn1); xlabel('n'); ylabel('y(n)'); title('y(n) by x(n) Circular-Conv x((-n))_N N=10'); grid on; %subplot(2,2,3); stem(n, xn_cirfold); %xlabel('n'); ylabel('x((-n))'); %title('x((-n)) N=10'); grid on; subplot(2,2,4); stem(n, yn2); xlabel('n'); ylabel('y(n)'); title('y(n) by IDFT of Y(k)'); grid on;
运行结果: