代码:

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的更多相关文章

  1. 《DSP using MATLAB》 Problem 3.19

    先求模拟信号经过采样后,对应的数字角频率: 明显看出,第3种采样出现假频了.DTFT是以2π为周期的,所以假频出现在10π-2kπ=0处. 代码: %% ----------------------- ...

  2. 《DSP using MATLAB》Problem 2.19

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  3. 《DSP using MATLAB》Problem 8.19

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  4. 《DSP using MATLAB》Problem 7.16

    使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  5. 《DSP using MATLAB》Problem 5.18

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...

  6. 《DSP using MATLAB》Problem 5.5

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  7. 《DSP using MATLAB》Problem 5.4

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  8. 《DSP using MATLAB》Problem 5.3

    这段时间爬山去了,山中林密荆棘多,沟谷纵横,体力增强不少. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  9. 《DSP using MATLAB》Problem 4.23

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

随机推荐

  1. tensorflow之word2vec_basic代码研究

    源代码网址: https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/word2vec/wor ...

  2. UVA LA 3983 - Robotruck DP,优先队列 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. day15 装饰器

    关于函数的装饰器 1 .装饰器,(难点,重点) 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args,**kwargs) ...

  4. OPENWRT安装配置指南之 17.01.4 LEDE

    简介 这个东西,需要看简介的就不要看下去了. 下面已刚刷进去,路由IP地址为192.168.1.1为例开始配置. 浏览器访问192.168.1.1,无密码. 一:配置上网 不管你是什么方式上网,请根据 ...

  5. (C/C++学习笔记) 二. 数据类型

    二. 数据类型 ● 数据类型和sizeof关键字(也是一个操作符) ※ 在现代半导体存储器中, 例如在随机存取存储器或闪存中, 位(bit)的两个值可以由存储电容器的两个层级的电荷表示(In mode ...

  6. [leetcode整理]

    =======简单 leetcode164 Maximum Gap sort两次 =======有参考 330 Patching Array 98 Validate Binary Search Tre ...

  7. Centos7安装ansible

    CentOS下部署Ansible自动化工具 1.确保机器上安装的是 Python 2.6 或者 Python 2.7 版本: python -V 2.查看yum仓库中是否存在ansible的rpm包 ...

  8. kubenetes pv(nfs) pvc 搭建

    1:nfs-server的搭建. install the NFS Server: sudo apt install nfs-kernel-server 2:配置server. vim /etc/exp ...

  9. 一个灵活的AssetBundle打包工具

      尼尔:机械纪元 上周介绍了Unity项目中的资源配置,今天和大家分享一个AssetBundle打包工具.相信从事Unity开发或多或少都了解过AssetBundle,但简单的接口以及众多的细碎问题 ...

  10. 关于selenium实现滑块验证

    关于selenium实现滑块验证 python2.7+selenium2实现淘宝滑块自动认证参考链接:https://blog.csdn.net/ldg513783697/article/detail ...