声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1374|回复: 3

[编程技巧] matlab语言转化问题

[复制链接]
发表于 2008-10-11 11:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
1.编写一个程序,读取一句英语短语,并将其编制成莫尔斯码,再用一个程序将莫尔斯码变成英语。
回复
分享到:

使用道具 举报

发表于 2008-10-11 12:41 | 显示全部楼层
程序我倒不回编,给后面的高手点资料,帮忙解决问题
莫尔斯电码(Morse code)是美国人莫尔斯于1844年发明的,由点(.)、划(-)两种符号组成。

1、一点为一基本信号单位,一划的长度=3点的长度。

2、在一个字母或数字内,各点、划之间的间隔应为两点的长度。

3、字母(数字)与字母(数字)之间的间隔为7点的长度。

字符 电码符号 字符 电码符号
A ●— N —●
B —●●● O ———
C —●—● P ●——●
D —●● Q ——●—
E ● R ●—●
F ●●—● S ●●●
G ——● T —
H ●●●● U ●●—
I ●● V ●●●—
J ●——— W ●——
K —●— X —●●—
L ●—●● Y —●——
M —— Z ——●●


数字 电码符号 标点符号 电码符号
1 ●———— ? ●●——●●
2 ●●——— / —●●—●
3 ●●●—— ( ) —●——●—
4 ●●●●— — —●●●●—
5 ●●●●● 。 ●—●—●—
6 —●●●●
7 ——●●●
8 ———●●
9 ————●
0 —————
摩尔斯电码
以下列出摩尔斯电码

摩尔斯电码
A .-
I ..
Q --.-
Y -.--
7 --…
B -…
J .---
R .-.
Z --..
8 ---..
C -.-.
K -.-
S …
1 .----
9 ----.
D -..
L .-..
T -
2 ..---
0 -----
E .
M --
U ..-
3 …--
. .-.-.-
F ..-.
N -.
V …-
4 ….-
? ..--..
G --.
O ---
W .--
5 …..
, --..--
H ….
P .--.
X -..-
6 -….
1 ●—滴哒
2 ●●— 滴滴哒
3 ●●●—— 滴滴哒哒
4 ●●●●— 滴滴滴滴哒
5 ●●●●● 滴滴滴滴滴
6 —●●●● 哒滴滴滴滴
7 ——●●● 哒哒滴滴滴
8 —●● 哒滴滴
9 —● 哒滴
0 —哒

评分

1

查看全部评分

发表于 2008-10-11 16:23 | 显示全部楼层

回复 楼主 小乖小傻 的帖子


  1. function morse(varargin)

  2. % MORSE converts text to playable morse code in wav format
  3. %
  4. % SYNTAX
  5. % morse(text)
  6. % morse(text,file);
  7. %
  8. % Description:
  9. %
  10. %   If the wave file name is specified, then the funtion will output a wav
  11. %   file with that file name.  If only text is specified, then the function
  12. %   will only play the morse code wav file without saving it to a wav file.
  13. %
  14. % Examples:
  15. %
  16. %   morse('Hello');
  17. %   morse('How are you doing my friend?','morsecode.wav');
  18. %
  19. %   Copyright 2005 Fahad Al Mahmood
  20. %   Version: 1.0 $  $Date: 05-Jun-2005

  21. text = varargin{1};
  22. if nargin==2
  23.     file = varargin{2};
  24. end

  25. Fs=11025;
  26. load wav;
  27. Dit = wav(1106:2121);
  28. ssp = wav(2121:3133);
  29. Dah = wav(3133:6176);
  30. lsp = wav(6176:23022);

  31. % Defining Characters & Numbers
  32. A = [Dit;ssp;Dah];
  33. B = [Dah;ssp;Dit;ssp;Dit;ssp;Dit];
  34. C = [Dah;ssp;Dit;ssp;Dah;ssp;Dit];
  35. D = [Dah;ssp;Dit;ssp;Dit];
  36. E = [Dit];
  37. F = [Dit;ssp;Dit;ssp;Dah;ssp;Dit];
  38. G = [Dah;ssp;Dah;ssp;Dit];
  39. H = [Dit;ssp;Dit;ssp;Dit;ssp;Dit];
  40. I = [Dit;ssp;Dit];
  41. J = [Dit;ssp;Dah;ssp;Dah;ssp;Dah];
  42. K = [Dah;ssp;Dit;ssp;Dah];
  43. L = [Dit;ssp;Dah;ssp;Dit;ssp;Dit];
  44. M = [Dah;ssp;Dah];
  45. N = [Dah;ssp;Dit];
  46. O = [Dah;ssp;Dah;ssp;Dah];
  47. P = [Dit;ssp;Dah;ssp;Dah;ssp;Dit];
  48. Q = [Dah;ssp;Dah;ssp;Dit;ssp;Dah];
  49. R = [Dit;ssp;Dah;ssp;Dit];
  50. S = [Dit;ssp;Dit;ssp;Dit];
  51. T = [Dah];
  52. U = [Dit;ssp;Dit;ssp;Dah];
  53. V = [Dit;ssp;Dit;ssp;Dit;ssp;Dah];
  54. W = [Dit;ssp;Dah;ssp;Dah];
  55. X = [Dah;ssp;Dit;ssp;Dit;ssp;Dah];
  56. Y = [Dah;ssp;Dit;ssp;Dah;ssp;Dah];
  57. Z = [Dah;ssp;Dah;ssp;Dit;ssp;Dit];
  58. period = [Dit;ssp;Dah;ssp;Dit;ssp;Dah;ssp;Dit;ssp;Dah];
  59. comma = [Dah;ssp;Dah;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dah];
  60. question = [Dit;ssp;Dit;ssp;Dah;ssp;Dah;ssp;Dit;ssp;Dit];
  61. slash_ = [Dah;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dit];
  62. n1 = [Dit;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dah];
  63. n2 = [Dit;ssp;Dit;ssp;Dah;ssp;Dah;ssp;Dah];
  64. n3 = [Dit;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dah];
  65. n4 = [Dit;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dah];
  66. n5 = [Dit;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dit];
  67. n6 = [Dah;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dit];
  68. n7 = [Dah;ssp;Dah;ssp;Dit;ssp;Dit;ssp;Dit];
  69. n8 = [Dah;ssp;Dah;ssp;Dah;ssp;Dit;ssp;Dit];
  70. n9 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dit];
  71. n0 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dah];

  72. text = upper(text);
  73. text1 = text + 0
  74. panjang=length(text1);
  75. i=1;
  76. for j=1;panjang
  77.     if text1(j)~= 32
  78.         text(i)=text1(j);
  79.         i=i+1;
  80.     end
  81. end
  82. vars ={'period','comma','question','slash_'};
  83. morsecode=[];
  84. for i=1:length(text)
  85.     if isvarname(text(i))
  86.     morsecode = [morsecode;eval(text(i))];
  87.     elseif ismember(text(i),'.,?/')
  88.         x = findstr(text(i),'.,?/');
  89.         morsecode = [morsecode;eval(vars{x})];
  90.     elseif ~isempty(str2num(text(i)))
  91.         morsecode = [morsecode;eval(['n' text(i)])];
  92.     elseif text(i)==' '
  93.         morsecode = [morsecode;ssp;ssp];
  94.     end
  95.     morsecode = [morsecode;ssp;ssp;ssp];
  96. end
  97. if exist('file','var')
  98.     wavwrite(morsecode,11025,16,file);
  99. else
  100.     wavplay(morsecode);
  101. end
复制代码

wav.mat

12.9 KB, 下载次数: 9

评分

1

查看全部评分

 楼主| 发表于 2008-10-12 12:56 | 显示全部楼层

回复 板凳 sogooda 的帖子

嘻嘻:lol :@)
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 03:28 , Processed in 0.070948 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表