This commit is contained in:
Miloslav Ciz 2022-04-14 14:56:35 +02:00
parent 2dda017fde
commit 6ac4fd0c6c
4 changed files with 62 additions and 0 deletions

47
aliasing.md Normal file
View file

@ -0,0 +1,47 @@
# Aliasing
Aliasing is a certain mostly undesirable phenomenon that distorts signals (such as sounds or images) when they are [sampled](sampling.md) [discretely](discrete.md) (captured at periodic intervals) -- this can happen e.g. when capturing sound with digital recorders or when [rendering](rendering.md) computer graphics. There exist [antialiasing](antialiasing.md) methods for suppressing or even eliminating aliasing. Aliasing can be often seen on small checkerboard patterns as a moiré pattern (spatial aliasing), or maybe more famously on rotating wheels or helicopter rotor blades that in a video look like standing still or rotating the other way (temporal aliasing, caused by capturing images at intervals given by the camera's [FPS](fps.md)).
The following diagram shows the principle of aliasing:
```
^ original sampling period
| | | |<------------->|
| | _ | _ | _ |
| .'|'. .' '| .' '. | .' '. |
|/__|__\_______/____|\_______/_____\|______/_____\__|___
| | \ / | \ / \ / \ |
| | '._.' | '._.' |'._.' '|_.'
| | | | |
| : : : :
V : : : :
: : : :
^ : : : :
| : : : :
|---o---...____ : : :
| | '''''o...____ : :
|___|_______________|______ ''''----o_______________:___
| '''----___ |
| ''''O---
| reconstructed
|
V
```
The top signal is a [sine](sin.md) function of a certain [frequency](frequency.md). We are sampling this signal at periodic intervals indicated by the vertical lines (this is how e.g. digital sound recorders record sounds from the real world). Below we see that the samples we've taken make it seem as if the original signal was a sine wave of a much lower frequency. It is in fact impossible to tell from the recorded samples what the original signal looked like.
Let's note that signals can also be two and more dimensional, e.g. images can be viewed as 2D signals. These are of course affected by aliasing as well.
The explanation above shows why a helicopter's rotating blades look to stand still in a video whose [FPS](fps.md) is synchronized with the rotation -- at any moment the camera captures a frame (i.e. takes a sample), the blades are in the same position as before, hence they appear to not be moving in the video.
Of course this doesn't only happen with perfect sine waves. [Fourier transform](fourier_transform.md) shows that any signal can be represented as a sum of different sine waves, so aliasing can appear anywhere.
**NyquistShannon sampling theorem** says that aliasing can NOT appear if we sample with at least twice as high frequency as that of the highest frequency in the sampled signal. This means that we can eliminate aliasing by using a [low pass filter](low_pass.md) before sampling which will eliminate any frequencies higher than the half of our sampling frequency. This is why audio is normally sampled with the rate of 44100 Hz -- from such samples it is possible to correctly reconstruct frequencies up to about 22000 Hz which is about the upper limit of human hearing.
Aliasing is also a common problem in [computer graphics](computer_graphics.md). For example when rendering textured 3D models, aliasing can appear in the texture if that texture is rendered at a smaller size than its resolution (when the texture is enlarged by rendering, aliasing can't appear because enlargement decreases the frequency of the sampled signal and the sampling theorem won't allow it to happen). (Actually if we don't address aliasing somehow, having lower resolution textures can unironically have beneficial effects on the quality of graphics.) This happens because texture samples are normally taken at single points that are computed by the texturing algorithm. Imagine that the texture consists of high-frequency details such as small checkerboard patterns of black and white pixels; it may happen that when the texture is rendered at lower resolution, the texturing algorithm chooses to render only the black pixels. Then when the model moves a little bit it may happen the algorithm will only choose the white pixels to render. This will result in the model blinking and alternating between being completely black and completely white (while it should rather be rendered as gray).
The same thing may happen in [ray tracing](ray_tracing.md) if we shoot a single sampling ray for each screen pixel. Note that [interpolation/filtering](interpolation.md) of textures won't fix texture aliasing. What can be used to reduce texture aliasing are e.g. by [mipmaps](mip.md) which store the texture along with its lower resolution versions -- during rendering a lower resolution of the texture is chosen if the texture is rendered as a smaller size, so that the sampling theorem is satisfied. However this is still not a silver bullet because the texture may e.g. be shrink in one direction but enlarged in other dimension (this is addressed by [anisotropic filtering](anisotropic_filtering.md)). However even if we sufficiently suppress aliasing in textures, aliasing can still appear in geometry. This can be reduced by [multisampling](multisampling.md), e.g. sending multiple rays for each pixel and then averaging their results -- by this we **increase our sampling frequency** and lower the probability of aliasing.
**Why doesn't aliasing happen in our eyes and ears?** Because our senses don't sample the world discretely, i.e. in single points -- our senses [integrate](integration.md). E.g. a rod or a cone in our eyes doesn't just see exactly one point in the world, it sees an averaged light over a small area, and it also doesn't sample the world at specific moments like cameras do, its excitation by light falls off gradually which averages the light over time, preventing temporal aliasing.
So all in all, **how to prevent aliasing?** As said above, we always try to satisfy the sampling theorem, i.e. make our sampling frequency at least twice as high as the highest frequency in the signal we're sampling, or at least get close to this situation and lower the probability of aliasing. This can be done by either increasing sampling frequency (which can be done smart, some methods try to detect where sampling should be denser), or by preprocessing the input signal with a low pass filter or otherwise ensure there won't be too high frequencies.

View file

@ -21,6 +21,17 @@
[] [][][][][]
SAF FTW
^
|
| _.--._ _.--._
| .' '. .' '.
|/__________\____________/__________\______
| \ / \
| '. .' '.
| `'--'` `'-
|
V
```
## See Also

View file

@ -7,3 +7,5 @@ TODO
- There was a guy who made a whole game (named *DRAGON: A Game About a Dragon*), some 30000+ lines of code, without knowing about the concept of loops. He only ever used the if statement. (This was posted on reddit along with a portion of the code.)
- The MMORPG *New World* by *Amazon Games* was programmed by retards (probably some diversity team) who made the client authoritative which allowed for fun such as becoming invincible by draggine the game window or duplicate currency with lag switches.
- In 2016 there was a progaming team in Halo called Mi Seng which in a broadcast game did a pretty funny thing: when they were leading they went into hiding in buggy spots and then just did nothing until the time ran out. Normies were crying, the commentators were pretty awkward, they considered this "unethical" xD We consider it pretty cool.
- In 2016 [Micro$oft](microsoft.md) released a Twitter [AI](ai.md) bot called Tay which was made to teach itself how to talk from the text on the Internet. It quickly became extremely racist and enraged waves of [SJW](sjw.md)s so they had to shut it down.
- There are many funny stories from [4chan](4chan.md). In 2012 they made masses of Justin Bieber fans shave their heads by spreading fake news that Bieber had cancer under the hashtag #BaldForBieber. In 2013 they made a similarly funny prank by making Justin Bieber fans cut themselves with another faked campaign #CuttingForBieber. In 2013 they made a huge number of Appletoddlers destroy their [iPhones](iphone.md) with fake ads that promoted a new "feature" that makes the phone waterproof via a software update. Similarly in 2014 they spread fake ads about a new iPhone "feature" that would let users charge their phones in a microwave. 4chan also hijacked many internet polls such as the Mountain Dew's poll for naming their new drink in 2012: people from 4chan raided the poll and chose the name "Hitler Did Nothing Wrong", with names such as "Diabeetus" or "Soda" as followers. Another raided poll was that of Talor Swift about at which school she should perform -- 4chan mass voted for a school for deaf children which eventually won (Taylor Switch handled it by donating money to the school). 4chan also chose North Korea as a country for Justin Bieber's tour. Another hilarious story is from 2006 when 4chan raided the Habbo Hotel (a MMO game mostly for children); they made shitton of black characters with afros, went around blocking players from accessing game areas, grouping to form swastikas and famously blocking a hotel pool with the sign "Pool's closed due to AIDS".

View file

@ -4,6 +4,8 @@ This is a Wiki for [less retarded software](lrs.md) (LRS) and related topics.
This wiki is **NOT** a satire.
**We love all living beings. Even you.**
**Before contributing please read the [rules & style](wiki_style.md)!** {But contributions aren't really accepted RN :) ~drummyfish }
We have a **[C tutorial](c_tutorial.md)**!