【问题标题】:Amplitude modulation of a brown noise generated with acoustics package in pythonpython中声学包产生的棕色噪声的幅度调制
【发布时间】:2018-09-05 23:54:02
【问题描述】:

我对 python 完全陌生,所以我尝试阅读和学习我能做的,但我似乎无法做我想做的事,而且我还没有在 Stack Overflow 或其他来源找到解决方案。我的目标是创建一个brown noise 的波形文件,并在给定频率下进行幅度调制。我想生成棕色噪声并对其进行调制。

我打算使用python acoustics package,不幸的是我不明白如何使用这些函数来创建彩色噪声。我查看了示例,但没有看到有关使用彩色噪声函数的示例。

谁能帮我解决这个问题?谢谢。


这是我的代码:

""" This file proposes to modulate a given wav file"""

import wave
import struct
import time
import math
import random
import acoustics

###########################################
# General variables
outputName = "waveXP.wav"
frequencyModulation = 40
period = 1/frequencyModulation
duration = 1
maxVolume = 23000.0
framerate = 44100


###########################################
# Ask the user about the output file name
temp = ""
temp = input("Name of the output wave file to import (with extension):")
if temp != "":
    outputName = str(temp)

# Ask the user about the modulation frequency wanted
temp = ""
temp = input("Modulation frequency wanted (in hertz):")
if temp != "":
    frequencyModulation = int(temp)

period = 1/frequencyModulation

# Ask the user about the duration wanted
temp = ""
temp = input("Duration wanted (in seconds):")
if temp != "":
    duration = int(temp)

print("------------------------")


###########################################
# Create the output wave file
newWaveFile = wave.open(outputName, "w")

# Define parameters of the wave file
# nchannels = 1 for mono; sampwidth = 2 for 2 bytes per sample; framerate = 44100 for wave file;
# comptype = "NONE" for no compression support; compname = 'not compressed' for no compression support
newWaveFile.setparams([1, 2, framerate, duration, 'NONE', 'not compressed'])

# Generate noise
newWaveFile.writeframes(struct.pack('h'*framerate*duration, *int(maxVolume*0.7*acoustics.generator.brown(framerate*duration))))

# Close wave files
originalWaveFile.close()
newWaveFile.close()

【问题讨论】:

  • 为“棕色噪音”点赞
  • 我想你可能会从code review得到更好的回答。
  • @user3351605 谢谢你的提示,我会尝试代码审查
  • @user3351605 我不太确定;由于第(1)项。代码审查仅适用于功能完整的代码,如果出现错误或意外行为,即处于调试状态且不在主题范围内。
  • 关于这个问题本身,您可以通过将其缩减为一次一个特定问题来使其变得更好。现在它太宽泛了。

标签: python wave modulation noise-generator acoustics


【解决方案1】:

看起来你提议的库已经有一个棕色噪声发生器:

http://python-acoustics.github.io/python-acoustics/generator.html

假设您只想将单个调制作为幅度增益应用于整个信号,那么您可能希望以信号的采样率对调制进行采样,并将调制(乘以某个比例因子)添加到棕色噪声信号。或者,您可以将信号乘以调制,但这会产生更极端的效果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    相关资源
    最近更新 更多