用python中的声学包生成的棕色噪声的振幅调制。

问题描述 投票:1回答:1

我对python完全是个新手,所以我试着阅读和学习我可以学习的东西,但我似乎无法做到我想要的,我在Stack Overflow或其他来源上没有找到解决方案。我的目的是创建一个波浪文件 褐色噪音 在给定的频率下进行振幅调制。我想产生棕色噪声并对其进行调制。

我打算使用 蟒蛇声学包不幸的是,我不明白如何使用函数来创建彩色噪声。我看了例子,但我没有看到彩色噪声函数使用的例子。

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


这是我的代码。

""" 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()
python wave modulation noise-generator acoustics
1个回答
0
投票

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

http:/python -acoustics.github.iopython -acousticsgenerator.html。

假设你想只将一个调制作为幅度增益应用到整个信号中,那么你要以信号的采样率对你的调制进行采样,并将调制(乘以某个比例因子)加到棕色噪声信号中。或者,你也可以将信号乘以调制,但那会是一个更极端的效果。

© www.soinside.com 2019 - 2024. All rights reserved.