0
0
SciPydata~30 mins

Why Fourier transforms reveal frequencies in SciPy - See It in Action

Choose your learning style9 modes available
Why Fourier transforms reveal frequencies
📖 Scenario: Imagine you recorded a sound that is a mix of two musical notes played together. You want to find out which notes (frequencies) are in the sound.
🎯 Goal: You will create a simple signal with two frequencies, use Fourier transform to find these frequencies, and then display the result.
📋 What You'll Learn
Create a time array for the signal
Create a signal with two sine waves of different frequencies
Use Fourier transform to find frequency components
Print the frequencies found in the signal
💡 Why This Matters
🌍 Real World
Fourier transforms help us find hidden frequencies in signals like music, sound, or sensor data.
💼 Career
Data scientists use Fourier analysis in fields like audio processing, communications, and vibration analysis.
Progress0 / 4 steps
1
Create a time array for the signal
Create a variable called t that is a numpy array of 500 points evenly spaced from 0 to 1 second.
SciPy
Need a hint?

Use np.linspace(0, 1, 500) to create the time array.

2
Create a signal with two sine waves
Create a variable called signal that is the sum of two sine waves: one with frequency 5 Hz and one with frequency 20 Hz, both using the time array t. Use np.sin() and multiply the frequency by 2 * np.pi * t.
SciPy
Need a hint?

Use np.sin(2 * np.pi * frequency * t) for each sine wave and add them.

3
Apply Fourier transform to find frequencies
Import fft and fftfreq from scipy.fft. Create a variable called fft_values by applying fft to signal. Create a variable called frequencies by applying fftfreq to the length of signal and the sample spacing 1/500.
SciPy
Need a hint?

Use fft(signal) and fftfreq(len(signal), 1/500) to get frequency components.

4
Print the main frequencies found
Print the frequencies where the absolute value of fft_values is greater than 100. Use a for loop with variables freq and value iterating over zip(frequencies, fft_values). Print freq rounded to 1 decimal place.
SciPy
Need a hint?

Check absolute fft values and print frequencies where value is large.