0

4Hz の正弦波を計算し、FFT を適用して振幅を計算しました。振幅は長さ 500 の配列です。その配列の各要素を dBm 形式に変換し、スペクトログラムを描画します。しかし、私は計算を正しく行うことができないようです。

私はその一般式を見ました:

valueDBFS = 20 np.log10(abs(値))

だから私はそれを使ってみましたが、否定的な結果しか得られません..

これが私の完全なコードです(編集済み):

# Python example - Fourier transform using numpy.fft method
import numpy as np
import matplotlib.pyplot as plotter
from os import times
from PIL import Image
import numpy as np

# How many time points are needed i,e., Sampling Frequency
samplingFrequency = 100
# At what intervals time points are sampled
samplingInterval = 1 / samplingFrequency
# Begin time perod of the signals
beginTime = 0
# End time period of the signals
endTime = 10
# Frequency of the signals
signal1Frequency = 4
signal2Frequency = 70

# Time points
time = np.arange(beginTime, endTime, samplingInterval)
# Create two sine waves
amplitude1 = 100 * np.sin(2*np.pi*signal1Frequency*time)

fourierTransform = np.fft.fft(amplitude1)
fourierTransform = fourierTransform[range(int(len(amplitude1)/2))] # Exclude sampling frequency
tpCount = len(amplitude1)
values = np.arange(int(tpCount/2))
timePeriod = tpCount/samplingFrequency
frequencies = values/timePeriod


valueDBFS = 20*np.log10(abs(fourierTransform))

print(valueDBFS)

#SPECTROGRAM
w, h = 500, 500
data = np.zeros((h, w, 3), dtype=np.uint8)
time = time[:len(time)//2]
for i in range(500):
    for j in range(500):
        color = abs(fourierTransform)[i]
        data[i,j] = [color, color, color] 
        
img = Image.fromarray(data, 'RGB')
img.show()
4

1 に答える 1