代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% 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的更多相关文章

  1. 《DSP using MATLAB》Problem 7.24

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

  2. 《DSP using MATLAB》Problem 4.24

    Y(z)部分分式展开, 零状态响应部分分式展开, 零输入状态部分分式展开,

  3. 《DSP using MATLAB》Problem 6.15

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

  4. 《DSP using MATLAB》Problem 6.8

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

  5. 《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) ...

  6. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  7. 《DSP using MATLAB》Problem 2.16

    先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...

  8. 《DSP using MATLAB》 Problem 2.3

    本题主要是显示周期序列的. 1.代码: %% ------------------------------------------------------------------------ %% O ...

  9. 《DSP using MATLAB》Problem 7.29

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

随机推荐

  1. 解决eclipse/myeclipse导入项目时出现红色叹号的方法

  2. unity中让摄像机移动到鼠标点击的位置和鼠标控制平移视角

    private Vector3 targetVector3; private float movespeed=0.5f; private bool IsOver = true; private Gam ...

  3. day3-PyCharm 断点 调试模式

    上篇学习了Python的工具选择,PyCharm的基本设置,简单的了解了下PyCharm的调试模式,今天主要学习下PyCharm的调式模式,在以后的开发中是一个非常重要的工具. [运行]和[调试]前的 ...

  4. 用FPGA对ASIC进行原型验证的过程(转)

    用FPGA对ASIC进行原型验证的过程   reference:http://xilinx.eetrend.com/d6-xilinx/article/2018-10/13736.html     鉴 ...

  5. MyEclipse使用教程:使用REST Web Services管理JPA实体

    MyEclipse 在线订购专享特惠!火爆开抢>> MyEclipse最新版下载 使用REST Web Services来管理JPA实体.在逆向工程数据库表后生成REST Web服务,下面 ...

  6. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法

    1.导入mysql-connector-java-5.1.26-bin.jar包,我试着把maven中自动下载下来的mysql-connector-java-5.1.26.jar包导入,还是没能解决问 ...

  7. Java语法基础学习DayTwo

    一.数据类型补充问题 数据类型的自动转换等级: byte,short,char -- int -- long -- float -- double long是8个字节,float是4个字节,为什么是这 ...

  8. SQL server的高可用

    SQL server 2012实现数据库中的表同步到局域网中的另外一个服务器上的数据库的方法: 1.发布.订阅功能 2.AlwayOn功能(最稳定.最优的方案) 3.修改程序,写两份数据,或者用触发器 ...

  9. 深入了解HyperServer

    本文,我们将尝试深入了解uniGUI HyperServer. 可以将HyperServer所有功能分成三类: HyperServer和稳定性 HyperServer和可扩展性 HyperServer ...

  10. springboot区分开发、测试、生产多环境的应用配置

    转:https://blog.csdn.net/daguairen/article/details/79236885 springboot区分开发.测试.生产多环境的应用配置(一) Spring可使用 ...