0
1

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.

【python】波形からしきい値以上の値をしきい値に変更する

Last updated at Posted at 2018-10-05

ある波形のしきい値以上の部分をカットします。
サンプルとして正弦波を生成しています。

qiita.rb


# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import math
import copy

def main():
    # データのパラメータ
    N = 10000             # サンプル数
    dt = 1*1e-4           # サンプリング間隔
    fq1, fq2 = 10, 10     # 周波数
    t = np.arange(0, N*dt, dt) # 時間軸
    pi = math.pi               # π
    phi = 90                   # 位相
    phirad = phi*pi/180        # 位相ラジアン

    # 時間信号を生成(周波数f1の正弦波+周波数f2の正弦波)
    f = 10*np.cos(2*np.pi*fq1*t) + 10*np.cos(2*np.pi*fq2*t+phirad) 

    F = copy.copy(f)  # 参照でなく複製する

    i = 0
    limit = 3 #しきい値

#    見直し前
#    for dummy in F:
#        if F[i] > limit:
#            F[i] = limit
#        i += 1

    for i in range(len(F)):
        if F[i] > limit:
            F[i] = limit

    # 確認用
    plt.plot(t, f)
    plt.show()       # 元波形

    plt.plot(t, F)
    plt.show()       # カット波形


if __name__ == "__main__":
    main()
    

実行前
Figure_1.png

実行後
Figure_1-1.png

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?