Challenge - 5 Problems
Pitch Detection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediateOutput of autocorrelation pitch detection snippet
Given the following Python code snippet that computes the autocorrelation of a signal segment to detect pitch, what is the output array?
Signal Processing
import numpy as np signal = np.array([0, 1, 0, -1, 0, 1, 0, -1]) autocorr = np.correlate(signal, signal, mode='full') result = autocorr[autocorr.size // 2:] print(result)
Attempts:
2 left
๐ก Hint
Recall that autocorrelation at lag 0 is the sum of squares of the signal values.
โ Incorrect
The autocorrelation of the signal at lag 0 is 4 (sum of squares). The subsequent values are computed by shifting the signal and summing the product of overlapping elements. Option B matches the correct autocorrelation values.
โ data_output
intermediateNumber of detected pitch periods in a signal
A pitch detection algorithm segments a 1-second audio sampled at 8000 Hz into frames of 80 samples each. If the algorithm detects a pitch period every frame, how many pitch periods are detected in total?
Attempts:
2 left
๐ก Hint
Divide total samples by frame size to find number of frames.
โ Incorrect
Total samples = 8000. Frame size = 80 samples. Number of frames = 8000 / 80 = 100. Each frame detects one pitch period, so total is 100.
โ visualization
advancedIdentify correct pitch contour plot
Which plot correctly shows a pitch contour that rises linearly from 100 Hz to 200 Hz over 1 second?
Signal Processing
import matplotlib.pyplot as plt import numpy as np time = np.linspace(0, 1, 100) contour_A = 100 + 100 * time contour_B = 200 - 100 * time contour_C = 100 * np.sin(2 * np.pi * time) + 150 contour_D = np.full_like(time, 150) plt.figure(figsize=(8, 4)) plt.plot(time, contour_A, label='A') plt.plot(time, contour_B, label='B') plt.plot(time, contour_C, label='C') plt.plot(time, contour_D, label='D') plt.legend() plt.xlabel('Time (s)') plt.ylabel('Frequency (Hz)') plt.title('Pitch Contours') plt.show()
Attempts:
2 left
๐ก Hint
Look for a straight line increasing from 100 to 200 Hz.
โ Incorrect
Plot A shows a linear increase from 100 Hz to 200 Hz over 1 second, matching the description of the pitch contour.
๐ง Conceptual
advancedEffect of window size on pitch detection accuracy
How does increasing the window size in a pitch detection algorithm typically affect the accuracy and time resolution of pitch estimation?
Attempts:
2 left
๐ก Hint
Think about the trade-off between frequency precision and temporal precision.
โ Incorrect
A larger window size captures more data, improving frequency resolution (accuracy) but reduces the ability to detect quick changes in pitch (time resolution).
๐ง Debug
expertIdentify error in pitch detection code snippet
What error will the following Python code raise when trying to detect pitch using zero crossing rate?
Signal Processing
import numpy as np signal = np.array([1, -1, 1, -1, 1]) zero_crossings = np.where(np.diff(np.sign(signal)))[0] pitch_period = 1 / zero_crossings print(pitch_period)
Attempts:
2 left
๐ก Hint
Check what happens if zero_crossings contains zero values.
โ Incorrect
The zero_crossings array contains indices starting at 0, so dividing 1 by zero_crossings causes a divide by zero warning and results in inf values.
