用C语言编写产生正弦调幅波信号的源程序,并用CCS仿真。要求调制幅度可变。(熟悉CCS绘图和滑块的使用方法)
软件环境:CCS Studio 3.3
1.编写文件
(1)编写C源文件 sin_am.c
正弦调幅波的公式在离散域中可以表示为
y(n)=[1+Msin(2*pi*n*fb/fs)]*sin(2*pi*n*fa/fs)
其中,sin(2*pi*fa/fs)为载波信号;[1+Msin(2*pi*n*fb/fs)]为调制信号;M为调制度系数。
假设载波信号的频率fa为200Hz,调制信号的频率fb为20Hz,采样频率fs为4000Hz。为保证不产生过调制,必须满足M小于或等于1。M=1为临界调制。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h>
2 #include<math.h>
3 #define TURE 1
4 int y[500],i;
5 float M;
6 void main()
7 {
8 puts("amplitude modulation sinewave example started.\n");
9 M=50;
10 for(i=0;i<500;i++)
11 {
12 y[i]=0;
13 }
14 while(TURE)
15 {
16 for(i=0;i<500;i++)
17 {
18 y[i]=(int)((1+M/100*sin(i*2*3.14159*20/4000))*sin(i*2*3*3.14159*200/4000)*16384);
19 }
20 puts("program end");
21 }
22 }
2 #include<math.h>
3 #define TURE 1
4 int y[500],i;
5 float M;
6 void main()
7 {
8 puts("amplitude modulation sinewave example started.\n");
9 M=50;
10 for(i=0;i<500;i++)
11 {
12 y[i]=0;
13 }
14 while(TURE)
15 {
16 for(i=0;i<500;i++)
17 {
18 y[i]=(int)((1+M/100*sin(i*2*3.14159*20/4000))*sin(i*2*3*3.14159*200/4000)*16384);
19 }
20 puts("program end");
21 }
22 }
程序中设定M的初始值为50,一次运算500个样点。
(2)编写复位向量文件 sin_am.asm
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 .title"sin_am_v.asm"
2 .sect".vectors"
3 .ref _c_int00 ;C entry point
4 RESET: ;reset vector
5 B _c_int00 ;branch to C entry point
6 .end
2 .sect".vectors"
3 .ref _c_int00 ;C entry point
4 RESET: ;reset vector
5 B _c_int00 ;branch to C entry point
6 .end
(3)编写链接命令文件 sin_am.cmd
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 MEMORY
2 {
3 PAGE 0: EPROG: origin=0x1400,len=0x7c00
4 VECT: origin=0xff80,len=0x80
5 PAGE 1: USERREGS:origin=0x60,len=0x1c
6 IDATA: origin=0x80,len=0x3000
7 }
8 SECTIONS
9 {
10 .vectors:>VECT PAGE 0
11 .text: >EPROG PAGE 0
12 .cinit: >EPROG PAGE 0
13 .bss: >IDATA PAGE 1
14 .const: >IDATA PAGE 1
15 .switch: >IDATA PAGE 1
16 .sysmem: >IDATA PAGE 1
17 .stack: >IDATA PAGE 1
18 }
2 {
3 PAGE 0: EPROG: origin=0x1400,len=0x7c00
4 VECT: origin=0xff80,len=0x80
5 PAGE 1: USERREGS:origin=0x60,len=0x1c
6 IDATA: origin=0x80,len=0x3000
7 }
8 SECTIONS
9 {
10 .vectors:>VECT PAGE 0
11 .text: >EPROG PAGE 0
12 .cinit: >EPROG PAGE 0
13 .bss: >IDATA PAGE 1
14 .const: >IDATA PAGE 1
15 .switch: >IDATA PAGE 1
16 .sysmem: >IDATA PAGE 1
17 .stack: >IDATA PAGE 1
18 }
(4)建立GEL文件 vary_M.gel
menuitem "My Functions"
slider vary_M(0,100,10,1,Amount_of_modulation)
{
M=Amount_of_modulation;
}
2.建立工程项目和向工程项目添加文件
不积跬步,无以至千里;不积小流,无以成江海。