Search⌘ K
AI Features

Cleaning a Noisy Sine Wave

Explore how to clean a noisy sine wave by applying a simple filter using Fast Fourier Transform and NumPy in Python. Understand how to isolate frequencies and remove unwanted noise to improve signal clarity.

We'll cover the following...

We won’t cover filtering in detail as it’s a very extensive topic. Instead, we’ll create a simple filter just by using the Fast Fourier Transform (FFT). The goal is to get comfortable with NumPy.

Here is the complete code:

Python 3.8
filtered_freq = []
index = 0
for f in freq:
# Filter between lower and upper limits
# Choosing 950, as closest to 1000. In real world, won't get exact numbers like \these
if index > 950 and index < 1050:
# Has a real value. I'm choosing >1, as many values are like 0.000000001 etc
if f > 1:
filtered_freq.append(f)
else:
filtered_freq.append(0)
else:
filtered_freq.append(0)
index += 1

Now, let’s go over it line by line:

In lines 1–3, we’ll create an empty list called filtered_freq. Remember, freq stores the ...