You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python3的pytftb绘制Wigner-Ville分布及频率轴调整咨询

Got it, let's fix that frequency axis issue for your Wigner-Ville Distribution plot in pytftb!

First, a quick reminder: pytftb uses normalized frequency by default (usually ranging from -0.5 to 0.5) because it’s agnostic to your signal’s sampling rate. To convert this to absolute frequency (like Hz), you just need to multiply the normalized values by your signal’s sampling frequency (Fs)—you should have this value from when you acquired or generated your signal (e.g., 1000 Hz for a 1kHz sample rate).

Here are two reliable ways to adjust the plot:

1. Pass absolute frequencies directly to the plot method

If you check pytftb’s docs, the WignerVilleDistribution.plot() method accepts a freqs parameter that lets you override the default normalized frequencies. Here’s how to use it:

import matplotlib.pyplot as plt

# Your existing code
tfr = WignerVilleDistribution(prepack[0])
tfr.run()

# Define your signal's sampling rate (replace with your actual Fs)
Fs = 1000  # Example: 1000 Hz

# Convert normalized frequencies to absolute frequencies
normalized_freqs = tfr.freqs
absolute_freqs = normalized_freqs * Fs

# Plot with custom frequency axis
tfr.plot(show_tf=True, freqs=absolute_freqs)
plt.ylabel("Absolute Frequency (Hz)")
plt.show()

2. Manually tweak the axis after plotting

If the freqs parameter doesn’t work for your pytftb version, you can grab the matplotlib axis object and update the ticks/labels directly:

import matplotlib.pyplot as plt

# Your existing code
tfr = WignerVilleDistribution(prepack[0])
tfr.run()

# Create a figure and axis to modify
fig, ax = plt.subplots()
tfr.plot(show_tf=True, ax=ax)

# Define your sampling rate
Fs = 1000

# Get current normalized frequency ticks (assuming frequency is on the y-axis)
normalized_ticks = ax.get_yticks()
# Convert to absolute frequency
absolute_ticks = normalized_ticks * Fs

# Update the axis ticks and labels
ax.set_yticks(normalized_ticks)
ax.set_yticklabels([f"{tick:.2f}" for tick in absolute_ticks])
ax.set_ylabel("Absolute Frequency (Hz)")

plt.show()

A quick note on interpreting the results: Wigner-Ville Distribution shows the signal’s instantaneous power distribution over time and frequency. For noisy signals, you might see cross-term artifacts (since WVD is a quadratic time-frequency distribution)—just keep that in mind when estimating the original signal’s amplitude.

内容的提问来源于stack exchange,提问作者Danf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:08:33