《DSP using MATLAB》Problem 6.24

代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 6.24 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D = [1001, -63, -449, 978, -205]; fprintf('\nConvert a Sign-Magnitude Format Decimal integer D to its binary representation B! \n');
fprintf('\n %5d binary representation is :-- %20s -- \n', D(1), sm2bin(D(1)) );
fprintf('\n %5d binary representation is :-- %20s -- \n', D(2), sm2bin(D(2)) );
fprintf('\n %5d binary representation is :-- %20s -- \n', D(3), sm2bin(D(3)) );
fprintf('\n %5d binary representation is :-- %20s -- \n', D(4), sm2bin(D(4)) );
fprintf('\n %5d binary representation is :-- %20s -- \n', D(5), sm2bin(D(5)) ); %B = {'1010', '011011011', '11001', '1010101', '011011'};
%B = char('1010', '011011011', '11001', '1010101', '011011');
%B = ['1010'; '011011011'; '11001'; '1010101'; '011011']; B1 = '1010';
fprintf('\nConvert a binary representation B to its Sign-Magnitude Format Decimal integer D! \n');
fprintf('\n --%15s-- Sign-Magn representation is : %10d \n', B1, bin2sm(B1) ); B2 = '011011011';
fprintf('\n --%15s-- Sign-Magn representation is : %10d \n', B2, bin2sm(B2) ); B3 = '11001';
fprintf('\n --%15s-- Sign-Magn representation is : %10d \n', B3, bin2sm(B3) ); B4 = '1010101';
fprintf('\n --%15s-- Sign-Magn representation is : %10d \n', B4, bin2sm(B4) ); B5 = '011011';
fprintf('\n --%15s-- Sign-Magn representation is : %10d \n', B5, bin2sm(B5) );
用到的子函数sm2bin
function B = sm2bin(D);
% Convert a Sign-Magnitude format Decimal integer D
% to its binary representation B
% ----------------------------------------------------------
% B = sm2bin(D)
% D = sign-magnitude format decimal integer
% B = binary representation
%
% s = sign(D); % sign of D (-1 if x<0, 0 if x=0, 1 if x>0)
sb = (s < 0); % sign-bit (0 if x>=0, 1 if x<0)
B = strcat( num2str(sb), dec2bin( abs(D) ) );
另一个子函数bin2sm
function D = bin2sm(B);
% Convert a binary representation B to its
% Sign-Magnitude format Decimal integer D
% ----------------------------------------------------------
% D = bin2sm(B)
% D = sign-magnitude format decimal integer
% B = binary representation
%
%
%B = num2str(B)
sb = str2num( B(1) ); % sign-bit (0 if x>=0, 1 if x<0) if sb == 0
D = (1-sb) * bin2dec( B(2:length(B)) ); % or D = bin2dec( B(2:1:length(B)) )
elseif sb == 1
D = -bin2dec( B(2:length(B)) );
end
运行结果:

第6章的习题我就做到这里了,剩下的不会,以后开始第7章。
《DSP using MATLAB》Problem 6.24的更多相关文章
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 4.24
Y(z)部分分式展开, 零状态响应部分分式展开, 零输入状态部分分式展开,
- 《DSP using MATLAB》Problem 6.15
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.8
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.24-5.25-5.26
代码: function y = circonvt(x1,x2,N) %% N-point Circular convolution between x1 and x2: (time domain) ...
- 《DSP using MATLAB》Problem 4.15
只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...
- 《DSP using MATLAB》Problem 2.16
先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...
- 《DSP using MATLAB》 Problem 2.3
本题主要是显示周期序列的. 1.代码: %% ------------------------------------------------------------------------ %% O ...
- 《DSP using MATLAB》Problem 7.29
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
随机推荐
- Win10系列:VC++绘制几何图形3
在绘制三角形之前,首先需要创建一个三角形,打开D2DBasicAnimation.h头文件,在D2DBasicAnimation类中添加如下的代码: private: //声明成员变量obje ...
- bzoj1798
题解: 同洛谷2023 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll p,v,su ...
- InterBase 数据库与驱动 版本不同
[Window Title] Project1 - Delphi 10.1 Berlin - Unit1 [Content] Failed: "unsupported on-disk str ...
- Eclipse集成Tomcat插件(特别简单)
. 只需要一个jar包 复制到eclipse/plugins文件夹下,重启Eclipse即可看到如下三只小猫 1.修改Tomcat (1)Tomcat version:版本 (2)Tomcat Hom ...
- ppt点击文字出现图片,再次点击消失
实现效果:在PPT一个页面的任意位置,单击左键,出现图片:在图片上,单击左键,图片消失 实现思路:给图片做两个动画,一个进入,文字作触发器,另一个退出,图片本身为触发器. 实现方法: 1.选中图片…… ...
- bind配置文件
options{} - 整个bind使用的全局配置选项 bind监听的端口,数据文件存储位置,缓存的存储位置,权限加密的控制 logging{}- 服务日志选项 日志输出的位置,以及输出的级别 zon ...
- 5.4 C++重载输入与输出操作符
参考:http://www.weixueyuan.net/view/6382.html 总结: 在C++中,系统已经对左移操作符“<<”和右移操作符“>>”分别进行了重载,使其 ...
- Java语法基础学习DayTwo
一.数据类型补充问题 数据类型的自动转换等级: byte,short,char -- int -- long -- float -- double long是8个字节,float是4个字节,为什么是这 ...
- 7.Python 正则表达式学习笔记
本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例.本文的内容不包括如何编写高效的正则表达式.如何优化正则表达式,这些主题请查看其他教程 ...
- <Dr.Elephant><How to tune ur application>
Why Dr.Elephant? Most of Hadoop optimization tools out there, but they are focused on simplifying th ...