0
0

More than 1 year has passed since last update.

Pythonでの音声信号処理 (9) 波の解析の一歩の疑問点

Last updated at Posted at 2023-02-09

今回のテーマ

「(8) 波の解析の一歩」を踏まえて、しっくりこない疑問点を整理する。

疑問点

  1. sin波が横にズレたような場合に、解析結果が変にならないか
  2. そもそも周期が分からないときはどうすればいいか

順番に検証する。

「sin波が横にズレる」場合

「sin波が横にズレる」とは、つまり、
p9_1.png
のように、dだけズレたような場合でも、きちんと周波数成分を抽出できるのかということ。

dだけズレたsin波の式を加法定理を使って展開すると、

p9_2_1.png

という感じになる。つまり、同じ周波数のsinとcosの中で完結するので、他の周波数に影響を与えたりすることは無いということ。

加えて、
p9_2_2.png
となるので、横にいくらズレても、もともとのsin波の大きさRを取り出すこともできるということ。

一応、プログラムで検証

p9_1.py
# -*- coding: utf-8 -*-
import sys
sys.dont_write_bytecode = True

import Dummy as dmy
import Analyze as ana
from multiprocessing import Process
import time
from Grp import Line
from Grp import Bar
import numpy as np
import math

def main():
    smpl = 44100
    sec  = 2
    r    = 2.0

    # sin(x) 4Hz 2秒分
    sin4x = dmy.makeWave(4, smpl, sec, r, 0, 1)

    # ちょっと横にズラす
    wav = sin4x[1000:]

    # Hz 1~10で、解析
    rng = (1, 10)
    res = ana.ft(wav, smpl, (0, 1), rng)
    res_sin = res[0]
    res_cos = res[1]

    # sinとcosの係数を2乗して加算して平方根をとる
    res_all = list(map(  
        lambda v : math.sqrt(v),
        np.array(res_sin) * np.array(res_sin) + np.array(res_cos) * np.array(res_cos)))


    # 表示
    p_s = []
    p = Process(target=drawLineGraph, args=(wav, smpl))
    p.start()
    p_s.append(p)

    p = Process(target=drawBarGraph, args=(res_all, range(rng[0], rng[1] + 1)))
    p.start()
    p_s.append(p)

    while len(p_s) > 0:
        for p in p_s:
            if not p.is_alive():
                p.join()
                p_s.remove(p)
        time.sleep(0.1)

    return

# 折れ線グラフの表示
def drawLineGraph(data, rate):
    grp = Line()
    grp.setData(data, rate)
    grp.setScale(1)
    grp.display()

# 棒グラフの表示
def drawBarGraph(data, label):
    grp = Bar()
    grp.setDataLabel(data, label)
    grp.display()

if __name__ == '__main__':
    main()

4Hzの波が、ちょっとだけ横にズレている。
p9_3.png

解析結果は、4Hzのところだけが出ている。
p9_4.png

補足

Grp.pyはここにあります。
https://qiita.com/u1tym/items/b52c466620f65225edf3

Dummy.pyはここにあります。
https://qiita.com/u1tym/items/3e2be5364e83df1b7792

Analyze.py、Integral.pyはここにあります。
https://qiita.com/u1tym/items/6fadd6b2974fc3281137

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