《DSP using MATLAB》Problem 2.2

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的更多相关文章
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.15
用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.14
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.13
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.12
阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- Git 系列——第一步安装 Git
之前也没有用过什么版本控制的工具,唯一用过的就是 SVN 了,不过也只是简单的使用而已,比如写好代码就签入,没了?是的,没了. 于是接触到了 Git 这个分布式版本控制软件,接下来就让我们好好学习,天 ...
- 028-B+树(一)
B+ 树 这部分主要学习:什么是B+树? 了解了 B 树后再来了解下它的变形版:B+ 树,它比 B 树的查询性能更高. 一棵 B+ 树需要满足以下条件: 节点的子树数和关键字数相同(B 树是关键字数比 ...
- 20155310 2016-2017-2 《Java程序设计》第七周学习总结
20155310 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 第十三章 时间与日期 认识时间与日期 •时间的度量 •GMT(格林威治标准时间):现在不是标 ...
- WebApi_返回Post格式数据
[HttpPost] public HttpResponseMessage Post([FromBody] DingTalkCallBack bodyMsg, string signature, st ...
- 关于Redis命令keys在性能方面的说明
redis的keys命令类似于Mysql的like命令,无非就是模糊匹配相近的字符数据. KEYS 的速度非常快,但在一个大的数据库中使用它仍然可能造成性能问题,如果你需要从一个数据集中查找特定的 k ...
- dependencyManagement、parent与dependencies
本文总结自:https://www.cnblogs.com/feibazhf/p/7886617.html 当我们的项目很多时,为了适应子项目的依赖项使用统一的版本,我们可以创建一个parent项目来 ...
- openwrt编译系统制作ubi镜像时会使用系统自带的ubinize还是openwrt编译系统中编译的ubinize
答:使用openwrt编译系统中编译的ubinize,那么这个工具在哪个目录下?在staging_dir/host/bin目录下
- IntelliJ IDEA 中配置lombok插件,编写简略风格Java代码
1.打开IDEA的Settings面板,并选择Plugins选项,然后点击 “Browse repositories..” 2.开启注释处理 3.在pom.xml中添加lombox <!-- h ...
- [Pytorch]Pytorch加载预训练模型(转)
转自:https://blog.csdn.net/Vivianyzw/article/details/81061765 东风的地方 1. 直接加载预训练模型 在训练的时候可能需要中断一下,然后继续训练 ...
- Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理
1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...