I am an extreme moderate

May 25, 2011

Don’t abuse Nyquist-Shannon theorem like this

Filed under: Uncategorized — niezmierniespokojny @ 7:56 pm

One common misconception among audiophiles goes like this:

1. Whittaker-Nyquist-Kotielnikov-Shannon theorem states that if your sampling rate is 2*X Hz, you can perfectly restore signals of frequencies below X Hz
2. Human hearing limits are (well) below 22050 Hz
3. Ergo: Music can be encoded at 44100 and anything more is pure waste, snake oil, etc.

So how is it in practice? Let’s do a quick check, listen to the following file:
Click
It’s sampled at 8000 Hz and contains a 3999.5 Hz sine wave. Sine wave has a nice property: its sound level is constant. So why what you hear is clearly pulsating? Because it’s wasn’t correctly preserved. Why? Because Nyquist-Shannon theorem doesn’t work here. Why? Because decoder doesn’t use Shannon-Nyquist algorithm to recreate it. And why? Because music rarely consists on infinite repetitions of the same signal, and that’s what Shannon-Nyquist theorem requires to work.

Now before I get to details, a remark: I never studied signalling theory, what I know is general mathematical sense and peeks at Wikipedia. I might get some details wrong. However my understanding proved good enough to predict the presented effect, so I think it’s good enough to do some talk.
[ADDED]
Some people pointed out that the example is bad. They use too advanced language, but what I think they meant is it’s because good filtering in a digital-to-analog converter could fix the pulsation, which negates a major part of my post, but doesn’t change the merit.
I’m learning signal processing basics to understand the issue better.
Thanks for all helpful comments.
[/ADDED]
[ADDED2]
I half-read a book on signal processing and then got a very hard month, got no time for anything. Now I’m returning to life, but over the time lost the will to continue investigating what was wrong. I leave it for now. I think I’ll return to it one day, I sure will be much more careful when talking about related issues and probably one day I’ll again want to learn it enough to go on and do it. But it’s nothing sure, I may leave it forever.
[/ADDED2]
Also, the following assumes you understand signal sampling. If you don’t, take a quick look here.

Let’s look at the signal.
I took a series of close-ups before getting to particular samples, so you have an overview where you are:

1

2

3

4

We have samples oscillating with frequency of (exactly!) 4000 Hz. Amplitude starts small but grows up to maximum, then gets back down.
I think the best explanation of why it happened is to draw a sine with frequency X and sampling rate a little over 2*x:

sine

Does it resemble something? Every 2 samples, you land close of where you’ve been previously, but not exactly, the wave goes slower than 2 samples, so you sample it further back. You go further and further back and at some point you’re at the peak. And so on as long as you wish.

Now this is just example of what can happen, purely artificial, obviously. But you can experience different sampling artifacts. And not only with frequencies close to the maximum, with lower ones the problem is just smaller.

To sum up:
No, 44100 Hz is not enough to perfectly preserve audible frequencies. Neither is 96 kHz or more. That’s because so commonly quoted Nyquist-Shannon theorem doesn’t work with finite signals and decoders go the simpler way. And good for them.

There’s also a very important question whether such imperfections matter in practice. Maybe using higher sampling rates indeed doesn’t produce audible improvements?
This is not a point of this post, but I’ll answer it anyway: I don’t know.

UPDATE:
Thanks to bandpass who spotted that the file was actually 44.1 kHz, Audacity exported it badly and I failed to notice. Now I replaced it with a correct file. It doesn’t sound any different though.

May 22, 2011

The big 3

Filed under: Uncategorized — niezmierniespokojny @ 8:22 pm

I’m on the way to leave Windows for Unix. There is only one big obstacle: software compatibility. I have to move the most important tools or find and learn suitable replacements.
There are really only 3 programs that matter:
Total Commander, Firefox and MirandaIM.
I use Total Commander as the main computer management console. 99% of what I do on a computer starts with it.
Firefox. Web browsing, obviously. But also good majority of my public communication.
MirandaIM does all private talk.

Also, these are the only tools that I heavily customised. Ever. And not surprisingly – they are the most tweakable tools in their respectable categories. I spent 100+ hours on Miranda. Significantly more on Firefox. And probably ~1500 on Total Commander.
I think the numbers say it clear, they are important for me.

Moving Firefox turned out to be easy. Copying the config folder to a Linux version mostly worked. I still have some edges to polish, but it’s manageable.
Total Commander works great on Wine. Except for one thing. It can’t launch native programs. Which is 80% of what it was supposed to do.
Miranda is said to be working great with Wine too. Except that it doesn’t launch. Well, I’m not surprised, nobody said that the 36 plugins that I use are compatible with Wine. I leave troubleshooting for later, there are more important things. And I think I can live with Pidgin. Though don’t want to, Miranda gives me many features that are unavailable on it.

So the biggest problem is TC. I have to find a replacement. Actually I know this for several months already and I spent some hours on research.
But also, I don’t want to leave it. I put a really big piece of my heart in it. I went through every single thing that can be customised in the GUI. Then in configuration files. Then started writing extensions. Then started implementing (but never finished) entirely new plugin framework based on instrumenting Total Commander binaries, then integrated hundreds (literally) of external tools to streamline their use. I stopped when I realised that for months I’ve been spending much more time on configuration than on actually using it and that I was optimizing for scenarios that have never happened, but I thought they might happen.
So I stopped extending and just did some maintainance. Why did I put so much time in it? Because I enjoyed productivity that Total Commander enabled. I knew that returns were smaller than the time I invested, but it was so much fun to do whatever I wanted to do so really fast… And talking with people (often programmers like me) about advanced management tasks that were problematic to them and knowing that a couple of keystrokes, 2 clicks and in a second or 5 I can have it done.
I wonder whether I’ll ever be as productive with Unix. I have little hope. I’m thinking sometimes about writing my own file manager. Better than TC (it’s not *that* hard, there’s 1000 things I’d improve). But I don’t think I’ll bite the bullet. After all, there is a reason Total Commander is so good – a great programmer developing it full-time for 18 years. Some work could be saved by using more modern (read: productive) tools. But the cost is still overwhelming. 1500 hours doesn’t look so big now, does it?

P.S.
This post is the first productive work I did on my new Lubuntu.

EDIT: I was tired when I wrote it and got hours calculations wrong, you know, 40*52 was just over 1000. Fixed now.

Blog at WordPress.com.

%d bloggers like this: