我需要将0.0到1.0的值转换为它们的颜色表示(每个值都是一个像素).我正在制作光谱图,因此像素应该是最亮的值(如下图所示).
我怎样才能做到这一点?我在C#工作,但普遍适用的解决方案也很好.
例:

如何用Python绘制A[i,j]这样的2D矩阵:
i 是x轴j 是y轴A[i,j] 是一个0到100之间的值,必须用颜色绘制(例如:0 =蓝色,100 =红色)有没有Python功能?
(注:我不想,做频谱对我来说,如函数specgram,因为我想计算自己的信号的FFT,因此我只需要绘出一个矩阵颜色的功能)

我正在尝试获取wavpython 中文件的频谱图。但它给出了错误:
“模块”对象没有属性“频谱图”。
这是代码:
import scipy.io.wavfile
from scipy.io.wavfile import read
from scipy import signal
sr_value, x_value = scipy.io.wavfile.read("test.wav")
f, t, Sxx= signal.spectrogram(x_value,sr_value)
Run Code Online (Sandbox Code Playgroud)
还有什么方法可以获取wav文件的频谱图吗?
nfft参数在这个函数中意味着什么?请参阅此链接以获取文档https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.signal.spectrogram.html
我想从wav文件中获取一个频谱图,然后将其保存为png,但是我只需要图像的内容(而不是轴或其他任何东西)。我遇到了
Matplotlib绘制的这些问题:删除轴,图例和空白区域
scipy:没有框架,轴,仅内容的savefig
我也阅读了Matplotlib文档,但似乎无用,因此上述问题的答案已过时或我做错事是因为简单
plt.savefig('out.png', bbox_inches='tight', pad_inches=0)
不做我想实现的目标。最初,我尝试遵循此指南,但是代码崩溃了。然后,我尝试了这种方法,但是由于它已经过时,因此我对其进行了一些修改:
import matplotlib.pyplot as plt
from scipy.io import wavfile
import numpy as np
def graph_spectrogram(wav_file):
rate, data = wavfile.read(wav_file)
pxx, freqs, bins, im = plt.specgram(x=data, Fs=rate, noverlap=384, NFFT=512)
plt.axis('off')
plt.savefig('sp_xyz.png', bbox_inches='tight', dpi=300, frameon='false')
if __name__ == '__main__': # Main function
graph_spectrogram('...')
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
也许它不可见,但是内容周围有一个白色边框(从最大到最小):左,下,上,右。我想要相同的图像,但只包含内容,没有其他内容。我该如何实现?我使用python 3.6和Matplotlib 2.0.2。
我有一个用于音乐和语音分析的 PyQt 加 pyqtgraph 程序,我想绘制 wav 文件的频谱(使用 scipy python 包计算)。我可以在 matplotlib 中完成,但由于 matplotlib 的性能,我需要切换到 pyqtgraph,但我找不到任何一致的方法来将 scipy.signal.spectrogram 的输出绘制到 pyqtgraph
谢谢!
我是 python 和 librosa 的新手。我正在尝试按照这种方法进行语音识别:声学前端
我的代码:
import librosa
import librosa.display
import numpy as np
y, sr = librosa.load('test.wav', sr = None)
normalizedy = librosa.util.normalize(y)
stft = librosa.core.stft(normalizedy, n_fft = 256, hop_length=16)
mel = librosa.feature.melspectrogram(S=stft, n_mels=32)
melnormalized = librosa.util.normalize(mel)
mellog = np.log(melnormalized) - np.log(10**-5)
Run Code Online (Sandbox Code Playgroud)
问题是,当我将 librosa.util.normalize 应用于变量 mel 时,我希望值介于 1 和 -1 之间,但实际上并非如此。我错过了什么?
我正在尝试使用 ffmpeg 和 gnuplot 来绘制一些音频频谱,我正在关注此ffmpeg 文档链接。
现在我问-这行后面的“破折号”是什么意思,它应该是一个文件名:ffmpeg命令的最后一个元素应该是输出文件,但运行命令后目录中-f data没有命名的文件。-
ffmpeg -y -i in.wav -ac 1 -filter:a aresample=8000 -map 0:a -c:a pcm_s16le -f data - | gnuplot -p -e "plot '<cat' binary filetype=bin format='%int16' endian=little array=1:0 with lines;"
Run Code Online (Sandbox Code Playgroud)
我查看了 ffmpeg 文档,但没有找到任何内容。
从音频文件中提取数据字节时,以下两种实现有什么区别?
该文件是一个.wav文件,我想只提取数据,没有标题或任何其他东西.
实施1:
public byte[] extractAudioFromFile(String filePath) {
try {
// Get an input stream on the byte array
// containing the data
File file = new File(filePath);
final AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(file);
byte[] buffer = new byte[4096];
int counter;
while ((counter = audioInputStream.read(buffer, 0, buffer.length)) != -1) {
if (counter > 0) {
byteOut.write(buffer, 0, counter);
}
}
audioInputStream.close();
byteOut.close();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}// end catch
return ((ByteArrayOutputStream) byteOut).toByteArray();
}
Run Code Online (Sandbox Code Playgroud)
实施2:
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试位于 Octave 信号包中的 specgram 函数,但我对 specgram 的输入/输出变量有点困惑。我想要做的是能够将频谱图数据放入一个数组中,该数组将显示频率开始和停止时的频率和时间长度。
请参阅下面的示例代码:我试图让数组显示 t1 的长度为 7hz,t2 为 12hz,t3 为 2hz。我该怎么做呢?
我正在使用 ubuntu 12.04 和 Octave 3.2.4 以及信号包 1.0.11
% combines sig with spectra plot
clear all,clc,tic;
fs=1000;
t1=linspace(0,2*pi,fs/0.1); %need to round off no decimals
t2=linspace(0,2*pi,fs/0.3); %need to round off no decimals
t3=linspace(0,2*pi,fs/0.6); %need to round off no decimals
%Create signal in different arrays
y1=sin(7*t1);
y2=sin(12*t2);
y3=sin(2*t3);
%append arrays to test specgram
yt = [y1 y2 y3];
%plot(yt) %will show combined plot
%Spectrum section
yts=specgram(yt',20,500, 2,1); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用matplotlib绘制信号和信号的频谱图,但是...我只得到我的信号的第一个值(样本)的频谱图(就像30000中的60个......).
这是一个非常长的文件,这就是我想只绘制第一个30000样本的原因.
这是代码:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Data=pd.read_csv('MySignal.txt',
skiprows=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],
header=0)
print(Data.head())
DataI=Data['Sig'].tolist()
print(len(Data.index))
DataI=DataI[0:30000]
NFFT = 200 # the length of the windowing segments
Fs = 500 # the sampling rate
# plot signal and spectrogram
t=range(len(DataI))
ax1 = plt.subplot(211)
plt.plot(t, DataI)
plt.subplot(212, sharex=ax1)
Pxx, freqs, bins, im = plt.specgram(DataI, NFFT=NFFT,
Fs=Fs,noverlap=100, cmap=plt.cm.gist_heat)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我不太了解plt.specgram如何工作,所以我不明白问题在哪里...
非常感谢 !
我计算了 uint8 I/Q 数据的 STFT,并将其存储在一个 numpy 矩阵中,其中每一行存储一个窗口的 STFT,如下面的 sudo 代码所示。
#k= length of window
#fs= Sampling frequency
#n= Number of STFT calculated
#matrix= Initially empty numpy array
for i in range(0,n):
t=data[start:end,:] #start & end calculated with each iteration
t=t.flatten()
t=t-127.5
array = np.empty(t.shape[0]//2, dtype=np.complex128)
array.real = t[::2]
array.imag = t[1::2]
transform=(np.fft.fft(temp_array))
line = 2*abs(transform)/k
#Inserting row into numpy array
if(i==0):
matrix = np.hstack((matrix, line))
else:
matrix = np.vstack((matrix, line))
Run Code Online (Sandbox Code Playgroud)
现在如何绘制频率与时间的频谱图?
spectrogram ×13
python ×7
audio ×3
matplotlib ×3
plot ×3
scipy ×3
numpy ×2
c# ×1
colors ×1
ffmpeg ×1
fft ×1
java ×1
librosa ×1
matlab ×1
mfcc ×1
octave ×1
parameters ×1
pixel ×1
pyqtgraph ×1
python-2.7 ×1
python-3.x ×1
wav ×1