<jupyter_start><jupyter_text>Homework – Spectral Analysis  IEOR 135/290, Data-X: Applied Data VenturesAuthor: <NAME> (in collaboration with I<NAME>)UC Berkeley, B.S. EECS'21Email: <EMAIL>  ObjectiveIn this homework, we will explore using spectral analysis to understand how you can generate features that you can use to build classification and predictive models for timeseries data.   Setting Up Imports and Dataset<jupyter_code>import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import librosa

%matplotlib inline

sns.set(rc={'figure.figsize':(14,6)})
samples, sampling_rate = librosa.load("audio.wav", sr=None, mono=True, offset=0.0, duration=None)

len(samples), sampling_rate<jupyter_output><empty_output><jupyter_text>Your Audio File<jupyter_code>plt.plot(np.linspace(start=0, stop=len(samples)/sampling_rate, num=len(samples)), samples)
plt.xlabel("Duration (s)")
plt.ylabel("Normalized Aplitude")<jupyter_output><empty_output><jupyter_text>Question 1Compute the fourier transformation of the HSN1F Value in the dataset, and store it in fft_hsn1f.<jupyter_code>freq = np.fft.fftfreq(len(samples), 1/sampling_rate)
fft_x = np.fft.fft(samples)
fft_x[:10]<jupyter_output><empty_output><jupyter_text>-------------------As expected, you notice a real and an imaginary component in the above array. The plot below shows fft_hsn1f plotted vs samples **Plot:** Fourier Transformation of Audio File vs. Sample Count<jupyter_code>plt.plot(abs(fft_x))
plt.xlabel("Sample Count")<jupyter_output><empty_output><jupyter_text>Question 2What do you notice about this signal?<jupyter_code># Use this space to manipulate the signal for your analysis<jupyter_output><empty_output><jupyter_text>*Your answer here*  Question 3 **Question 3a: Shifting**Use the Swap Half Spaces technique to process the FFT signal. Generate plots and discuss your conclusions.<jupyter_code># Write your code here

# fft_x_shifted = np.fft.fftshift(fft_x)
# freq_shifted = np.fft.fftshift(freq)
# Write your code here to generate plots

# plt.plot(freq_shifted, np.abs(fft_x_shifted))
# plt.xlabel("Frequency (Hz)")<jupyter_output><empty_output><jupyter_text>*Discuss your conclusions here* **Question 3b: Folding**Use the Fold Negative Frequencies technique to process the FFT Signal<jupyter_code># Write your code here

# half_n = int(np.ceil(len(samples)/2.0))
# fft_x_half = (2.0 / len(samples)) * fft_x[:half_n]
# freq_half = freq[:half_n]
# Write your code here to generate plots


# plt.plot(freq_half, np.abs(fft_x_half))
# plt.xlabel("Frequency (Hz)")
# plt.ylabel("Amplitude")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11386138613861387, 'fraction_numerical': 0.011043412033511044, 'mean_word_length': 6.703812316715543, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '432339', 'license': 'Apache-2.0', 'n_tokens_mistral': 933, 'n_tokens_neox': 900, 'n_words': 243, 'path': '02-data-x-signals/m250-theory-signal-spectral-lti-ffts/soln-hw_spectral_analysis.ipynb', 'repo_name': 'UCBerkeley-SCET/DataX-Berkeley', 'size': '2670'}