mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 12:20:58 +01:00
Compare commits
4 Commits
f4442a05f5
...
2c48f12d0e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c48f12d0e | ||
|
|
52aadfcd53 | ||
|
|
705a63e161 | ||
|
|
39ceb8eedc |
2
.idea/A.K.03.iml
generated
2
.idea/A.K.03.iml
generated
@ -4,7 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (A.K.03)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.13 (A.K.03)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
||||
BIN
files/Student Recordings/audio_beacon_67676767_at_center.wav
Executable file
BIN
files/Student Recordings/audio_beacon_67676767_at_center.wav
Executable file
Binary file not shown.
BIN
files/Student Recordings/audio_beacon_67676767_at_x220_y415.wav
Executable file
BIN
files/Student Recordings/audio_beacon_67676767_at_x220_y415.wav
Executable file
Binary file not shown.
BIN
files/Student Recordings/audio_beacon_67676767_at_x28_y417.wav
Executable file
BIN
files/Student Recordings/audio_beacon_67676767_at_x28_y417.wav
Executable file
Binary file not shown.
BIN
files/Student Recordings/audio_beacon_67676767_at_x42_y225.wav
Executable file
BIN
files/Student Recordings/audio_beacon_67676767_at_x42_y225.wav
Executable file
Binary file not shown.
BIN
files/Student Recordings/audio_beacon_67676767_driving_03_12_2025.wav
Executable file
BIN
files/Student Recordings/audio_beacon_67676767_driving_03_12_2025.wav
Executable file
Binary file not shown.
@ -3,7 +3,7 @@ import matplotlib.pyplot as plt # For plotting for tests
|
||||
|
||||
from scipy.io import wavfile # For reading .wav files for testing
|
||||
from scipy.signal import find_peaks # For cropping the microphone recordings
|
||||
from scipy.fft import fft, ifft # For channel estimation
|
||||
from scipy.fft import fft, ifft, fftshift # For channel estimation
|
||||
from scipy.optimize import least_squares # For estimating KITT's location
|
||||
|
||||
def recording_crop_normalize(recordings, ref_mic):
|
||||
@ -13,8 +13,8 @@ def recording_crop_normalize(recordings, ref_mic):
|
||||
ref_peak = ref_peaks[-1]
|
||||
|
||||
# Cropping all recordings to show only the peaks around the reference peak
|
||||
start = ref_peak - 1500
|
||||
end = ref_peak + 1500
|
||||
start = ref_peak - 3600
|
||||
end = ref_peak + 3600
|
||||
recordings = recordings[start:end]
|
||||
|
||||
# Normalizing all recordings after they are cropped
|
||||
@ -28,15 +28,15 @@ def recording_crop_normalize(recordings, ref_mic):
|
||||
def channel_estimation(recording, reference_recording, epsilon):
|
||||
# Finding both the recording and the reference recording in the frequency domain
|
||||
padded_length = max(len(recording), len(reference_recording))
|
||||
rec_freq = fft(recording, padded_length-len(recording))
|
||||
ref_rec_freq = fft(reference_recording, padded_length-len(reference_recording))
|
||||
rec_freq = fft(recording, padded_length)
|
||||
ref_rec_freq = fft(reference_recording, padded_length)
|
||||
|
||||
# Performing the deconvolution in the frequency domain
|
||||
ch_est_freq = (ref_rec_freq*np.conj(rec_freq))/(np.abs(rec_freq)**2+epsilon)
|
||||
|
||||
# Finding the channel estimation in the time domain and centre it
|
||||
channel_estimate = np.real(ifft(ch_est_freq))
|
||||
channel_estimate = np.fft.fftshift(channel_estimate)
|
||||
channel_estimate = abs(ifft(ch_est_freq))
|
||||
channel_estimate = fftshift(channel_estimate)
|
||||
return channel_estimate
|
||||
|
||||
def distance_calc(channel_estimate, sampling_rate):
|
||||
@ -57,16 +57,17 @@ def location_estimation(mic_locations, ref_mic, distances, start_point = None):
|
||||
|
||||
# Using the location of the reference microphone as the refence point
|
||||
ref_point = mic_locations[ref_mic]
|
||||
other_indices = [i for i in range(mic_locations.shape[0]) if i != ref_mic]
|
||||
|
||||
# Generating the residuals function that is to be minimized. This residual is the difference between the "guessed" location and the location calculated from the microphone recordings
|
||||
def residuals_function(guess):
|
||||
guess = np.array([guess[0],guess[1],0])
|
||||
residuals = []
|
||||
for i, idx in enumerate(other_indices):
|
||||
mic = mic_locations[idx]
|
||||
residual = (np.linalg.norm(guess-mic) - np.linalg.norm(guess-ref_point)) - distances[i]
|
||||
residuals.append(residual)
|
||||
mic, axs = mic_locations.shape
|
||||
for i in range(mic):
|
||||
if i != ref_mic:
|
||||
mic_location = mic_locations[i]
|
||||
residual = (np.linalg.norm(guess-mic_location) - np.linalg.norm(guess-ref_point)) + distances[i]
|
||||
residuals.append(residual)
|
||||
return residuals
|
||||
|
||||
# Using the least squares method to minimize the residuals function
|
||||
@ -85,9 +86,7 @@ def localization(recordings, sampling_rate):
|
||||
channel_estimates = []
|
||||
recording, mic = recordings.shape
|
||||
for i in range(mic):
|
||||
if i == ref_mic:
|
||||
continue
|
||||
else:
|
||||
if i != ref_mic:
|
||||
channel_estimates.append(channel_estimation(recordings[:, i], recordings[:, ref_mic], epsilon))
|
||||
|
||||
# Finding the distances that correspond to the Time Difference of Arrival (TDOA) for each channel estimate
|
||||
@ -119,6 +118,7 @@ if __name__ == "__main__":
|
||||
real_y = record_y[i]
|
||||
filenames.append(f"../files/Student Recordings/record_x{real_x}_y{real_y}.wav")
|
||||
|
||||
# Performing the location estimation on each file
|
||||
for i in range(len(filenames)):
|
||||
sampling_rate, recordings = wavfile.read(filenames[i])
|
||||
print(f"\nRecording {i+1}: {filenames[i]}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user