《DSP using MATLAB》Problem 5.19



代码:
function [X1k, X2k] = real2dft(x1, x2, N)
%% ---------------------------------------------------------------------
%% DFT of two Real-Valued N-Point sequence x1(n) and x2(n)
%% ---------------------------------------------------------------------
%% [X1, X2] = real2dft(x1, x2, N)
%% X1k = n-point DFT of x1
%% X2k = n-point DFT of x2
%% x1 = sequence of length <= N
%% x2 = sequence of length <= N
%% N = length of DFT % ----------------------------------------
% if length of x1 and x2 < N,
% then padding zeros
% ----------------------------------------
if ( length(x1) < N)
x1 = [x1 zeros(1, N-length(x1))];
end if ( length(x2) < N)
x2 = [x2 zeros(1, N-length(x2))];
end x = x1 + j * x2; N = length(x); k = 0:(N-1); Xk_DFT = dft(x, N);
Xk_DFT_fold = Xk_DFT(mod_1(-k,N)+1); Xk_CCS = 0.5*(Xk_DFT + conj(Xk_DFT_fold));
Xk_CCA = 0.5*(Xk_DFT - conj(Xk_DFT_fold)); X1k = Xk_CCS;
X2k = Xk_CCA;
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.19 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ---------------------------------------------------------------------------------
% X(k) is N-point DFTs of N-point Complex-valued sequence x(n)
% x(n) = xR(n) + j xI(n)
% xR(n) and xI(n) are real and image parts of x(n);
% DFT[xR]=Xccs(k) DFT[j*xI]=Xcca(k)
%
% Xccs = 0.5*[X(k)+ X*((-k))] Xcca = 0.5*[X(k) - X*((-k))]
%
% ---------------------------------------------------------------------------------
n = [0:39];
x1 = cos(0.1*pi*n); % N=40 real-valued sequence
x2 = sin(0.2*pi*n); % N=40 real-valued sequence x = x1 + j * x2; N = length(x); k = 0:(N-1); Xk_DFT = dft(x, N);
Xk_DFT_fold = Xk_DFT(mod_1(-k,N)+1); 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); magXk_DFT_fold = abs( [ Xk_DFT_fold ] ); % DFT magnitude
angXk_DFT_fold = angle( [Xk_DFT_fold] )/pi; % DFT angle
realXk_DFT_fold = real(Xk_DFT_fold);
imagXk_DFT_fold = imag(Xk_DFT_fold); % --------------------------------------------------------
% Calculater one N-point DFT to get
% two N-point DFT
% --------------------------------------------------------
[X1k_DFT, X2k_DFT] = real2dft(x1, x2, N); magX1k_DFT = abs( [ X1k_DFT ] ); % DFT magnitude
angX1k_DFT = angle( [X1k_DFT] )/pi; % DFT angle
realX1k_DFT = real(X1k_DFT);
imagX1k_DFT = imag(X1k_DFT); magX2k_DFT = abs( [ X2k_DFT ] ); % DFT magnitude
angX2k_DFT = angle( [X2k_DFT] )/pi; % DFT angle
realX2k_DFT = real(X2k_DFT);
imagX2k_DFT = imag(X2k_DFT); % -------------------------------------------------------
% Get DFT of xR and xI directorly
% -------------------------------------------------------
XRk_DFT = dft(x1, N);
XIk_DFT = dft(j*x2, N); magXRk_DFT = abs( [ XRk_DFT ] ); % DFT magnitude
angXRk_DFT = angle( [XRk_DFT] )/pi; % DFT angle
realXRk_DFT = real(XRk_DFT);
imagXRk_DFT = imag(XRk_DFT); magXIk_DFT = abs( [ XIk_DFT ] ); % DFT magnitude
angXIk_DFT = angle( [XIk_DFT] )/pi; % DFT angle
realXIk_DFT = real(XIk_DFT);
imagXIk_DFT = imag(XIk_DFT); figure('NumberTitle', 'off', 'Name', 'P5.19 xR(n) and xI(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n, x1);
xlabel('n'); ylabel('x1');
title('real part of x(n), cos(0.1\pin), N=40'); grid on;
subplot(2,1,2); stem(n, x2);
xlabel('n'); ylabel('x2');
title('imag part of x(n), sin(0.2\pin), N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 X(k), DFT of x(n)')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magXk_DFT);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude DFT of x(n), N=40'); grid on;
subplot(2,2,3); stem(k, angXk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle DFT of x(n), N=40'); grid on;
subplot(2,2,2); stem(k, realXk_DFT);
xlabel('k'); ylabel('real (k)');
title('real DFT of x(n), N=40'); grid on;
subplot(2,2,4); stem(k, imagXk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag DFT of x(n), N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 X((-k))_N')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magXk_DFT_fold);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude X((-k)), N=40'); grid on;
subplot(2,2,3); stem(k, angXk_DFT_fold);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle X((-k)), N=40'); grid on;
subplot(2,2,2); stem(k, realXk_DFT_fold);
xlabel('k'); ylabel('real (k)');
title('real X((-k)), N=40'); grid on;
subplot(2,2,4); stem(k, imagXk_DFT_fold);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag X((-k)), N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 X1(k) by real2dft')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magX1k_DFT);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude, N=40'); grid on;
subplot(2,2,3); stem(k, angX1k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle, N=40'); grid on;
subplot(2,2,2); stem(k, realX1k_DFT);
xlabel('k'); ylabel('real (k)');
title('real, N=40'); grid on;
subplot(2,2,4); stem(k, imagX1k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag, N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 X2(k) by real2dft')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magX2k_DFT);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude, N=40'); grid on;
subplot(2,2,3); stem(k, angX2k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle, N=40'); grid on;
subplot(2,2,2); stem(k, realX2k_DFT);
xlabel('k'); ylabel('real (k)');
title('real, N=40'); grid on;
subplot(2,2,4); stem(k, imagX2k_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag, N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 XR(k) by direct')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magXRk_DFT);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude, N=40'); grid on;
subplot(2,2,3); stem(k, angXRk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle, N=40'); grid on;
subplot(2,2,2); stem(k, realXRk_DFT);
xlabel('k'); ylabel('real (k)');
title('real, N=40'); grid on;
subplot(2,2,4); stem(k, imagXRk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag, N=40'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.19 XI(k) by direct')
set(gcf,'Color','white');
subplot(2,2,1); stem(k, magXIk_DFT);
xlabel('k'); ylabel('magnitude(k)');
title('magnitude, N=40'); grid on;
subplot(2,2,3); stem(k, angXIk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle, N=40'); grid on;
subplot(2,2,2); stem(k, realXIk_DFT);
xlabel('k'); ylabel('real (k)');
title('real, N=40'); grid on;
subplot(2,2,4); stem(k, imagXIk_DFT);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag, N=40'); grid on;
运行结果:
复数序列的实部和虚部

复数序列的DFT,X(k)

X((-k))

直接计算实部和虚部的DFT,XR(k)和XI(k)


利用函数real2dft计算实部和虚部对应的DFT,Xccs(k)和Xcca(k)


结论:
如果X(k)是N点复数序列x(n)的N点DFT,x(n)=xR(n)+jxI(n),那么有
DFT[xR]=Xccs(k) DFT[j*xI]=Xcca(k)
实部序列的DFT是复数序列的DFT的共轭圆周对称分量
虚部序列的DFT是复数序列的DFT的共轭圆周反对称分量。
《DSP using MATLAB》Problem 5.19的更多相关文章
- 《DSP using MATLAB》 Problem 3.19
先求模拟信号经过采样后,对应的数字角频率: 明显看出,第3种采样出现假频了.DTFT是以2π为周期的,所以假频出现在10π-2kπ=0处. 代码: %% ----------------------- ...
- 《DSP using MATLAB》Problem 2.19
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 8.19
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 5.18
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...
- 《DSP using MATLAB》Problem 5.5
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.4
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.3
这段时间爬山去了,山中林密荆棘多,沟谷纵横,体力增强不少. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 4.23
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
随机推荐
- 网口扫盲二:Mac与Phy组成原理的简单分析
1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. MAC(Medi ...
- linux系统监控与硬盘分区/格式化/文件系统管理
1.系统监控 1) 系统监视和进程控制的工具----> Top 与 free 类似于windows的资源管理器. 进程运行的三种状态: tips: 进程(Process)是计 ...
- xshell提示必须安装最新的更新
今天大家的xshell基本都出了这个问题 调整时间,调整到比较前的时间,打开xshell即可. 然后工具->选项 把更新去了
- 【原创】paintEvent()函数显示文本
[代码] void MainWindow::paintEvent(QPaintEvent*) { QPainter p(this); QRect r; p.setPen(Qt::red); p.dra ...
- 【资料收集】QT学习资料
几个专栏 Qt学习之路(3):Hello, world!(续) - 豆子空间 - 51CTO技术博客 http://devbean.blog.51cto.com/448512/194137 Qt 学习 ...
- 【转】用深度学习做crowd density estimation
本博文主要是CVPR2016的<Single-Image Crowd Counting via Multi-Column Convolutional Neural Network>这篇文章 ...
- (C/C++学习笔记) 三. 作用域和可见性
三. 作用域和可见性 ● 标识符的作用域 标识符的作用域是标识符在程序源代码中的有效范围,从小到大分为函数原型作用域.块作用域(局部作用域),文件作用域(全局作用域). 1. 函数原型作用域 函数原型 ...
- Cracking The Coding Interview 4.1
//Implement a function to check if a tree is balanced. For the purposes of this question, a balanced ...
- powerdesigner远程连接数据库
1. dabatase-->configure connections 2.新建连接 3.配置TNS连接测试 4.出现异常及处理 Could not Initialize JavaVM! 出现这 ...
- el-container 实践上的布局问题
当自己利用element-ui上面的例子来实现整体布局的时候, 就是自己分开成单独的vue组件时,发现布局是不对的,效果是这样的: 代码是这样的,代码一模一样,只是拆开了各个组件,如下图: 后来发现是 ...