0
0
SciPydata~30 mins

Power spectral density in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Calculate Power Spectral Density using SciPy
📖 Scenario: You have recorded a simple signal from a sensor measuring vibrations. You want to analyze the signal to find out how its power is distributed across different frequencies. This helps in understanding the main frequency components of the signal.
🎯 Goal: Build a Python program that calculates the power spectral density (PSD) of a given signal using SciPy's signal.welch function.
📋 What You'll Learn
Create a signal as a list of numbers representing sensor data.
Set the sampling frequency of the signal.
Use SciPy's signal.welch function to calculate the PSD.
Print the frequency array and the corresponding PSD values.
💡 Why This Matters
🌍 Real World
Power spectral density analysis is used in engineering and science to find dominant frequencies in signals like vibrations, sound, or electrical signals.
💼 Career
Understanding PSD helps in roles like signal processing engineer, data analyst, and research scientist to analyze and interpret sensor data.
Progress0 / 4 steps
1
Create the signal data
Create a list called signal_data with these exact values: 0, 1, 0, -1, 0, 1, 0, -1 representing the sensor measurements.
SciPy
Need a hint?

Use square brackets to create a list and separate values with commas.

2
Set the sampling frequency
Create a variable called sampling_freq and set it to 4, representing 4 samples per second.
SciPy
Need a hint?

Assign the number 4 to the variable sampling_freq.

3
Calculate the power spectral density
Import signal from scipy. Then use signal.welch with signal_data and sampling_freq to calculate the frequency array freqs and power spectral density array psd.
SciPy
Need a hint?

Use from scipy import signal to import. Then call signal.welch(signal_data, fs=sampling_freq) and unpack the result into freqs and psd.

4
Print the frequency and PSD arrays
Print the variables freqs and psd on separate lines to display the frequency values and their corresponding power spectral density values.
SciPy
Need a hint?

Use two print statements: one for freqs and one for psd.