rms归一化_将FFT频谱幅度归一化为0dB

本文介绍了如何使用Python的scipy库来实现RMS归一化的FFT频谱分析,参照Audacity的Welch算法进行信号处理。通过设置合适的参数,如窗口大小、重叠和窗函数类型,计算并显示功率谱密度。归一化过程包括将最大振幅的正弦波作为参考,设置0dB,并将低于-90dB的频谱忽略不计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在对Audacity做了一些逆向工程后,这里给出了一些答案。首先,他们使用Welch algorithm来估计PSD。简而言之,它将信号分割成重叠段,应用一些窗口函数,应用FFT并对结果进行平均。主要是因为这有助于在存在噪声时获得更好的结果。总之,在提取了必要的参数后,这里的解决方案近似于Audacity的光谱图:import numpy as np

from scipy.io import wavfile

from scipy import signal

from matplotlib import pyplot as plt

segment_size = 512

fs, x = wavfile.read('sine3k6k.wav')

x = x / 32768.0 # scale signal to [-1.0 .. 1.0]

noverlap = segment_size / 2

f, Pxx = signal.welch(x, # signal

fs=fs, # sample rate

nperseg=segment_size, # segment size

window='hanning', # window type to use

nfft=segment_size, # num. of samples in FFT

detrend=False, # remove DC part

scaling='spectrum', # return power spectrum [V^2]

noverlap=nover

在以下这段代码的基础上增加短时功率谱以及倒谱的matlab代码%% 读取音频文件 [audio, Fs] = audioread('留得青山在,不怕没柴烧.wav'); audio = mean(audio, 2); % 转为单声道 %% 基础参数计算 duration = length(audio)/Fs; % 音频时长 t = (0:length(audio)-1)/Fs; % 时间轴 %% 噪声分析(假设前50ms为静音段) noise_samples = round(0.05*Fs); % 取前50ms作为噪声样本 noise_energy = rms(audio(1:noise_samples)); % 噪声能量 signal_energy = rms(audio); % 整体能量 SNR = 20*log10(signal_energy/noise_energy); % 信噪比估计 %% 清浊音判断参数设置 frame_size = round(0.03*Fs); % 30ms帧长 overlap = round(0.02*Fs); % 20ms重叠 threshold_ZCR = 0.15; % 过零率阈值 threshold_E = 0.05; % 能量阈值 %% 分帧处理 frames = buffer(audio, frame_size, overlap, 'nodelay'); num_frames = size(frames, 2); %% 特征提取 energy = zeros(1, num_frames); ZCR = zeros(1, num_frames); pitch = zeros(1, num_frames); for n = 1:num_frames frame = frames(:, n); % 短时能量 energy(n) = sum(frame.^2); % 过零率 ZCR(n) = 0.5*sum(abs(diff(sign(frame)))); % 基频估计(自相关法) [r, lags] = xcorr(frame); r = r(lags>=0); [peaks, locs] = findpeaks(r); if ~isempty(peaks) [~, idx] = max(peaks(peaks>0.3*max(peaks))); pitch(n) = Fs/locs(idx+1); end end %% 清浊音分类 voiced = (energy > threshold_E) & (ZCR < threshold_ZCR) & (pitch > 80 & pitch < 300); %% 时频分析 % 语谱图绘制 figure('Color','white','Position',[100 100 1200 800]) subplot(4,1,1) spectrogram(audio, hamming(512), 256, 512, Fs, 'yaxis'); title('语谱图') %% 波形+基频轨迹 subplot(4,1,2) plot(t, audio) hold on frame_time = (0:num_frames-1)*(frame_size-overlap)/Fs + frame_size/(2*Fs); plot(frame_time(voiced), pitch(voiced), 'ro') title('波形与浊音段基频') xlabel('Time (s)'), ylabel('Amplitude/F0 (Hz)') %% 能量曲线 subplot(4,1,3) plot(frame_time, energy/max(energy)) hold on plot([0 duration], [threshold_E threshold_E], 'r--') title('归一化能量曲线') ylabel('Energy') %% 过零率 subplot(4,1,4) plot(frame_time, ZCR/max(ZCR)) hold on plot([0 duration], [threshold_ZCR threshold_ZCR], 'r--') title('归一化过零率') xlabel('Time (s)'), ylabel('ZCR') %% 参数报表输出 %%fprintf('===== 语音特性分析报告 =====\
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值