0
0
SciPydata~30 mins

FFT-based filtering in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
FFT-based filtering
📖 Scenario: Imagine you have a noisy signal from a sensor measuring temperature over time. You want to remove the high-frequency noise to see the smooth trend clearly.
🎯 Goal: You will create a simple signal, set a frequency threshold, apply FFT-based filtering to remove noise, and then display the filtered signal.
📋 What You'll Learn
Create a time series signal with noise using numpy arrays
Set a frequency threshold to separate noise from the main signal
Use FFT to transform the signal to frequency domain
Filter out frequencies above the threshold
Use inverse FFT to get the filtered signal back
Print the filtered signal array
💡 Why This Matters
🌍 Real World
FFT-based filtering is used in many fields like audio processing, sensor data cleaning, and image processing to remove unwanted noise and improve signal quality.
💼 Career
Understanding FFT and filtering is important for data scientists and engineers working with time series data, signal processing, and any application where noise reduction is needed.
Progress0 / 4 steps
1
Create a noisy signal
Create a numpy array called time with 100 points from 0 to 1 using np.linspace(0, 1, 100). Then create a numpy array called signal that is sin(2 * pi * 5 * time) plus random noise using np.random.normal(0, 0.5, 100).
SciPy
Need a hint?

Use np.linspace to create time. Use np.sin and np.random.normal to create signal.

2
Set frequency threshold
Create a variable called freq_threshold and set it to 10. This will be the cutoff frequency to keep in the signal.
SciPy
Need a hint?

Just create a variable freq_threshold and assign it the value 10.

3
Apply FFT and filter frequencies
Use np.fft.fft(signal) to get the FFT of signal and store it in fft_signal. Use np.fft.fftfreq(len(signal), d=1/100) to get the frequency bins and store in freqs. Then set all values in fft_signal to zero where the absolute value of freqs is greater than freq_threshold.
SciPy
Need a hint?

Use np.fft.fft and np.fft.fftfreq. Then zero out frequencies above the threshold.

4
Get filtered signal and print
Use np.fft.ifft(fft_signal) to get the filtered signal and store it in filtered_signal. Then print filtered_signal.real to show the real part of the filtered signal.
SciPy
Need a hint?

Use np.fft.ifft and print the real part of the result.