# November 05, 2017

## Impulse Noise Filtering - Median Filter Demo

### Math Demonstration, Impulse Noise Filtering

In this demonstration there are three sliders. From left to right they are: signal noise, spike density, and filter window length. The signal noise is just basic white noise added to the signal. The spike density is the percentage of impulse noise added to the signal. And the filter window is how many samples are used by the median filter.

Shown in red is the raw signal, complete with spikes. In blue is the median filtered signal. The goal is to have the blue signal from a smooth trace with no spikes, and the default settings should produce this. Increasing the spike density will require a larger filter window.

Just as with an average filter, the median filter will induce phase shift as well as attenuate the signal. The larger the filter window the larger the phase shift and the more attenuation. Unique to the median filter is the creation of plateaus around signal peaks. This is because of the phase shift and the changing direction of the signal lags during peak values.

# July 05, 2017

## N-Queens Demonstration

### Math Demonstration, Programming, 8 queens puzzle

In implementing the 8 queens puzzle I decided to crate a Javascript interface that allows one to try and place queens on the chessboard of arbitrary size.

By clicking on a cell a queen is placed or removed. Highlighted cells show the threats created by placing a queen at that location. Yellow cells show that the highlighted area poses a threat. Red cells show the board is in conflict. A fully green board shows a solution.

One can generally find solutions to the smaller boards pretty quickly. The larger boards get very complected but also have more possible solutions. The solve button will use the method of permutations to try and find a random solution. For the larger boards it may not find a solution and will time out after 30 seconds. However, trying again will eventually produce a result and sometimes quite fast. It really depends on how the board was shuffled.  The total number of solutions to test for any board is n! where n is the number of rows/columns.

Rows/Columns Total Permutations
4 24
5 120
6 720
7 5,040
8 40,320
9 362,880
10 3,628,800
11 39,916,800
12 479,001,600
13 6,227,020,800
14 87,178,291,200
15 1,307,674,368,000
16 20,922,789,888,000
17 355,687,428,096,000
18 6,402,373,705,728,000
19 121,645,100,408,832,000
20 2,432,902,008,176,640,000

That last number is 2.4 quintillion. For comparison a computer counting at 4 billion counts/second (4 GHz) would take 19 years just to count that high.

Download a zip file of the project: nQueens_v1.0.zip. SHA256: a0de13bc06dd9a2cb8cde3b535939825946b07e8f8164b51fb6f2af89f0c7f11.

# December 24, 2012

## Gibbs Phenomenon - Part 2

### Math, Math Demonstration, Math Demonstration

I have expanded on the Gibbs Phenomenon demo I wrote about the other day. In addition to the plot of the series output, I have added the output of a Fast Fourier Transform (FFT). The top graph is the signal. The bottom graph shows the first 150 values of the FFT output, interlacing the real and imaginary values. Arranged in this manner, the graph is the spectrum of the signal. Each column on the lower represents an increment of 1 Hz, so the full graph spans 0 and 150 Hz. The height of each bar is the amplitude of the sine wave at this frequency. The default graph is setup to create a square wave out of 10 sines waves. The first column is at 5 Hz with an amplitude of 0.6 * 4 / π. The 4 / π is the scale factor used in the series equation, and the 0.6 is the default amplitude. The next spike is at 15 Hz, and 1/3 the amplitude of the first; and the third is at 25 Hz and 1/5 the amplitude of the first. There are 10 bars in the FFT graph all together because the default number of sine waves to add together is 10.

The demo can switch between the appropriated square wave, and a true square wave. When the switch is made, note that the FFT graph only has bars adds additional graph, but the amplitude and position of the existing bars does not change. What this shows is that the series output and a square wave really do share the relation to one an other.

The idea behind a Fourier transform is to describe a function as a series of sine waves at different frequencies and amplitudes added together. A Fast Fourier Transform is a method to calculate the coefficients of for the amplitudes for equally spaced frequencies on a set of samples. Since the Gibbs Phenomenon is a series of sine waves added together, an FFT of this signal has a very predictable output.

While adjusting the values of the demo you will notice some interesting things. Frequencies between integer number produce bars on the FFT between that sweep over a range. This is because the output only has equally spaces sine waves every 1 Hz, so partial frequencies must consist the frequencies available. You may also notice small bars next to primary bars. This is caused by the accumulated in the FFT calculations—floating-point numbers only have to much precision.

Notice that the phase has no effect on the FFT output, which is expected.

So the amplitude may be a little confusing. To understand it we need to look at the series equation. The scale factor is 4 / π. This will result in the steady-state of the square wave resting at amplitude. For example, the default settings of the demo have an amplitude of 0.6, and a look at the graph revels the ringing signal hovers right around 0.6. To get a known amplitude on the FFT, simple scale the desired amplitude by 4 / π. For example, setting the amplitude to 0.785 will result in the first FFT bar at 1.0 for amplitude. Setting the series sum to 1 will produce a sine wave with peaks at -1 and 1.

Feel free to experiment, and post if you find something interesting.

# December 24, 2012

## Gibbs Phenomenon - Part 2

### Math, Math Demonstration, Math Demonstration

I have expanded on the Gibbs Phenomenon demo I wrote about the other day. In addition to the plot of the series output, I have added the output of a Fast Fourier Transform (FFT). The top graph is the signal. The bottom graph shows the first 150 values of the FFT output, interlacing the real and imaginary values. Arranged in this manner, the graph is the spectrum of the signal. Each column on the lower represents an increment of 1 Hz, so the full graph spans 0 and 150 Hz. The height of each bar is the amplitude of the sine wave at this frequency. The default graph is setup to create a square wave out of 10 sines waves. The first column is at 5 Hz with an amplitude of 0.6 * 4 / π. The 4 / π is the scale factor used in the series equation, and the 0.6 is the default amplitude. The next spike is at 15 Hz, and 1/3 the amplitude of the first; and the third is at 25 Hz and 1/5 the amplitude of the first. There are 10 bars in the FFT graph all together because the default number of sine waves to add together is 10.

The demo can switch between the appropriated square wave, and a true square wave. When the switch is made, note that the FFT graph only has bars adds additional graph, but the amplitude and position of the existing bars does not change. What this shows is that the series output and a square wave really do share the relation to one an other.

The idea behind a Fourier transform is to describe a function as a series of sine waves at different frequencies and amplitudes added together. A Fast Fourier Transform is a method to calculate the coefficients of for the amplitudes for equally spaced frequencies on a set of samples. Since the Gibbs Phenomenon is a series of sine waves added together, an FFT of this signal has a very predictable output.

While adjusting the values of the demo you will notice some interesting things. Frequencies between integer number produce bars on the FFT between that sweep over a range. This is because the output only has equally spaces sine waves every 1 Hz, so partial frequencies must consist the frequencies available. You may also notice small bars next to primary bars. This is caused by the accumulated in the FFT calculations—floating-point numbers only have to much precision.

Notice that the phase has no effect on the FFT output, which is expected.

So the amplitude may be a little confusing. To understand it we need to look at the series equation. The scale factor is 4 / π. This will result in the steady-state of the square wave resting at amplitude. For example, the default settings of the demo have an amplitude of 0.6, and a look at the graph revels the ringing signal hovers right around 0.6. To get a known amplitude on the FFT, simple scale the desired amplitude by 4 / π. For example, setting the amplitude to 0.785 will result in the first FFT bar at 1.0 for amplitude. Setting the series sum to 1 will produce a sine wave with peaks at -1 and 1.

Feel free to experiment, and post if you find something interesting.