《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 ...
随机推荐
- centos6.5 安装php-5.6.31
1 从PHP官网下载所需要的PHP版本 下载地址: http://php.net/get/php-5.6.31.tar.gz/from/a/mirror 把下载好的文件上传到服务器 2 安装PHP ...
- Unity中物体碰撞后去掉相互之间的反弹力
最近自制了一个的角色控制器(没有重力的角色)时发现,角色碰撞到墙壁之后会有一个小小的反弹力导致角色有一个微弱的反弹位移,这样给人一种不好的感觉.研究了一下,除了限制坐标轴( Rigidbody---C ...
- mybatis if标签判断字符串相等
mybatis 映射文件中,if标签判断字符串相等,两种方式: 因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串sex变量是否是字符串Y的时候, <if test=" ...
- 【原创】QT简单计算器
代码 //main.cpp #include "calculator_111.h" #include <QtWidgets/QApplication> int main ...
- Oracle Rman 控制RMAN的备份时间,减少IO消耗
一.问题描述 由于服务器配置不高,备份策略为周末全备.周一至周六差异备份. 平时服务器CPU使用30%左右. 全备份时,开启两个通道,CPU达到70%-80%左右,业务不卡顿.不掉单,session不 ...
- sqlalchemy(一)常用连接参数及包
简介: 本文默认你已经有了一定的数据库基础.我们不喜欢写原生SQL语句,那个写着费劲,日常开发时候,我们怎么CRUD数据库呢?一般使用ORM,对象关系映射(英语:Object Relational M ...
- vue引用样式
cnpm i sass-loader node-sass -D <link rel="stylesheet" href="./static/reset.css&qu ...
- 双引号与尖括号的区别 and 相对路径与绝对路径
包含头文件的时候,如果包含的是自己写的头文件是用" " .如果是包含系统的头文件,一般用<>. 相对路径与绝对路径
- 第三节 java 函数的封装方法 以及 访问封装内容
从我们的选择排序和冒泡排序里我们可以看到有很多相同的代码, 我们 可以把这些相同的代码提取出来封装为方法:比如我们的判 断交换和遍历输出: 抽取1: public static void PanDua ...
- Positioning
boxPostion.html <html><head> <title>Box Position</title><meta charset=& ...