Python 中的音频分离

发布于 2025-01-19 23:55:07 字数 326 浏览 1 评论 0原文

我正在从事一个书呆子项目以获取乐趣。 该项目是录制在录音带上的模拟视频。 挑战在于带宽非常有限。 我有一种以 24fps 录制彩色视频和单声道音频的方法。 我的视频工作正常,但需要一些音频方面的帮助。 这是我必须使用的信号:

注意:使用 YUV 色彩空间

左通道: 同步脉冲和 Y(亮度)数据

右通道: U& V(色度)数据 混合着 单声道音频(14kHz 幅度调制)

我不确定如何将颜色数据与音频分开。 我已经用 numpy 研究了一些 FFT,但还没有完全理解它。

基本上我需要的是一个带滤波器来分离 13990Hz - 14010Hz (以考虑哇和颤振)

I'm working on a nerd project for fun.
The project is analog video recorded onto an audio cassette.
The challenge lies in the very limited bandwidth.
I have a method to record color video at 24fps along with mono audio.
I got the video stuff working but need some help with the audio.
Here is the signal I have to work with:

Note: using YUV color space

Left channel:
Sync Pulses &
Y (luma) data

Right channel:
U & V (chroma) data
mixed with
Mono audio (Amplitude Modulated at 14kHz)

I'm not sure how to separate the color data from the audio.
I've looked into FFT with numpy a bit but am not fully understanding it.

Basically what I need is a band filter to separate 13990Hz - 14010Hz (to account for wow and flutter)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2025-01-26 23:55:07

好的,这是一个小的测试代码,显示了它的工作原理。

import matplotlib.pyplot as plt
import numpy as np
import math as mt
from scipy.signal import butter, sosfilt, lfilter

def butter_bandpass(lowcut, highcut, fs, order=5):
        nyq = 0.5 * fs
        low = lowcut / nyq
        high = highcut / nyq
        sos = butter(order, [low, high], analog=False, btype='band', output='sos')
        return sos

def bandpass(data, lowcut, highcut, fs, order=5):
        sos = butter_bandpass(lowcut, highcut, fs, order=order)
        y = sosfilt(sos, data)
        return y

def bandstop(data, lowcut, highcut, fs, order):
    nyq = 0.5 * fs
    low = lowcut / nyq
    high = highcut / nyq

    i, u = butter(order, [low, high], btype='bandstop')
    y = lfilter(i, u, data)
    return y

# Modulation & Bandpass Test

# note that the data is just test data and isn't actual audio or color data

Fs = 192000 # rate
f = 14000 # carrier frequency (Hz)
sample = 192000 # total length

x = np.arange(sample)
signal = (np.sin(2 * np.pi * 1000 * x / Fs)) # audio
noise = 0.5*(np.sin(2 * np.pi * 10000 * x / Fs)) # color data

y = [] # combined AM audio and color data

for t in range(0, sample, 1):
    amp = (signal[t] + 1) / 2
    sine = amp * (mt.sin(2*mt.pi * f * t / Fs))
    y.append((sine+noise[t])/2)

# y is raw signal
w = bandpass(y, 1600, 1800, 24000, order=1) # only AM audio signal
v = bandstop(y, 1450, 1950, 24000, order=6) # Rest of the signal
# Note: lowered the sample rate input for the filters (and frequencies accordingly) 
# since it didn't like 192khz

# The color data does get impacted by the bandstop filter but this is 
# mostly not noticable as the YUV color space is used meaning
# the color resolution can be reduced drastically without noticable effect
    
plt.plot(y)
plt.plot(w)
plt.plot(v)
plt.xlabel('sample')
plt.ylabel('amplitude')
plt.show()

如果您想查看完整的代码以及信号的波动和输出的示例视频,请参见一个链接:

Ok here is a little test code that shows how this works.

import matplotlib.pyplot as plt
import numpy as np
import math as mt
from scipy.signal import butter, sosfilt, lfilter

def butter_bandpass(lowcut, highcut, fs, order=5):
        nyq = 0.5 * fs
        low = lowcut / nyq
        high = highcut / nyq
        sos = butter(order, [low, high], analog=False, btype='band', output='sos')
        return sos

def bandpass(data, lowcut, highcut, fs, order=5):
        sos = butter_bandpass(lowcut, highcut, fs, order=order)
        y = sosfilt(sos, data)
        return y

def bandstop(data, lowcut, highcut, fs, order):
    nyq = 0.5 * fs
    low = lowcut / nyq
    high = highcut / nyq

    i, u = butter(order, [low, high], btype='bandstop')
    y = lfilter(i, u, data)
    return y

# Modulation & Bandpass Test

# note that the data is just test data and isn't actual audio or color data

Fs = 192000 # rate
f = 14000 # carrier frequency (Hz)
sample = 192000 # total length

x = np.arange(sample)
signal = (np.sin(2 * np.pi * 1000 * x / Fs)) # audio
noise = 0.5*(np.sin(2 * np.pi * 10000 * x / Fs)) # color data

y = [] # combined AM audio and color data

for t in range(0, sample, 1):
    amp = (signal[t] + 1) / 2
    sine = amp * (mt.sin(2*mt.pi * f * t / Fs))
    y.append((sine+noise[t])/2)

# y is raw signal
w = bandpass(y, 1600, 1800, 24000, order=1) # only AM audio signal
v = bandstop(y, 1450, 1950, 24000, order=6) # Rest of the signal
# Note: lowered the sample rate input for the filters (and frequencies accordingly) 
# since it didn't like 192khz

# The color data does get impacted by the bandstop filter but this is 
# mostly not noticable as the YUV color space is used meaning
# the color resolution can be reduced drastically without noticable effect
    
plt.plot(y)
plt.plot(w)
plt.plot(v)
plt.xlabel('sample')
plt.ylabel('amplitude')
plt.show()

If you want to check out the full code along with a wav of the signal and an example video of the output here's a link:
https://drive.google.com/drive/folders/18ogpK4n43d_Q0tjdmlm2uIRZBIrRu01y?usp=sharing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文