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?

コヒーレントサンプリングされた波形データを並び替えて1周期分の波形にする

Posted at

正弦波信号の並び替えと可視化

はじめに

本記事では、サンプリングされた正弦波信号の並び替え(wave sorting)を行い、
その結果を可視化するシミュレーションをPythonで実装します。

設定するパラメータ

以下のパラメータを使用してシミュレーションを行います。

  • サンプリング周波数 (fs): 1 MHz (1,000,000 サンプル/秒)
  • 入力信号周波数 (fin): 124.511 kHz
  • サンプル数 (N): 500
  • シミュレーション時間: (N / fs)

シミュレーションコード

import numpy as np
import matplotlib.pyplot as plt

def wave_sort(data, fs, fin):
    """
    信号の並び替えを行う関数
    :param data: 入力信号
    :param fs: サンプリング周波数
    :param fin: 入力信号周波数
    :return: 並び替え後の信号
    """
    indices = np.argsort(np.angle(np.exp(1j * 2 * np.pi * fin * np.arange(len(data)) / fs)))
    return data[indices]

# パラメータ設定
fs = 1e6  # サンプリング周波数 1 MHz
fin = 124.511e3  # 入力周波数 124.511 kHz
N = 1024  # サンプル数
simulation_time = N / fs  # シミュレーション時間

# 時間軸
t = np.arange(0, simulation_time, 1 / fs)
original_data = np.sin(2 * np.pi * fin * t)  # 正弦波信号

# 並び替え
sorted_data = wave_sort(original_data, fs, fin)

# プロット
plt.figure(figsize=(10, 6))

# 並び替え前の波形
plt.subplot(2, 1, 1)
plt.plot(original_data, marker='o', linestyle='-', markersize=3, label="Original Data")
plt.title("Original Data")
plt.xlabel("Sample Index")
plt.ylabel("Amplitude")
plt.legend()
plt.grid()

# 並び替え後の波形
plt.subplot(2, 1, 2)
plt.plot(sorted_data, marker='o', linestyle='-', markersize=3, label="Sorted Data", color='r')
plt.title("Sorted Data")
plt.xlabel("Sample Index")
plt.ylabel("Amplitude")
plt.legend()
plt.grid()

plt.tight_layout()
plt.show()

実行結果と考察

並び替え前の波形

もとの波形は通常の正弦波信号であり、サンプリング間隔ごとにデータが取得されています。

並び替え後の波形

並び替え後の波形は、入力周波数に基づいた角度の昇順でソートされています。
これにより、波形が特定のパターンで整列されることが確認できます。

まとめ

本記事では、

  • サンプリング信号の並び替え
  • ソートされた波形の可視化

を実装しました。この技術は、信号処理やデータ解析の一環として利用可能です。

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?