坚持到第10章了,继续努力!

代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Exameple 10.1 \n\n'); time_stamp = datestr(now, 31);
[wkd1, wkd2] = weekday(today, 'long');
fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);
%% ------------------------------------------------------------------------ clear; close all; % Example parameters
B = 2; N = 500000; n = [1:N];
xn = (1/3)*(sin(n/11) + sin(n/31) + cos(n/67)); clear n; % Quantization error analysis
[H1, H2, Q, estat] = StatModelR(xn, B, N); % Compute histograms
H1max = max(H1); H1min = min(H1); % Max and Min of H1
H2max = max(H2); H2min = min(H2); % Max and Min of H2 Hf1 = figure('units', 'inches', 'position', [1, 1, 8, 6], ...
'paperunits', 'inches', 'paperposition', [0, 0, 6, 4], ...
'NumberTitle', 'off', 'Name', 'Exameple 10.1a');
set(gcf,'Color','white');
TF = 10;
title('Normalized error e1 and e2');
subplot(2, 1, 1);
bar(Q, H1); axis([-0.5, 0.5, -0.001, 4/128]); grid on; xlabel('Normalized error e1'); ylabel('Distribution of e1 ', 'vertical', 'baseline');
set(gca, 'YTickMode', 'manual', 'YTick', [0, [1:1:4]/128] );
text(-0.45, 0.030, sprintf('SAMPLE SIZE N = %d', N));
text(-0.45, 0.025, sprintf(' ROUNDED TO B = %d BITS', B));
text(-0.45, 0.020, sprintf(' MEAN = %.4e', estat(1)));
text(0.10, 0.030, sprintf('MIN PROB BAR HEIGHT = %f', H1min)) ;
text(0.10, 0.025, sprintf('MAX PROB BAR HEIGHT = %f', H1max)) ;
text(0.10, 0.020, sprintf(' SIGMA = %f', estat(2))) ; subplot(2, 1, 2);
bar(Q, H2); axis([-0.5, 0.5, -0.001, 4/128]); grid on;
%title('Normalized error e2');
xlabel('Normalized error e2'); ylabel('Distribution of e2', 'vertical', 'baseline');
set(gca, 'YTickMode', 'manual', 'YTick', [0, 1:1:4]/128 );
text(-0.45, 0.030, sprintf('SAMPLE SIZE N = %d', N));
text(-0.45, 0.025, sprintf(' ROUNDED TO B = %d BITS', B));
text(-0.45, 0.020, sprintf(' MEAN = %.4e', estat(3)));
text(0.10, 0.030, sprintf('MIN PROB BAR HEIGHT = %f', H2min)) ;
text(0.10, 0.025, sprintf('MAX PROB BAR HEIGHT = %f', H2max)) ;
text(0.10, 0.020, sprintf(' SIGMA = %f', estat(4))) ; %% ---------------------------------------------------------------------
%% B = 6
%% ---------------------------------------------------------------------
% Example parameters
B = 6; N = 500000; n = [1:N];
xn = (1/3)*(sin(n/11) + sin(n/31) + cos(n/67)); clear n; % Quantization error analysis
[H1, H2, Q, estat] = StatModelR(xn, B, N); % Compute histograms
H1max = max(H1); H1min = min(H1); % Max and Min of H1
H2max = max(H2); H2min = min(H2); % Max and Min of H2 Hf2 = figure('units', 'inches', 'position', [1, 1, 8, 6], ...
'paperunits', 'inches', 'paperposition', [0, 0, 6, 4], ...
'NumberTitle', 'off', 'Name', 'Exameple 10.1b');
set(gcf,'Color','white');
TF = 10; subplot(2, 1, 1);
bar(Q, H1); axis([-0.5, 0.5, -0.001, 4/128]); grid on;
title('Normalized error e1'); ylabel('Distribution of e1 ', 'vertical', 'baseline');
set(gca, 'YTickMode', 'manual', 'YTick', [0, 1:1:4]/128 );
text(-0.45, 0.030, sprintf('SAMPLE SIZE N = %d', N));
text(-0.45, 0.025, sprintf(' ROUNDED TO B = %d BITS', B));
text(-0.45, 0.020, sprintf(' MEAN = %.4e', estat(1)));
text(0.10, 0.030, sprintf('MIN PROB BAR HEIGHT = %f', H1min)) ;
text(0.10, 0.025, sprintf('MAX PROB BAR HEIGHT = %f', H1max)) ;
text(0.10, 0.020, sprintf(' SIGMA = %.7f', estat(2))) ; subplot(2, 1, 2);
bar(Q, H2); axis([-0.5, 0.5, -0.001, 4/128]); grid on;
title('Normalized error e2'); ylabel('Distribution of e2', 'vertical', 'baseline');
set(gca, 'YTickMode', 'manual', 'YTick', [0, 1:1:4]/128 );
text(-0.45, 0.030, sprintf('SAMPLE SIZE N = %d', N));
text(-0.45, 0.025, sprintf(' ROUNDED TO B = %d BITS', B));
text(-0.45, 0.020, sprintf(' MEAN = %.4e', estat(3)));
text(0.10, 0.030, sprintf('MIN PROB BAR HEIGHT = %f', H2min)) ;
text(0.10, 0.025, sprintf('MAX PROB BAR HEIGHT = %f', H2max)) ;
text(0.10, 0.020, sprintf(' SIGMA = %.7f', estat(4))) ;

  运行结果:

B=2的结果如第1张图所示,很明显,即使误差看起来均匀分布,但误差采样序列不是独立的。对应B=6的
结果如第2张图所示,当B≥6时,结果满足误差模型假设条件。

《DSP using MATLAB》示例 Example 10.1的更多相关文章

  1. DSP using MATLAB 示例 Example3.10

    用到的性质 上代码: n = -5:10; x = rand(1,length(n)) + j * rand(1,length(n)); k = -100:100; w = (pi/100)*k; % ...

  2. DSP using MATlAB 示例Example2.10

    上代码 % noise sequence 1 x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3:3]; % given signal x(n) [y,ny] = sigshi ...

  3. DSP using MATLAB 示例Example3.21

    代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*a ...

  4. DSP using MATLAB 示例 Example3.19

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...

  5. DSP using MATLAB示例Example3.18

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fou ...

  6. DSP using MATLAB 示例 Example3.13

    上代码: w = [0:1:500]*pi/500; % freqency between 0 and +pi, [0,pi] axis divided into 501 points. H = ex ...

  7. DSP using MATLAB 示例 Example3.12

    用到的性质 代码: n = -5:10; x = sin(pi*n/2); k = -100:100; w = (pi/100)*k; % freqency between -pi and +pi , ...

  8. DSP using MATLAB 示例 Example3.11

    用到的性质 上代码: n = -5:10; x = rand(1,length(n)); k = -100:100; w = (pi/100)*k; % freqency between -pi an ...

  9. DSP using MATLAB 示例Example3.8

    代码: x = rand(1,11); n = 0:10; k = 0:500; w = (pi/500)*k; % [0,pi] axis divided into 501 points. X = ...

  10. DSP using MATLAB 示例Example3.7

    上代码: x1 = rand(1,11); x2 = rand(1,11); n = 0:10; alpha = 2; beta = 3; k = 0:500; w = (pi/500)*k; % [ ...

随机推荐

  1. VS2010/MFC编程入门之二十七(常用控件:图片控件Picture Control)

    上一节中鸡啄米讲的是滚动条控件,本节主要讲一种简单实用的控件,图片控件Picture Control.我们可以在界面某个位置放入图片控件,显示图片以美化界面. 图片控件简介 图片控件和前面讲到的静态文 ...

  2. BUCT20180814邀请赛 Solution

    A:SUM 水. #include<bits/stdc++.h> using namespace std; #define N 100010 typedef long long ll; i ...

  3. 20165207 实验一 Java开发环境的熟悉

    20165207 实验一 Java开发环境的熟悉 一.实验报告封面 课程:Java程序设计 班级:1652 姓名:李天林 学号:20165207 实验日期:2018年4月2日 实验序号:一 实验名称: ...

  4. 应用连接mysql8.0注意事项

    mysql8.0在安装过程中会让你选择一个Authentication Method,如果你选择上面的更强的授权机制,那么就会出现下面的情况 图片来源:https://blog.csdn.net/qq ...

  5. C#反射——简单反射操作类的封装

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Re ...

  6. 【运维技术】kafka三实例集群环境搭建及测试使用

    kafka三实例集群环境搭建及测试使用 单机搭建分为两部分:1. 软件安装启动 2. 软件配置 软件安装启动: # 切换到目录 cd /app # 获取kafka最新安装包,这边使用的是镜像地址,可以 ...

  7. mysql日期和JDBC查询出来的结果相差8小时

    数据库时间:2017-11-08 16:30:00 查询出来: 2017-11-09 00:30:00 问题:数据库时区,和JDBC连接时区设置问题. set global time_zone = ' ...

  8. [Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1

    真tm坑. QString execStr = QString("SELECT * FROM [Log] WHERE [username]=\"yyy\" ") ...

  9. POJ 1833 排序

    http://poj.org/problem?id=1833 题意: 给出一个排序,求出它之后的第k个排序. 思路: 排序原理: 1.如果全部为逆序时,说明已经全部排完了,此时回到1~n的排序. 2. ...

  10. HTML 入门1

    HTML   入门1  一,什么是HTML 超文本标记语言 二,如何写一个HTML文件? 1 通过sublime的文件->新建->保存 "文件名.html"格式 2,在 ...