簡體   English   中英

如何將 IDFT 和噪聲應用於 python 中的信號陣列?

[英]How to apply IDFT and noise to a signal array in python?

所以我目前正在制作一個涉及制作合成心電圖信號的 python 程序,首先我們必須制作一個 rr 轉速圖,我做了,這是代碼

#import necessary modules to start the program
import matplotlib.pyplot as plt
import numpy as np

#Create standard deviation variables, which are c1 and c2, t1 and t2 have the same value as hf and lf
c1 = 0.01
c2 = 0.01
#N = NRR which is 256, and is the total amount of data
tau1 = np.sqrt(0.056)
tau2 = np.sqrt(0.076)
N = 256
f1 = 0.1
f2 = 0.25
Nrr= 256
lf = 0.056
hf = 0.076
#ratio also has the equation of  lf/hf
ratio = lf/hf

#declare imaginary numbers
S_real = np.zeros(1000)
S_imaj = np.zeros(1000)
MagIDFT = np.zeros(1000)
#the arrays(lists) that will be used for plotting the signal
S = []
F = []

#we make this into a gauss series function
def SF_gauss_series():
  #The main S(F) series that is according to the bimodal spectrum equation
  for i in range(N):
    f = i/Nrr
    #In the mirroring part, we use the signal mirroring equation, x(t) -> x(t+1) -> x(-t+1)
    s = (tau1**2/(np.sqrt(2*np.pi*c1**2)))*np.exp(-(f-f1)**2/(2*c1**2)) + \
    (tau2**2/(np.sqrt(2*np.pi*c2**2)))*np.exp(-(f-f2)**2/(2*c2**2))     + \
    (tau1**2/(np.sqrt(2*np.pi*c1**2)))*np.exp(-(f-1+f1)**2/(2*c1**2))   + \
    (tau2**2/(np.sqrt(2*np.pi*c2**2)))*np.exp(-(f-1+f2)**2/(2*c2**2))
    #As you can see we have 4 signals, we the the last 2 signals, inverted.
    #After sequencing the f and s variables, 
    #We use the append() function and move it the F and S array
    F.append(f)
    S.append(s)
SF_gauss_series()

#Here, we utilize matplotlib as plt, and start plotting the current RSA and Mayer Signals
plt.figure(figsize=(8,4))
#this part to plot the array
plt.plot(F,S, color='orange')
#labeling and naming code
plt.xlabel('Freq. (Hz)')
plt.ylabel('power (sec*2/Hz)')
plt.title("Post-Mirrored Mayer and RSA Waves")
#final show() function to display the graph
plt.show()

現在的問題是,我如何將 IDFT 應用於它?(逆離散傅里葉變換)並給信號帶來噪聲? 我知道應用噪聲是您可以使用 np.random() function,但我不知道如何對其進行 IDFT。

如果您想將逆 DFT 應用於某個信號S (作為數組),您可以應用

FS = np.fft.ifft(S)

這記錄在np.fft.ifft中。

如果您對純實信號感興趣,您可以應用例如使用np.real提取實部或使用絕對值np.abs - 但如果您將信號構造為實數而虛部只是浮點數學,您還可以考慮使用numpy.real_if_close以避免意外丟棄如果輸入可能實際上不代表真實信號時可能出現的大虛數值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM