C# 画参数可调调幅波

参阅此,

使用VC++输出调幅波的数值和波形_c++如何显示下位机传输过来的频谱信号 csdn_bcbobo21cn的博客-CSDN博客

用winform做一下;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace amtest
{
    public partial class Form1 : Form
    {
        private double pi = 3.14159;
        int tzh = 100;
        int zbh = 1000;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Graphics g = pictureBox1.CreateGraphics();
            //g.Clear(this.BackColor);
            tzh = Convert.ToInt32(textBox2.Text);
            zbh = Convert.ToInt32(textBox3.Text);
            pictureBox1.Invalidate();
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen p1 = new Pen(Color.Blue, 1);

            int r = 0;
            double s, t;
            int i;      //循环变量
            Point ptstart = new Point(0, 0);
            Point pt = new Point();
            for (i = 0; i < 10000; i++)
            {
                t = i / 10000.0;
                s = (1 + 0.5 * Math.Cos(2 * pi * tzh * t)) * Math.Cos(2 * pi * zbh * t);//信号的表达式

                pt.X = (int)(t * 10000);
                //pt.X = (int)t;
                pt.Y = 200 + (int)s * 60;

                g.DrawLine(p1, ptstart, pt);
                ptstart = pt;
                r = r + 1;
            }

        }
    }
}

2个代码是一样的;只是C#的参数可调;

C# 画参数可调调幅波_第1张图片 

C# 画参数可调调幅波_第2张图片 

C# 画参数可调调幅波_第3张图片 

画了几个看上去不太像调幅波;

s = (1 + 0.5 * Math.Cos(2 * pi * tzh * t)) * Math.Cos(2 * pi * zbh * t);//信号的表达式

这是调幅波的表达式;当前是假定载波为余弦,调制信号也是余弦;tzh是调制信号频率,zbh是载波频率,单位Hz;算出来的s是调制后的信号幅度;zbh必须高于tzh;

pt.X = (int)(t * 10000);

横坐标是用t来算的; t * 10000,然后把结果转换为整型;如果写 pt.X = (int)t * 10000 将会出现错误,因为t非常小,先把t转为整型总是0,再乘以10000结果总是0;

有时间再细看;

你可能感兴趣的:(.Net,通信软件开发,c#,调幅,信号)