/
dut_test_reality.py
69 lines (45 loc) · 1.33 KB
/
dut_test_reality.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""Software-Test with a known IR in real-life conditions.
h[k] = dirac[k] + dirac[k-1050]
"""
import sys
sys.path.append('..')
import matplotlib.pyplot as plt
import numpy as np
import generation
import plotting
import calculation
import measurement_chain
import ir_imitation
fs = 44100
fstart = 1
fstop = 22050
pad = 7
# Noise in measurement chain
noise_level_db = -50.
noise = measurement_chain.additive_noise(noise_level_db)
# FIR-Filter-System
dirac_system = measurement_chain.convolution(ir_imitation. diracs([0, 1050]))
# Combinate system elements
system = measurement_chain.chained(dirac_system, noise)
excitation = np.zeros(44100)
excitation[0] = 1
excitation_zeropadded = generation.zero_padding(excitation, pad, fs)
system_response = system(excitation_zeropadded)
h = calculation.deconv_process(excitation,
system_response, fs)[:len(excitation)]
# Plot impulse response
plotting.plot_time(h, title='')
plt.xlim(-1000, fs)
plt.savefig('impulse_response_reality.png')
plt.close()
# Plot frequency response
plotting.plot_freq(h, fs, scale='db', title='')
plt.xscale('log')
plt.savefig('frequency_response_reality.png')
plt.close()
# Plot phase response
plotting.plot_freq(h, fs, mode='phase', title='')
plt.xscale('log')
plt.savefig('phase_response_reality.png')
plt.close()