代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% 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. 逆袭之旅DAY20.XIA.选择结构

    2018-07-16  18:50:49 本章目标: 基本if选择结构 逻辑运算符 多重if选择结构 嵌套if选择结构 什么是if选择结构: if选择结构是根据条件判断之后再做处理 import ja ...

  2. 2.python函数编程-filter函数

    fileter功能主要使用在需要对数据进行多种操作,并对数据进行过滤的操作. 普通函数实现: movie = ['sb_alex', 'wupei', 'tiger', 'goosb','xxfd', ...

  3. where的顺序对运行的影响--无影响

    2.表连接的时候,大表与小表的顺序是哪个在前.3.在多表连接时,是表与表先连接起来,再执行对单表的限制条件where条件:还是先执行单表的限制where条件,再进行表连接?4.多表连接时,如4个表,我 ...

  4. 通过改变unity中物体的alpha值实现若隐若现的效果

    RawImage logo = mainLogo.transform.FindChild("back/headBack/Logo").GetComponent<RawImag ...

  5. flask不定参数的传递。多参数,多次传递

    有的时候有一个分类查询,再来一个排序,这就有两个参数要传递多次. 还是不定长度,不定内容的传递. 这个是用request.args来实现: def home(): requests=request.a ...

  6. C++ Templates STL标准模板库的基本概念

    STL标准库包括几个重要的组件:容器.迭代器和算法.迭代器iterator,用来在一个对象群集的元素上进行遍历操作.这个对象群集或许是一个容器,或许是容器的一部分.迭代器的主要好处是,为所有的容器提供 ...

  7. lnmp 基础设置

    1.设置ci.tp.laravel重写,去掉index.php location / { try_files $uri $uri/ /index.php?$query_string; } 2.开启ph ...

  8. selenium登录界面,创建表单并填写提交

    #! python3 # -*- coding:utf8 -*- # https://selenium-python.readthedocs.io/api.html#selenium.webdrive ...

  9. bootstrapTable--4.删除和批量删除

    http://blog.csdn.net/qq_26553781/article/details/78058389 ------------------------------------------ ...

  10. 通过powerdesiner导出sql,通过sql转mysql为oracle

    1.导出sql文件 Database-->generate database-->确定 执行完就可以看到生成的语句了 2.将mysql的PDM转换为oracle File-->rev ...