def q5_pre(vector_len): rand_v = lu.random_vector(vector_len) y1 = lu.regular_fft_ifft(rand_v) y2 = lu.conj_fft_ifft(rand_v) if (y1 == y2).all(): return True return False
def q1(plt, vector_len=8): t = numpy.arange(0, vector_len, 1) rand_v = lu.random_vector(vector_len) y1 = lu.conj_dft_idft_with_dftmtx(rand_v) fig, (sub1, sub2) = plt.subplots(2) plt.subplots_adjust(hspace=0.5) fig.suptitle("Comparison between 2 algorithms") sub1.plot(t, numpy.abs(rand_v)) sub1.set_title("original signal") sub2.plot(t, numpy.abs(y1)) sub2.set_title("after conj-dftmtx-conj") plt.savefig("results/comp_2_algo") return True
def q3_and_q4(fs, number_of_points, step_size_array, filter_coeffs_length_array, delay=1): nt = numpy.arange(0, number_of_points / fs, 1 / fs) s = numpy.sin(nt * 2 * numpy.pi * 200) d = s + lu.random_vector(number_of_points) * numpy.sqrt(0.1) x = numpy.pad(d[0:-1], (delay, 0)) for step_size in step_size_array: plot_adaptive_filter_lms(x, d, 16, step_size) for filter_coeffs_length in filter_coeffs_length_array: plot_adaptive_filter_lms(x, d, filter_coeffs_length, 0.01) return
def q5(fs, number_of_points, harmonic_factor_array, step_size=0.01, filter_coeffs_length=16, delay=1): nt = numpy.arange(0, number_of_points / fs, 1 / fs) for harmonic_factor in harmonic_factor_array: s = numpy.sin(nt * 2 * numpy.pi * 200) + numpy.sin( nt * 2 * numpy.pi * 200 * harmonic_factor) d = s + lu.random_vector(number_of_points) * numpy.sqrt(0.1) x = numpy.pad(d[0:-1], (delay, 0)) plot_adaptive_filter_lms(x, d, filter_coeffs_length, step_size, harmonic=200 * harmonic_factor) return
f"fft time:\t{t1}\n" f"cor time:\t{t2}") return if __name__ == "__main__": plt = lu.get_plt() os.makedirs("results", exist_ok=True) # preparation to LAB2 if q1_or_q2_pre(x=[1, 2, 3, 4], h=[4, 3, 2, 1]): print("EQUAL for Q1-PRE") if q1_or_q2_pre([1, 2, 3, 4], [1, 2, 3, 4]): print("EQUAL for Q2-PRE") q3_pre(x=[1, 2, 4], h=[1, 1, 1, 1]) q3_pre(x=[0, 1, -2, 3, -4], h=[0.5, 1, 2, 1, 1, 0.5]) q4_pre(1.5*scipy.signal.boxcar(5), 2*scipy.signal.boxcar(10), scipy.signal.boxcar(15), plt) # LAB2 q1_and_q2(fs=2e5, number_of_points=500, plt=plt) q3(fs=1e5, number_of_points=450, plt=plt) q4(s1=[0, 3, 5, 5, 5, 2, 0.5, 0.25, 0], s2=[1, 1, 1, 1, 1, 0, 0, 0, 0], s3=[0, 9, 15, 15, 15, 6, 1.5, 0.75, 0], s4=[2, 2, 2, 2, 2, 0, 0, 0, 0], plt=plt) q5(s1=lu.random_vector(1000), s2=lu.random_vector(1000)) # Unmark the command blow to show ALL the figures # plt.show()