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 1 year has passed since last update.

エレキ素人が何か考える(その25):tone()およびanalogWrite()のFFT

Posted at

tone()およびanalogWrite()の周波数解析(FFT)

その24同様、デジタルオシロスコープの機能を確認するため、Arduino互換機を用いて、tone()関数およびanalogWrite()関数実行時の周波数解析を実施。

ソースコード

#define PIN 9
uint32_t freq = 490;
uint8_t duty = 25;

void setup() {
}

// Either tone() or analogWrite() must be selected.
void loop() {
  //tone(PIN, freq);
  analogWrite(PIN, duty);
}

loop()中のtone()またはanalogWrite()のいずれかを選択。freqは周波数、dutyはデューティ比である。

検証

tone()とanalogWrite()との比較

tone()はデューティ比50%の矩形波を生成する。そこで、まず、analogWrite()にてデューティ比およそ50%(duty=127)を指定する。その時の波形が下記となる。
analogWrite127.png
このFFTは下記となる。
analogWrite127FFT-3.png
image.png
おおよそ、490Hzがメイン周波数となる。そこで、tone()にて、490Hzを指定した時の波形およびFFT結果が下記となる。
tone490.png
tone490FFT-1.png
両者はほぼ同じ。

また、デューティ比50%の矩形波の矩形波、3、5、7、9、、、の高調波が出るらしい(後述)。

analogWrite()でデューティ比を変化させる。

理論的には、こちら(非対称矩形波のフーリエ級数)で説明されている。また、デューティ比によって、高調波の出方もシミュレーションできる。先程のデューティ比50%は次のようになるようだ。
Duty50.png

デューティ比75%

理論値は下記。
Duty75.png
実測値は下記となった。
analogWrite191FFT.png
わかりにくいかもしれないが、ほぼ同じに見える。

デューティ比10%

理論値は下記。
Duty10.png
実測値は下記となった。
analogWrite25FFT-4.png
こちらもほぼ同じであろう。

EOF

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?