- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 iPhone 应用程序实现一个低通滤波器,在其中录制声音,然后播放时声音会稍微低沉;就像声音是从另一个房间传来的。
我研究了音频录制和操作的不同选项,发现它有点令人困惑......数字信号处理根本不是强项。我主要研究了 OpenAL,在 EFX 库内部有一个过滤器专门满足我的需要,但 EFX 不包含在 iPhone 中。有没有办法在 iPhone 上使用 OpenAL 复制这种行为?是否有其他选项(例如音频单元)可以提供解决方案?
感谢您的帮助
编辑:
因此,在汤姆的回答和链接之后,我提出了我认为正确的实现。然而,我根本没有得到消音效果,而只是音量减小。这是我目前拥有的(摘要)代码:
文件是使用 AVAudioRecorder 和以下设置录制的:
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
然后我读入该文件并使用以下代码对其进行转换:
// Read in the file using AudioFileOpenURL
AudioFileID fileID = [self openAudioFile:filePath];
// find out how big the actual audio data is
UInt32 fileSize = [self audioFileSize:fileID];
// allocate the memory to hold the file
SInt16 * outData = (SInt16 *)malloc(fileSize);
// Read in the file to outData
OSStatus result = noErr;
result = AudioFileReadBytes(fileID, false, 0, &fileSize, outData);
// close off the file
AudioFileClose(fileID);
// Allocate memory to hold the transformed values
SInt16 * transformData = (SInt16 *)malloc(fileSize);
// Start the transform - Need to set alpha to 0.15 or below to have a noticeable affect
float alpha = 1;
// Code as per Tom's example
transformData[0] = outData[0];
for(int sample = 1; sample < fileSize / sizeof(SInt16); sample ++)
{
transformData[sample] = transformData[sample - 1] + alpha * (outData[sample] - transformData[sample - 1]);
}
// Add the data to OpenAL buffer
NSUInteger bufferID;
// grab a buffer ID from openAL
alGenBuffers(1, &bufferID);
// Add the audio data into the new buffer
alBufferData(bufferID,AL_FORMAT_MONO16,transformData,fileSize,44100);
毕竟,我然后使用标准方法通过 OpenAL 进行播放(我认为这对我的结果没有任何影响,所以我不会将其包含在此处。)
我已经追踪了转换之前和之后的结果,它们对我来说似乎是正确的,即之前的值正如我所期望的那样正向和负向变化,并且 for 循环肯定会展平这些值。但正如我之前提到的,我只看到(在我看来)音量减少,因此我能够增加增益并抵消我刚刚所做的事情。
看来我的值(value)观一定是错误的。对我在这里做错了什么有什么建议吗?
最佳答案
汤姆的答案是以下递归过滤器:
y[n] = (1 - a)*y[n-1] + a*x[n]
H(z) = Y(z)/X(z) = a / (1 - (1 - a)*1/z)
我将在 Python/pylab 中针对 a=0.25、a=0.50 和 a=0.75 绘制此图:
from pylab import *
def H(a, z):
return a / (1 - (1 - a) / z)
w = r_[0:1000]*pi/1000
z = exp(1j*w)
H1 = H(0.25, z)
H2 = H(0.50, z)
H3 = H(0.75, z)
plot(w, abs(H1), 'r') # red
plot(w, abs(H2), 'g') # green
plot(w, abs(H3), 'b') # blue
Pi 弧度/样本是奈奎斯特频率,是采样频率的一半。
如果这个简单的滤波器不够用,请尝试二阶巴特沃斯滤波器:
# 2nd order filter:
# y[n] = -a[1]*y[n-1] - a[2]*y[n-2] + b[0]*x[n] + b[1]*x[n-1] + b[2]*x[n-2]
import scipy.signal as signal
# 2nd order Butterworth filter coefficients b,a
# 3dB cutoff = 2000 Hz
fc = 2000.0/44100
b, a = signal.butter(2, 2*fc)
# b = [ 0.01681915, 0.0336383 , 0.01681915]
# a = [ 1. , -1.60109239, 0.66836899]
# approximately:
# y[n] = 1.60109*y[n-1] - 0.66837*y[n-2] +
# 0.01682*x[n] + 0.03364*x[n-1] + 0.01682*x[n-2]
# transfer function
def H(b,a,z):
num = b[0] + b[1]/z + b[2]/(z**2)
den = a[0] + a[1]/z + a[2]/(z**2)
return num/den
H4 = H(b, a, z)
plot(w, abs(H4))
# show the corner frequency
plot(2*pi*fc, sqrt(2)/2, 'ro')
xlabel('radians')
评估 3dB 截止频率的测试信号fc=2000
:
fc = 2000.0/44100
b, a = signal.butter(2, 2*fc)
# test signal at corner frequency (signed 16-bit)
N = int(5/fc) # sample for 5 cycles
x = int16(32767 * cos(2*pi*fc*r_[0:N]))
# signed 16-bit output
yout = zeros(size(x), dtype=int16)
# temp floats
y = 0.0
y1 = 0.0
y2 = 0.0
# filter the input
for n in r_[0:N]:
y = (-a[1] * y1 +
-a[2] * y2 +
b[0] * x[n] +
b[1] * x[n-1] +
b[2] * x[n-2])
# convert to int16 and saturate
if y > 32767.0: yout[n] = 32767
elif y < -32768.0: yout[n] = -32768
else: yout[n] = int16(y)
# shift the variables
y2 = y1
y1 = y
# plots
plot(x,'r') # input in red
plot(yout,'g') # output in green
# show that this is the 3dB point
plot(sqrt(2)/2 * 32768 * ones(N),'b-')
xlabel('samples')
关于iPhone低通滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505405/
所以我试图增强我的图像的对比度,我发现一位绅士通过在线 Gamma 校正来做到这一点,代码如下: (im/255).^0.45*255 据我了解,1/gammavalue = 0.45,其中 gamm
我有一个包含简单时间序列数据的向量(从 deSolve 矩阵中提取),用于测试目的可以是: x x r for (n in 2:length(x)) r[n] (r) [1] NA 1 1
我有这段实现 Prewitt 边缘检测的代码。我需要做的是只用一个缓冲区来实现它,也就是说,我不会创建图像的拷贝,而是编辑原始图像。所以如果我想改变值 78 的像素,我不能把新值,例如100,直到所有
我想制作一个 FIR 滤波器。我有一个系数数组 (buffer[size]) 和一个数据数组 (filter[size_filter])。我必须在两个数组之间进行卷积: for(j = 0;j < s
我正在尝试制作 IIR 滤波器。我做了FIR滤波器,但是我觉得IIR比FIR难。 我认为 IIR 与 FIR 类似,但它让我感到困惑。 我觉得过滤器是这样的 FIR : y(n) = b0(x[n])
我想在 Python 中通过窗口创建一个基本的高通 FIR 滤波器。 我的代码在下面并且是故意惯用的 - 我知道你可以(很可能)用 Python 中的一行代码完成它,但我正在学习。我使用了一个带有矩形
我正在尝试用树莓派创建一个相机来检测在走廊中移动的人(这里我假设只有移动的东西是人),并识别那些在该区域花费太多时间的人(使用计时器),我使用背景减法来检测运动并尝试使用基于相关性的跟踪器(例如 MO
我正在研究用于特征提取的超像素。我已经成功地将超像素功能应用于图像。 A = imread('kobi.png'); [L,N] = superpixels(A,5); figure BW = bou
你好 我需要在应用中使用这个 Kolmogorov 过滤器。您将一些测量数据放入其中,并使用过滤器对其进行一些平滑处理。我试着用“nchoosek”来做,但是当我尝试为 50 或更多的 I 做这件事时
我正在尝试在具有静态掩码 5x5 并在 applyFilter() 函数中进行卷积编码的图像上实现 LoG 过滤器。然而,无论我使用什么面具,我都会得到奇怪的结果。保存图像而不通过函数传递它是有效的,
我已经在 Haskell 中实现了一个 FIR 滤波器。我不太了解 FIR 滤波器,我的代码很大程度上基于现有的 C# 实现。因此,我觉得我的实现有太多的 C# 风格,而不是真正的 Haskell 风
我需要制作一个简单的带通音频滤波器。现在我使用了这个简单的 C++ 类:http://www.cardinalpeak.com/blog/a-c-class-to-implement-low-pass
CUDA NPP 库支持使用 nppiFilter_8u_C1R 命令过滤图像,但不断出现错误。我可以毫无问题地启动并运行 boxFilterNPP 示例代码。 eStatusNPP = nppiFi
我是 OpenCV 和 gabor 过滤器的新手,只想获得这样的 gabor 小波: 我在 Java 中使用这个 OpenCV 代码: double sigma_bar = 40; double th
我正在使用 FIR 滤波器对音频进行过采样。这是一个简单的典型窗口 sinc,即一个被截断和窗口化的 sinc 函数。像往常一样,它需要过去和“ future ”的样本才能工作。实际上,这意味着音频输
目前我正在尝试实现 FIR 低通滤波器。 FIR 系数在 MATLAB 中计算。现在我需要用 C++ 实现 FIR 算法。 我将一个类定义为过滤器,将 FIR 的一个函数定义为: double * F
我有一个用 C 语言实现 FIR 滤波器的家庭作业,我想知道您是否认为我理解正确。我认为解决问题的程序是: #include float FIRfloats[5]; void floatFIR(fl
我希望对图像的每条水平线应用频域滤波器,例如低通或带通。这可能使用 opencv 吗? 最佳答案 我认为您需要详细说明您的问题。也许,举一些具体的例子。 如果我将您的问题解释为: 你有一张 10 x
我的问题与 A. Levy 的解释相关: Analyze audio using Fast Fourier Transform 如何在这些复数上生成带通滤波器... [-636.00000000 +0
FIR 滤波器有一个算法,但它是 float : FIR filter implementation in C programming 如果我想要一个符合此规范的定点算法,我该怎么做? the FIR
我是一名优秀的程序员,十分优秀!