我试图了解 scipy.fftpack.fft 的输出。我创建了一个信号并做了一个fft。这是fft的代码:
import numpy as np
from scipy.fftpack import fft
import matplotlib.pyplot as plt
# Number of samplepoints
N = 600
# sample spacing
T = 1.0 / 800.0
x = np.linspace(0.0, N*T, N)
y = 5.0 * np.sin(50.0 * 2.0*np.pi*x) + 1.0*np.sin(80.0 * 2.0*np.pi*x) #unit is V
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
plt.close()
plt.plot(xf, 2.0/N * np.abs(yf[0:N/2]))
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
这创造了这个:
我知道信号强度幅度的单位与它从(V)创建的波形上的信号单位相同。我不明白 fft 频率的幅度与原始信号幅度之间的关系。比如50Hz正弦部分的幅度是5.0V,那为什么fft上50Hz的幅度在3.6V左右呢?
我想知道 numpy 中是否有任何函数可以确定矩阵是否为酉矩阵?
这是我写的函数,但它不起作用。如果你们能在我的函数中找到错误和/或告诉我另一种方法来确定给定矩阵是否是酉矩阵,我将不胜感激。
def is_unitary(matrix: np.ndarray) -> bool:
unitary = True
n = matrix.size
error = np.linalg.norm(np.eye(n) - matrix.dot( matrix.transpose().conjugate()))
if not(error < np.finfo(matrix.dtype).eps * 10.0 *n):
unitary = False
return unitary
Run Code Online (Sandbox Code Playgroud) 我需要在一个包含大约 40 个文件的小型数据库中找到一个类似的 wav 文件,长度从 5 秒到 7 秒不等。
这些 wav 文件是电话服务提供商在您拨打电话时提供给您的记录。
例子:
我的针有 1 或 2 秒长。
所有的 wav 都是pcm 编码的 16 位 8000hz 单声道。
我尝试使用Aurio.AudioFingerPrint没有成功
https://github.com/protyposis/Aurio
// Setup the sources
var audioTrack1 = new AudioTrack(new FileInfo("Full5secs.wav"));
var audioTrack2 = new AudioTrack(new FileInfo("Part2Secs.wav"));
// Setup the fingerprint generator
var defaultProfile = FingerprintGenerator.GetProfiles()[0];
var generator = new FingerprintGenerator(defaultProfile);
// Create a fingerprint store
var store = new FingerprintStore(defaultProfile);
// Setup the generator event listener (a …Run Code Online (Sandbox Code Playgroud) 我有一个z采样频率fs = 12(每月数据)的时间序列,我想使用fft10 个月和 15 个月执行带通滤波器。这就是我将继续的方式:
y <- as.data.frame(fft(z))
y$freq <- ..
y$y <- ifelse(y$freq>= 1/10 & y$freq<= 1/15,y$y,0)
zz <- fft(y$y, inverse = TRUE)/length(z)
plot zz in the time domain...
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何推导出 fft 的频率,也不知道如何在时域中绘制 zz。有人能帮我吗?
我可以从 .wav 文件中获得信号的幅度,但如何获得该信号的相位,,,这是我浏览 .wav 文件并提取信号的地方
def browse_wav(self):
filepath = QtGui.QFileDialog.getOpenFileName(self, 'Single File', "C:\Users\Hanna Nabil\Documents",'*.wav')
f= str(filepath)
if f != "":
spf = wave.open(f, 'r')
import contextlib
with contextlib.closing(wave.open(f, 'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
print "Duration is " , duration
# Extract Raw Audio from Wav File
self.signal = spf.readframes(-1)
self.signal = np.fromstring(self.signal, 'Int16')
self.fs = spf.getframerate()
print "Sampling Rate is " ,self.fs
# If Stereo
if spf.getnchannels() == 2:
print 'Just …Run Code Online (Sandbox Code Playgroud) 几天前,我遇到了这个关于FFT使用的答案
在答案中有一段这样的代码:
w = np.fft.fft(data)
freqs = np.fft.fftfreq(len(w))
Run Code Online (Sandbox Code Playgroud)
我在 numpy 文档(这里)中阅读了函数fftfreq,我发现它返回一个包含以下内容的数组:
f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd
Run Code Online (Sandbox Code Playgroud)
在我的情况下,d var 等于 1 和n是偶数。
所以我的问题是:fftfreq 的真正目的是什么?
我想知道它是否是一种三角窗函数。
我是处理信号的新手,需要您的帮助。
我从我的 TI AFE4490 获得了一个 10 秒的原始 PPG(光体积描记图)信号。我的硬件已经过校准,我每秒使用 250 个样本来记录这些信号。最后我获得了2500分。
您可以在下面看到图像、点和代码。
顶部:我的原始 PPG 信号 - 底部:尝试应用 FFT:

代码:
RED, IR, nSamples, sRate = getAFESignal()
period = 1/sRate
plt.figure(1)
plt.subplot(2,1,1)
x = np.linspace(0.0, nSamples*period, nSamples)
y = IR
plt.xlabel("Time (s)")
plt.ylabel("Voltage (V)")
plt.plot(x,y)
plt.subplot(2,1,2)
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*period), nSamples//2)
plt.xlabel("Frequency (Hz)")
plt.ylabel("Gain")
plt.plot(xf, 2.0/nSamples * np.abs(yf[0:nSamples//2]))
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
该函数getAFEsignal()只是一个读取 .txt 文件并将所有内容放入两个 numpy 数组的函数。
在这里您可以找到 .txt 文件:原始信号文件
如您所见,我没有正确应用 FFT,我需要它来发现我需要过滤的频率。你知道我做错了什么吗,是否可以在这个信号上应用 FFT?
我有在相关点具有等效间隔和相应测量值的数据。例如,这是我拥有的数据的摘录:
y =[2.118, 2.1289, 2.1374, 2.1458, 2.1542, 2.1615, 2.1627, 2.165 2.1687...]
点之间的间隔为 0.1
所以,我需要从数据中获取的是幅度谱(幅度与频率)和相位谱(相位角与频率)。此外,我应该将数据的相位偏移负 90 度 (-pi/2)。
在移动相位并保持幅度不变时,我需要执行逆 fft 并获得新信号。我想在 Python 中做到这一点。
你能给我一个执行此操作的示例吗?
我使用的代码取自另一个 SO 问题,但我做了一些修改
## Perform FFT WITH SCIPY
signalFFT = np.fft.fft(y)
## Get Power Spectral Density
signalPSD = np.abs(signalFFT) ** 2
signalPhase = np.angle(signalFFT)
## Shift the phase py +90 degrees
new_signalPhase =(180/np.pi)*np.angle(signalFFT)+90
## Get frequencies corresponding to signal
fftFreq = np.fft.fftfreq(len(signalPSD), 0.1)
## Get positive half of frequencies
i = fftFreq>0
##
plt.figurefigsize=(8,4)
#plt.plot(fftFreq[i], 10*np.log10(signalPSD[i]));
plt.plot(fftFreq[i], …Run Code Online (Sandbox Code Playgroud) 我想分析麦克风输入的当前频率,以将我的 LED 与播放的音乐同步。我知道如何从麦克风捕获声音,但我不知道 FFT,我在寻找获取频率的解决方案时经常看到它。
我想测试某个频率的当前音量是否大于设定值。代码应该是这样的:
if(frequency > value) {
LEDs on
else {
LEDs off
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在 Java 中实现 FFT。为了更好地理解,这里有一个指向 YouTube 视频的链接,它显示了我正在努力实现的目标。
整个代码:
public class Music {
static AudioFormat format;
static DataLine.Info info;
public static void input() {
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, false);
try {
info = new DataLine.Info(TargetDataLine.class, format);
final TargetDataLine targetLine = (TargetDataLine) AudioSystem.getLine(info);
targetLine.open();
AudioInputStream audioStream = new AudioInputStream(targetLine);
byte[] buf = new byte[256]
Thread targetThread = new Thread() { …Run Code Online (Sandbox Code Playgroud) 我试图通过传递我创建的低通滤波器来使用 fft 模糊图像,但输出结果是一个充满灰色噪声的图像。我只是想遵循这里的基础知识,但我的实现似乎有问题:
from scipy import fftpack
import numpy as np
import imageio
from PIL import Image, ImageDraw
image1 = imageio.imread('image.jpg',as_gray=True)
#convert image to numpy array
image1_np=np.array(image)
#fft of image
fft1 = fftpack.fftshift(fftpack.fft2(image1_np))
#Create a low pass filter image
x,y = image1_np.shape[0],image1_np.shape[1]
#size of circle
e_x,e_y=50,50
#create a box
bbox=((x/2)-(e_x/2),(y/2)-(e_y/2),(x/2)+(e_x/2),(y/2)+(e_y/2))
low_pass=Image.new("L",(image1_np.shape[0],image1_np.shape[1]),color=0)
draw1=ImageDraw.Draw(low_pass)
draw1.ellipse(bbox, fill=255)
low_pass_np=np.array(low_pass)
low_pass_fft=fftpack.fftshift(fftpack.fft2(low_pass))
#multiply both the images
filtered=np.multiply(fft1,low_pass_fft)
#inverse fft
ifft2 = abs(fftpack.ifft2(fftpack.ifftshift(filtered)))
#save the image
imageio.imsave('fft-then-ifft.png', ifft2.astype(np .uint8))
Run Code Online (Sandbox Code Playgroud)