1、代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 2.2.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);
%% ------------------------------------------------------------------------ num = 100000;
x1 = 0 + (2-0)*rand(num,1);
x_axis = min(x1):0.02:max(x1); figure('NumberTitle', 'off', 'Name', 'Problem 2.2.1 hist');
set(gcf,'Color','white');
%hist(x1,x_axis);
hist(x1,100);
title('Uniformly Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('x1(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.1 bar');
set(gcf,'Color','white');
%[counts,binlocal] = hist(x1, x_axis);
[counts,binlocal] = hist(x1, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Uniformly Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('x1(n)'); grid on;

  运行结果:

2、代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 2.2.2 \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);
%% ------------------------------------------------------------------------ num = 10000; mean_val=10; variance=10;
x2 = mean_val + sqrt(variance)*randn(num,1);
x_axis = min(x2):0.02:max(x2); figure('NumberTitle', 'off', 'Name', 'Problem 2.2.2 hist');
set(gcf,'Color','white');
%hist(x1,x_axis);
hist(x2,100);
title('Gaussian Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('x2(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.2 bar');
set(gcf,'Color','white');
%[counts,binlocal] = hist(x1, x_axis);
[counts,binlocal] = hist(x2, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Gaussian Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('x2(n)'); grid on;

  运行结果:

3、代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 2.2.3 \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);
%% ------------------------------------------------------------------------ num = 100000; n_x1 = 0:num-1;
x1 = 0 + (2-0)*rand(num,1);
%x_axis = min(x2):0.02:max(x2);
[x11,n_x11] = sigshift(x1,n_x1,1)
[x3,n_x3] = sigadd (x1, n_x1, x11, n_x11) %% -------------------------------- START --------------------------------------------
% x1(n)'s hist and bar function
figure('NumberTitle', 'off', 'Name', 'Problem 2.2.3');
set(gcf,'Color','white');
hist(x1,100);
title('Uniformly Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('x1(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.3');
set(gcf,'Color','white');
[counts,binlocal] = hist(x1, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Uniformly Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('x1(n)'); grid on;
%% ---------------------------------- END ------------------------------------------------ %% -------------------------------- START --------------------------------------------
% x3(n) = x1(n) + x1(n-1) hist and bar function
figure('NumberTitle', 'off', 'Name', 'Problem 2.2.3');
set(gcf,'Color','white');
hist(x3,100);
title('Uniformly Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('x3(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.3');
set(gcf,'Color','white');
[counts,binlocal] = hist(x3, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Uniformly Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('x3(n)'); grid on;
%% ---------------------------------- END ------------------------------------------------

  运行结果:

两个均匀分布的序列相加,结果呈现三角形分布了。

4、代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 2.2.4 \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);
%% ------------------------------------------------------------------------ num = 100000; n_y = 0:num-1;
y1 = -0.5 + (0.5+0.5)*rand(num,1);
y2 = -0.5 + (0.5+0.5)*rand(num,1);
y3 = -0.5 + (0.5+0.5)*rand(num,1);
y4 = -0.5 + (0.5+0.5)*rand(num,1); %x_axis = min(x2):0.02:max(x2);
[x41,n_y11] = sigadd (y1, n_y, y2, n_y);
[x42,n_y12] = sigadd (y3, n_y, y4, n_y);
[x4,n_x4] = sigadd (x41, n_y11, x42, n_y12); %% -------------------------------- START --------------------------------------------
% x1(n)'s hist and bar function
figure('NumberTitle', 'off', 'Name', 'Problem 2.2.4');
set(gcf,'Color','white');
hist(y1,100);
title('Uniformly Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('y1(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.4');
set(gcf,'Color','white');
[counts,binlocal] = hist(y1, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Uniformly Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('y1(n)'); grid on;
%% ---------------------------------- END ------------------------------------------------ %% -------------------------------- START --------------------------------------------
% x3(n) = x1(n) + x1(n-1) hist and bar function
figure('NumberTitle', 'off', 'Name', 'Problem 2.2.4');
set(gcf,'Color','white');
hist(x4,100);
title('Uniformly Distributed Random Numbers (using hist)');
xlabel('n'); ylabel('x4(n)'); grid on; figure('NumberTitle', 'off', 'Name', 'Problem 2.2.4');
set(gcf,'Color','white');
[counts,binlocal] = hist(x4, 100);
counts = counts/num;
bar(binlocal, counts, 1); title('Uniformly Distributed Random Numbers (using bar)');
xlabel('n'); ylabel('x4(n)'); grid on;
%% ---------------------------------- END ------------------------------------------------

  运行结果:

4个均匀分布的随机序列相加,呈现正态分布的特征了。

《DSP using MATLAB》Problem 2.2的更多相关文章

  1. 《DSP using MATLAB》Problem 7.27

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

  2. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  3. 《DSP using MATLAB》Problem 7.25

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

  4. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

  5. 《DSP using MATLAB》Problem 7.23

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...

  6. 《DSP using MATLAB》Problem 7.16

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

  7. 《DSP using MATLAB》Problem 7.15

    用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  8. 《DSP using MATLAB》Problem 7.14

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

  9. 《DSP using MATLAB》Problem 7.13

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

  10. 《DSP using MATLAB》Problem 7.12

    阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. SEO笔记:Anatomy of a URL

    Dr. Peter J. Meyers 原文链接:https://moz.com/blog/seo-cheat-sheet-anatomy-of-a-url 原文主要通过对比讲解 SEO优化后的URL ...

  2. 手把手教你学node.js 之使用 eventproxy 控制并发

    使用 eventproxy 控制并发 目标 建立一个 lesson4 项目,在其中编写代码. 代码的入口是 app.js,当调用 node app.js 时,它会输出 CNode(https://cn ...

  3. 六.__FILE__ , __LINE__ 与调试日志

    很多人可能不知道,C\C++编译器提供了一套针对代码文件的宏定义,它们能够帮助开发者更好的定位代码的BUG. __FILE__ 该宏定义是一个字符串,存储着当前代码文件的完整路径 __LINE__ 该 ...

  4. P1131 [ZJOI2007]时态同步(树形dp)

    P1131 [ZJOI2007]时态同步 设$f[i]$为与$i$与最远的点的距离 在dfs时每次更新的时候顺便统计一下长度,不同的话就改成最长的那条并更新答案 #include<iostrea ...

  5. 20145204 《Java程序设计》第四周学习总结

    20145204 <Java程序设计>第四周学习总结 教材学习内容总结 继承 什么时候使用继承? 当多个类中出现重复定义的行为(即多个类中出现重复的代码)时,就把相同的程序代码提成为父类. ...

  6. Mac下将C程序创建为动态链接库再由另一个C程序调用

    写C的时候需要调用之前的一个C程序,想用动态链接库的方式.Mac下的动态链接库是dylib,与Linux下的.os或Windows下的.dll不同.由于之前没有接触过,所以翻了大量的博客,然而在编译过 ...

  7. Javaworkers团队最终项目总结

    Javaworkers团队最终项目总结 小组成员 20145205武钰 20145222黄亚奇 20145235李涛 20145103冯文华 团队项目总结 案例提出及工程用时 本次项目由十一到十六周共 ...

  8. shell判断文件,目录是否存在或者具有权限的代码

    核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的 ...

  9. HDU 6315 Naive Operations(线段树+区间维护)多校题解

    题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...

  10. A TLS packet with unexpected length was received 解决方法

    参考:A TLS packet with unexpected length was received. 系统环境 主系统 OS X,虚拟机 Ubuntu 14.04 64bit. 问题描述 在git ...