Search code examples
python-3.xsignal-processingfrequency-analysisfrequency-distributiontime-frequency

Frequency and time-freqeuncy domain features for a sinusoidal signal in Python


I have the following sine wave signal created in Python:

# Import libraries
import numpy as np
import matplotlib.pyplot as plt

Fs  = 1000                                              # Sampling frequency (Hz)
T   = 10                                                # Duration of time signal (s)
N   = T*Fs                                              # Number of data points
f   = 10                                                # Frequency of the sine wave signal (Hz)
t   = np.linspace(0, T, N)                              # Time axis data points
y   = 10 * np.sin(2*np.pi*f*t)                          # Amplitude of the sine wave signal

plt.figure(figsize=(8,8))                               # Figure size of the plot
plt.plot(t,y)                                           # time history plot of the sine wave
plt.xlabel('Time (s)')                                  # X-axis label
plt.ylabel('Amplitude')                                 # Y-axis label
##plt.xlim([0,2.5])                                     # X-axis limits
##plt.ylim([-8,18])                                     # Y-axis limits
plt.get_current_fig_manager().window.state('zoomed')    # Maximize the plot for full screen
plt.show()                                              # Show the plot

Can somebody please help me out in understanding the below points:

  1. What are the various "frequency domain features" that can be extracted from the 10 s sine wave signal Python?

  2. What are the various "time-freqeuncy domain features" that can be extracted from the 10 s sine wave signal in Python?

  3. How do we calculate the wavelet packet energy and wavelet packet entropy for this 10 s sine wave signal in Python?


Solution

  • For your first question, think about the time-domain characteristics of the signal, and what they mean in terms of frequency. In particular, what is the main frequency of the signal; is it infinite or has it been truncated; and what is the nature of the sampling (sampling frequency). These all contribute to the frequency characteristics of the signal.

    In relation to your second question, specgram() from matplotlib provides a time-frequency rendering of the signal. Note that you have a lot of power at one frequency, and also that you have some power leaking into adjacent frequencies.

    enter image description here

    plt.specgram(y, N, Fs)
    plt.xlabel('time')
    plt.ylabel('Frequency')
    plt.ylim(0, 50)