0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mathematica 基本操作+単一周波数の離散フーリエ変換(DFT)

Last updated at Posted at 2018-07-08

バージョン

Mathematica11を使用。

リスト

注意:In[N],Out[N]はコードとして書かなくて大丈夫です。

(*数値や文字の並び(配列)をリストといい、{}の中に要素を並べる*)
In[0] = data = {1, 2, 3, 4}

out[0] = {1, 2, 3, 4}
In[1] = invdata = 1/data

Out[1] = {1, 1/2, 1/3, 1/4}
In[2] = invdata[[2]]

Out[3] = 1/2
In[3] = pdata = {{1, 1}, {2, 1/2}, {3, 1/3}, {4, 1/4}}

Out[3] = {{1, 1}, {2, 1/2}, {3, 1/3}, {4, 1/4}}

In[4] = pdata[[3]]

Out[4] = {3, 1/3}

In[5] = 
{
 pdata[[3, 1]], pdata[[4, 2]]
 }

Out[5] = {3, 1/4}
(*別の書き方*)
In[7] = Table[{k,k^2},{k,0,3}]

Out[7] = {{0, 0}, {1, 1}, {2, 4}, {3, 9}}

#プロット

  • ListPlot関数は、点をプロット
  • ListLinePlot関数は、点を通る点をプロット
In[6] = 
{
 ListPlot[{pdata, Filling → Axis, PlotStyle → {Black}, PlotMarkers → {"*", 20}}],
 ListLinePlot[{pdata, PlotStyle → {Black, Thick}}]
 }

Out[6] =
m1.PNG

#遅延型
####遅延型の定義 ":=" と 即時型の "="

  • "="はプログラム内で変数を固定するときにオススメ
  • ":="は呼び出すたびに変数を置き直すときにオススメ
  • "_"ブランクで後から変数を代入できる
In[8]=f[x_] := x^2
In[9]=
{
 f[3],
 f[t],
 f[a + b] // Expand,
 D[f[t], t],
 Integrate[f[t], t],
 Integrate[f[t], {t, 0, 1}], 
 Plot[f[t], {t, -1, 1}, PlotStyle -> {Black, Thick}]
 }

Out[9]=
m2.PNG

組み込み関数

ギリシャ文字などの特殊記号の入力方法は https://bit.ly/2IKJhem から
(例)[Esc]+p+[Esc] -> π, [Esc]+w+[Esc] -> ω

In[10]=
f[t_, A1_, ω1_, A2_, ω2_] := A1 Sin[ω1 t] + A2 Sin[ω2 t];


{
 Plot[f[t, 1, 2 π/0.1, 1, 2 π/0.11], {t, 0, T}, 
  PlotStyle -> {Black, Thick}],
 Plot[f[t, 1, 2 π/0.1, 0, 2 π/0.11], {t, 0, T}, 
  PlotStyle -> {Black, Thick}]
 }

Out[10]=
m3.PNG

左はA2≠0,つまり,f[t]=A1 Sin[ω1 t] + A2 Sin[ω2 t]
右はA2=0,つまり,f[t]=A1 Sin[ω1 t]

単一周波数の離散フーリエ変換(DFT)

In[11]=
f[t_, A1_, ω1_, A2_, ω2_] := A1 Sin[ω1 t] + A2 Sin[ω2 t];

{A1 = 1, ω1 = 2 π/0.1, A2 = 0, ω2 = 2 π/0.11};
ts = 0.03; M = T/ts;

dat = Table[{t, f[t, A1, ω1, A2, ω2]}, {t, 0, T, ts}];
dat31 = Table[dat[[k, 2]], {k, 1, M}];

dFT31 = Fourier[dat31];
{
 ListLinePlot[Re[dFT31], PlotRange -> All, PlotStyle -> {Black, Trick}],
 ListLinePlot[Im[dFT31], PlotRange -> All, PlotStyle -> {Black, Trick}]
 }

Out[11]=
m4.PNG

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?