# 北軟96 pD 傅立葉級數 ###### tags: `北軟96` ## 題目: 傅立葉級數在工程上與物理上的應用相當廣泛。任一週期函數可以利用傅立葉級數分解成 許多不同振幅大小,不同頻率高低的正弦波與餘弦波。 下面方程式為方波之 Truncated exponential Fourier series 其中一種。 $$Y_N(t)=\dfrac{1}{2}\times\displaystyle{\sum_{k=1 \\ k=odd}^M} + \cos(k \pi t + ((-1)^{(k-1)/2} - 1)\times\dfrac{\pi}{2})$$ 其中− 3sec ≤ t ≤ 3sec,k = 1,3,5,7,...,M ,M 為奇數諧波(只需計算至最大奇數 M<=N) 1.請設計一個程式(畫面可自行設計),可讓使用者輸入 N=10(只需計算至 N=9)與取樣時 間,代入上式,按執行鍵之後,可繪畫出產生如(圖一)所示的波形。(12 分)  2. 可讓使用者輸入任一 N 值(N<=30)與取樣時間,代入上式,按執行鍵之後,可繪畫圖形 如(圖二)所示的波形。(13 分) ## 想法: 這題沒什麼特別的想法,就是圖表的應用和刻算式,請見以下的程式碼。 ## 程式碼(C#): ```csharp= 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 problemD { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public double formula(int n,double second) { double val = 0; for(double k = 1; k <= n; k+=2) { val += 2 / (k * Math.PI) * Math.Cos(k * Math.PI * second + ((Math.Pow(-1, (k - 1) / 2)) - 1) * (Math.PI / 2)); } return val + 1 / 2; } private void button1_Click(object sender, EventArgs e) { chart1.Series[0].Points.Clear(); int n = Convert.ToInt16(textBox1.Text); double m = Convert.ToDouble(textBox2.Text); chart1.ChartAreas[0].AxisX.Maximum = 3.0; chart1.ChartAreas[0].AxisX.Minimum = -3.0; chart1.ChartAreas[0].AxisY.Minimum = -1.5; chart1.ChartAreas[0].AxisY.Maximum = 1.5; for (double i = -3; i <= 3; i+=1*m) { chart1.Series[0].Points.AddXY(i,formula(n, i)); } } private void Form1_Load(object sender, EventArgs e) { chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chart1.Series[0].Points.Clear(); } } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up