《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窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- EF code first:列名 'Discriminator' 无效
使用EF code first编写类继承的时候,出现列名 'Discriminator' 无效 . 字段中没有列名 'Discriminator' 原来在代码中,定义了一个类A,类B,B继承A,但是数 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON MoveRectangle2
zw版[转发·台湾nvp系列Delphi例程]HALCON MoveRectangle2 procedure TForm1.Button1Click(Sender: TObject);var img ...
- ZW云推客即将登场
ZW云推客即将登场 即"4K云字库"框架文件发布后,ZW团队即将发布一全功能的:ZW云推客系统. ZW云推客系统,是原zBrow"百万社区营销系统".&qu ...
- Flask 使用富文本输入框
模板 <script src="{{ url_for('static', filename='ckeditor/ckeditor.js') }}"></scrip ...
- 生成TPC-H数据集
下载tpc-h tool 版本有点老,2.14.3,够用了. 在解压的文件夹下面cd到dbgen下,找到makefile.suite. ~/tpch_2_14_3$ cd dbgen~/tpch_2_ ...
- postman--实现接口自动化测试
postman使用 开发中经常用postman来测试接口,一个简单的注册接口用postman测试: 接口正常工作只是最基本的要求,经常要评估接口性能,进行压力测试. postman进行简单压力测试 下 ...
- Element-UI中Upload上传文件前端缓存处理
Element-UI对于文件上传组件的功能点着重于文件传递到后台处理,所以要求action为必填属性.但是如果需要读取本地文件并在前端直接处理,文件就没有必要传递到后台,比如在本地打开一个JSON文件 ...
- js中fn()和return fn()的区别
参考文章:http://www.jb51.net/article/87977.htm 这文章中没有讲明白,其实只要把文章里的代码加和不加return调试一下就知道是怎么回事了. var i = 0; ...
- 反射调用发生错误信息 LoadNeither
错误信息: Service cannot be started. System.Reflection.TargetInvocationException: Exception has been thr ...
- Python学习札记(三十四) 面向对象编程 Object Oriented Program 5
参考:获取对象信息 NOTE 1.type()函数可以用来判断对象的类型: >>> type(123) <class 'int'> >>> type(' ...