Skip to content

Latest commit

 

History

History
83 lines (49 loc) · 3.07 KB

File metadata and controls

83 lines (49 loc) · 3.07 KB

Hamming window for signal processing

Hamming window algorithm for the Arduino environment or any microcontroller. Specially usefull in signal processing.

Summary

// Include the hamming header
#include "hamming.h"

/*Invoke an instance of the Hamming class. The only requirement is to declare the size of the window in which the signal is*/
#define WINDOW_SIZE 1000

Hamming hamming_window(WINDOW_SIZE);

/*Just to test it I'll be using a heavyside function. Here you can use whatever function you want*/
float heavyside_function[WINDOW_SIZE];

/*Then simply apply the window to the signal. Beware that all changes will be applied to the same array that you put as argument.*/
hamming_window.applyWindow(heavyside_function);

Window Function:

Windows are mathematical functions frequently used in analysis and signal processing to avoid discontinuities at the beginning and end of analyzed blocks.

In signal processing, a window is used when the analysis focuses on a signal of voluntarily limited length. Indeed, a real signal has to be finite time; furthermore, a calculation is only possible from a finite number of points. To observe a signal in finite time, it is multiplied by a window function.

Hamming Function:

What is Hamming window used for?

Computers can't do computations with an infinite number of data points, so all signals are "cut off" at either end. This causes the ripple on either side of the peak that you see. The hamming window reduces this ripple, giving you a more accurate idea of the original signal's frequency spectrum

Equation

equals1

How to use:

Copy the following files in your proyect directory:

  • hamming.h
  • hamming.cpp

In your code invoke a instance of the Hamming class. The only argument that is needed is the amount of samples in the windows where the signal in question is.

If your window has 1000 samples, the code we'll be:

#define WINDOW_SIZE 1000

Hamming hamming_window(WINDOW_SIZE);

To test it, we'll be applying the Hamming window to the positive part of a heavyside function:

heavyside

In the code is represented like:

float heavyside_function[WINDOW_SIZE];

for (int i = 0; i < WINDOW_SIZE; i++)
  heavyside_function[i] = 1;

Then we apply the Hamming window to the signal:

hamming_window.applyWindow(heavyside_function);

Beware that all changes will be applied to the same array that you put as argument. Feel free to change this at will.

And then graph the response:

Hamming signal

To finish, we can compare the response done by the microcontroller to what you can get with a python algorithm:

descarga (1)