<commit_before># Determine the Sampling Rate (file samples are 300ms speech)
#   Note: there are 2400 samples.

s = []

with open("lab.dat") as labdat:
    for line in labdat.readlines():
        if line != "\n": s.append(line.rstrip())

sampling_rate = len(s)/0.3 # 0.3s...


# Apply the ideal delay operator with delay 5ms, 10ms, and 15ms
y = [[], [], []]  # For the ideal delay operators at 5, 10 and 15.

def ideal_delay_by_5ms(input_signal):
    output_signal = []
    # ideal delay y[n] = s[n-n0]
    n0 = len(input_signal) / (5 * samp_rate)
    for n in range(0, len(input_signal)):
        if n < n0:
            output_signal.append(0)
        else:
            output_signal.append(input_signal(n-n0))
    return output_signal


# Apply the moving average with k1=k2=5, 10, and 15ms

# Convolve the signal with a window of length 10ms

# Extract the shirt0term energy signal from the signal in labrotory.dat

# Plot the orginal signal, the energy signal, the magnitude signal and the .ZCR signal as a function of time
<commit_msg>Some work on the moving average function<commit_after>from numpy import mean

# Determine the Sampling Rate (file samples are 300ms speech)
#   Note: there are 2400 samples.

s = []

with open("lab.dat") as labdat:
    for line in labdat.readlines():
        if line != "\n": s.append(line.rstrip())

sampling_rate = len(s)/0.3 # 0.3s...


# Apply the ideal delay operator with delay 5ms, 10ms, and 15ms
y = [[], [], []]  # For the ideal delay operators at 5, 10 and 15.

def ideal_delay_by_5ms(input_signal):
    output_signal = []
    # ideal delay y[n] = s[n-n0]
    n0 = len(input_signal) / (5 * samp_rate)
    for n in range(0, len(input_signal)):
        if n < n0:
            output_signal.append(0)
        else:
            output_signal.append(input_signal(n-n0))
    return output_signal


y[0] = ideal_delay_by_5ms(s)     # 5ms
y[1] = ideal_delay_by_5ms(y[0])  # 10ms
y[2] = ideal_delay_by_5ms(y[1])  # 15ms

# Apply the moving average with k1=k2=5, 10, and 15ms
# Three cases to be aware of, as labelled in the code:
#   - 1: Moving average is clipped as there's too few measurements to go backward at the beginning of the signal
#   - 2: Ordinary moving average function
#   - 3: Moving average is clipped as there's too few measurements to go forward at the end of the signal
def moving_average(k1, k2, input_signal):
    output_signal = []
    #coefficient = 1/(k1 + k2 + 1)  # Shouldn't need this as numpy calculating for us
    for i in range(0, k1):
        output_signal[i] = mean(input_signal[0, i])
    for i in range(k1, len(input_signal) - k2):
        output_signal[i] = mean(input_signal[i-k1, i+k2])
    for i in range(len(input_signal) - k2, k2):
        output_signal[i] = mean(input_signal[i-k2, len(input_signal)])
    
    return output_signal
    


# Convolve the signal with a window of length 10ms

# Extract the short-term energy signal from the signal in labrotory.dat

# Plot the orginal signal, the energy signal, the magnitude signal and the .ZCR signal as a function of time

{'fraction_non_alphanumeric': 0.10562459123610203, 'fraction_numerical': 0.03564421190320471, 'mean_word_length': 3.167574931880109, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '2246821', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1024, 'n_words': 365}