《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 == 0D = (1-sb) * bin2dec( B(2:length(B)) ); % or D = bin2dec( B(2:1:length(B)) )elseif sb == 1D = -bin2dec( B(2:length(B)) );end
运行结果:
第6章的习题我就做到这里了,剩下的不会,以后开始第7章。
转载于:https://www.cnblogs.com/ky027wh-sx/p/10291752.html
《DSP using MATLAB》Problem 6.24相关推荐
- 《DSP using MATLAB》Problem 5.7
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.12
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.20
先放子函数: function [C, B, A, rM] = dir2fs_r(h, r);% DIRECT-form to Frequency Sampling form conversion % ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 6.6
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 8.22
时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...
- 《DSP using MATLAB》Problem 8.1
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
最新文章
- 前端自动化构建工具webpack (二)之css和插件加载总结
- 亚马逊科学家Nikko Ström:将人工智能助理日常化的梦想照进现实
- 3月9日起陆续开学!快来看看有没有你所在的省份
- 网络集中投射了全部安全问题
- uniapp android原生,在uni-app项目中集成Android原生工程
- Mybatis的核心——SqlSession解读
- 反射获取成员方法并运行
- SAP BTP 平台 CloudFoundry 环境下编程概述
- 【C语言笔记】关于数组的一个陷阱!
- 该虚拟机似乎正在使用中。 如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏。 配置文件: D:\instractPath\Developmen
- 集合点(掌握)-并发
- lottie动画效果使用简例
- 图书所属类别用mysql_Java图书信息查询
- 上座部佛教的佛陀略传
- Android补间动画原理介绍
- Safe Browsing API
- 远程桌面时,如何登录没有设置密码的系统
- java星座测试需求分析_如何进行软件测试需求分析
- python实现kmeans算法对图片的聚类分割
- 如何清空windows的系统剪贴板
热门文章
- echarts实现柱状图分页展示
- Linux下MySQL链接被防火墙阻止
- 企业真的要培养员工?
- java例程练习(批量修改文件后缀名)
- [原]Oracle删除大表并回收空间的过程
- [Caffe]:关于*** Aborted at 1479432790 (unix time) try date -d @1479432790 错误的另一种原因
- 【数据平台】Eclipse+Scala开发环境(本机和集群两个运行模式)
- MapReduce基础开发之九JDBC连接Hive
- 优化SQL步骤——查看SQL执行频率 || 定位低效率执行SQL
- Linux下MySQL数据库的备份与还原,mysql快速导入导出数据库实例演示,解决mysql大数据量数据库导出慢的问题