<jupyter_start><jupyter_text>DFT<jupyter_code>def dft(x):
    return get_transform_matrix(x.shape[0]) @ x
testVector = np.array([2,4,5,6])
dft(testVector)
np.fft.fft(testVector)<jupyter_output><empty_output><jupyter_text>IDFT<jupyter_code>def idft(y):
    return np.conj(dft(np.conj(y))) / y.shape[0]
idft(dft(testVector))
np.fft.ifft(np.fft.fft(testVector))<jupyter_output><empty_output><jupyter_text>FFT<jupyter_code>def get_d_vector(n):
    ksi = complex(math.cos(2*math.pi / n), - math.sin(2 * math.pi / n))
    return np.array([ksi ** i for i in range(n//2)], dtype=complex)
def fft(x):
    n = x.shape[0]

    if n == 2:
        return dft(x)

    else:
        even = x[::2]
        odd = x[1::2]
        d = get_d_vector(n)

        fftEven = fft(even)
        fftOdd = fft(odd)
        return np.append(fftEven + (d * fftOdd), fftEven - (d * fftOdd))
fft(testVector)
idft(fft(testVector))<jupyter_output><empty_output><jupyter_text>Badanie sygnałów<jupyter_code>def complex_sin_signal(signal_data):
    """signal data is a list of (freq, amp, shift)"""
    return lambda x: sum([i[1] * math.sin(i[0] * x + i[2]) for i in signal_data])
# signal_data = [(10,4,2), (4,5,2), (5,2,3), (1,21,32), (20,2,15)]
signal_data = [(5,1,0), (50,1,0), (100,1,0)]
complex_sample_signal = complex_sin_signal(signal_data)
testSignal = np.array(list(map(complex_sample_signal, np.linspace(0, 8 * math.pi, 2048))))
plt.plot(testSignal)
plt.show()
plt.plot(np.real(fft(testSignal)))
plt.show()
plt.plot(np.imag(fft(testSignal)))
plt.show()
def period_sin_signal(signal_data, signal_range):
    """signal data is a list of (freq, amp, shift), signal_range is a tuple containing:
    (start, stop, signal_num)"""
    breaks = np.linspace(*signal_range, len(signal_data) + 1)[1:]
    def signal(x):
        for i, signal_break in enumerate(breaks):
            if x < signal_break:
                return signal_data[i][1] * math.sin(signal_data[i][0] * x + signal_data[i][2])
        return signal_data[-1][1] * math.sin(signal_data[-1][0] * x + signal_data[-1][2])
        
    return signal
period_sample_signal = period_sin_signal(signal_data, [0,20])
periodtestSignal = np.array(list(map(period_sample_signal, np.linspace(0, 8 * math.pi, 2048))))
plt.plot(periodtestSignal)
plt.show()
plt.plot(np.real(fft(periodtestSignal)))
plt.show()
plt.plot(np.imag(fft(periodtestSignal)))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1749065226422933, 'fraction_numerical': 0.03115911923556294, 'mean_word_length': 4.613053613053613, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '79008', 'license': 'MIT', 'n_tokens_mistral': 1023, 'n_tokens_neox': 981, 'n_words': 166, 'path': 'Lab10/Lab10.ipynb', 'repo_name': 'maxiwoj/MownitLab', 'size': '2407'}