如何在声卡上输出方波

发布于 2024-10-02 12:50:41 字数 179 浏览 3 评论 0原文

我想在我的声卡上创建一个数字(方波)信号。如果我产生高频,效果会很好。但是,由于我无法在声卡上输出 DC,因此对于较低频率,生成的数字位将全部慢慢淡入 0。

这就是声卡高通对我的方波所做的操作:

当信号通过高通时将变成方波,其数学函数是什么?

理想情况下,该解决方案在 gnuplot 中演示。

I would like to create a digital (square) signal on my sound card. It works great if I generate high frequencies. But, since I can't output DC on a sound card, for lower frequencies the resulting digital bits will all slowly fade to 0.

This is what the soundcards high pass does to my square wave:
http://www.electronics-tutorials.ws/filter/fil39.gif

What's the mathematical function of a signal, that, when passed through a high pass will become square?

Ideally, the solution is demonstrated in gnuplot.

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

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

发布评论

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

评论(5

临走之时 2024-10-09 12:50:41

声卡会消除波形中的低频,因此您需要在传递给它的内容中将低频增强一些。

方波包含许多频率(请参阅此处有关傅立叶级数的部分)。我怀疑生成校正方波的最简单方法是对傅立叶级数求和,提高低频分量的幅度以补偿声卡中的高通滤波器。

为了计算出每个低频分量的提升量,您首先需要测量声卡中高通滤波器的响应,方法是输出各种频率但幅度恒定的正弦波,并测量每个频率的比率r(f) 输出幅度与输入幅度的比值。然后,通过将方波傅立叶级数中每个频率分量f的幅度乘以1/r(f)( '逆滤波器')。

声卡中的高通滤波器也可能调整信号的相位。在这种情况下,最好将高通建模为 RC 滤波器(即可能是声卡如何进行滤波),并反转幅度和相位响应。

The sound card cuts out the low frequencies in the waveform, so you need to boost those by some amount in what you pass to it.

A square wave contains many frequencies (see the section on the Fourier series here). I suspect the easiest method of generating a corrected square wave is to sum a Fourier series, boosting the amplitudes of the low frequency components to compensate for the high-pass filter in the sound card.

In order to work out how much to boost each low frequency component, you will first need to measure the response of the high-pass filter in your soundcard, by outputting sine waves of various frequencies but constant amplitude, and measuring for each frequency the ratio r(f) of the amplitude of the output to the amplitude of the input. Then, an approximation to a square wave output can be generated by multiplying the amplitude of each frequency component f in the square wave fourier series by 1/r(f) (the 'inverse filter').

It's possible that the high-pass filter in the soundcard also adjusts the phase of the signal. In this case, one might be better off modelling the high pass as an RC filter, (which is probably how the soundcard is doing the filtering), and invert both the amplitude and phase response from that.

徒留西风 2024-10-09 12:50:41

之前的一些答案已经正确地指出,正是高通滤波器(声卡输出上的交流耦合电容器)阻止了低频方波“停留”,因此它们快速衰减。

没有办法从软件中完全击败这个过滤器,否则它就不会存在,不是吗?如果您可以忍受较低频率下的较低振幅方波,您可以通过发送类似 三角波。从瞬态分析的角度来看,这里的工作原理是,当耦合电容器放电(阻塞直流)时,您将增加其偏置电压以抵消放电,从而使方波保持一段时间的稳定状态。当然,您最终会耗尽 PCM 余量(您不能无限期地不断增加电压),因此 24 位卡在这方面比 16 位卡更好,因为它可以为您提供更高的分辨率。另一种更抽象的思考方式是,RC 过滤器充当微分器,因此为了获得方波的平坦峰值,您需要在输入处为其提供三角波的平坦斜率。但这是一种理想化的行为。

作为概念的快速证明,以下是 60Hz ±1V 三角波信号通过 1Kohm 负载上的 1uF 耦合电容时的情况;它近似于 ±200mV 方波在此处输入图像描述

请注意,负载的阻抗/电阻在这里非常重要;如果将其降低到 100 欧姆,则输出幅度会急剧下降。这就是耦合电容如何阻止扬声器/耳机上的直流电,因为这些设备的阻抗远低于 1Kohm。

如果今天晚些时候我能找到更多时间,我将添加一个更好的模拟,使用形状更好的刺激而不是简单的三角波,但我无法从普通的基于网络的电路模拟器软件中获得这一点......

好吧,如果你够幸运的话,你可以买到一张 0.99 美元的 USB 声卡,制造商在这方面做了很多偷工减料,以至于他们没有安装耦合帽。 https://www.youtube.com/watch?v=4GNRzwfP7RE

Some of the previous answers have correctly noted that it is the high-pass filter (AC coupling capacitor on the soundcard's output) is what is preventing the low frequency square waves from "staying on" so they decay quickly.

There is no way to completely beat this filter from software or it wouldn't be there, now would it? If you can live with lower amplitude square waves at the lower frequencies, you can approximate them by sending out something like a triangle wave. From a transient analysis perspective, the theory of operation here is that as the coupling capacitor is discharging (blocking DC) you are increasing its bias voltage to counteract that discharge thus maintaining the square wave's plateau for a while. Of course you eventually run out of PCM headroom (you can't keep increasing the voltage indefinitely), so a 24-bit card is better in this respect than a 16-bit one as it will give you more resolution. Another, more abstract way to think of this is that the RC filter works as a differentiator, so in order to get the flat peaks of the square wave you need to give it the flat slopes of the triangle wave at the input. But this is an idealized behavior.

As quick proof of concept, here's what a 60Hz ±1V triangle signal becomes when passing through a 1uF coupling cap on a 1Kohm load; it approximates a ±200mV square waveenter image description here

Note that the impedance/resistance of the load matters quite a bit here; if you lower it to, say, 100ohm the output amplitude decrease dramatically. This is how the coupling caps block DC on speakers/headphone because these devices have much lower impedance than 1Kohm.

If I can find a bit more time later today, I'll add a better simulation, with a better shaped stimulus instead of the simple triangle wave, but I can't get that from your average web-based circuit simulator software...

Well, if you're lucky you can get one of those $0.99 USB sound cards where the manufacturer has cut corners so much that they didn't install coupling caps. https://www.youtube.com/watch?v=4GNRzwfP7RE

柠檬 2024-10-09 12:50:41

不幸的是,您无法获得方波的良好近似值。声音硬件有意限制转换速率,并且无法产生超出其预期频率范围的下降或上升沿。

您可以通过每 N 个样本交替使用高低 PCM 代码(+max、-max)来近似严重变形的方波。

Unfourtunately, you cannot get a good approximation of a square wave. Sound hardware is intentionally slew rate limited and would not be able to produce a falling or rising edge beyond its intended frequency range.

You can approximate a badly deformed square wave by alternating a high and low PCM code (+max, -max) every N samples.

一抹淡然 2024-10-09 12:50:41

您实际上无法产生真正的方波,因为它具有无限的带宽。不过,您可以在 10 Hz 到 1 kHz 之间的频率下产生合理的方波近似值(低于 10 Hz,声卡等的模拟部分可能会出现问题,而高于 1 kHz 左右,近似值将变得越来越不准确) ,因为您只能再现相对少量的谐波)。

生成波形时,样本值将在+/-某个值(例如满量程)之间交替,对于 16 位 PCM 流,该值将是 -32767 和 +32767。频率将由这些样本的周期决定。例如,对于 44.1 kHz 采样率,如果您有 100 个 -32767 样本,然后有 100 个 +32767 样本,即周期 = 200 个样本,那么方波的基频将为 44.1 kHz / 200 = 220 Hz。

You can't actually produce a true square wave, because it has infinite bandwidth. You can produce a reasonable approximation of a square wave though, at frequencies between say 10 Hz and 1 kHz (below 10 Hz you may have problems with the analogue part of your sound card etc, and above around 1 kHz the approximation will become increasingly inaccurate, since you can only reproduce a relatively small number of harmonics).

Tp generate the waveform the sample values will just alternate between +/- some value, e.g. full scale, which would be -32767 and +32767 for a 16 bit PCM stream. The frequency will be determined by the period of these samples. E.g. for a 44.1 kHz sample rate, if you have say 100 samples of -32767 and then 100 samples of +32767, i.e. period = 200 samples, then the fundamental frequency of your square wave will be 44.1 kHz / 200 = 220 Hz.

梦行七里 2024-10-09 12:50:41

我找到了一个基于它构建的应用程序。

http://www.blogger.com/blogger .g?blogID=999906212197085612#editor/target=post;postID=7722571737880350755

您可以生成您想要的格式,甚至您需要的模式。

该代码使用SLIMDX

I found an application that I build on it.

http://www.blogger.com/blogger.g?blogID=999906212197085612#editor/target=post;postID=7722571737880350755

you can generate the format you want and even the pattern you need.

The code uses SLIMDX.

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