Update auto-tune.py fix name

fiabv4-auto-tune
Alan Johnston 2 months ago committed by GitHub
parent a0dbfdc646
commit 20090e5cf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -16,44 +16,39 @@ if __name__ == "__main__":
graph = 'y'
# Create a sample signal (sum of two sine waves)
sampling_rate = 1024e3 # 250e3 # Hz
duration = 65536/sampling_rate # 1 # seconds
# t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
# frequency1 = 50 # Hz
# frequency2 = 120 # Hz
# signal = 0.7 * np.sin(2 * np.pi * frequency1 * t) + np.sin(2 * np.pi * frequency2 * t)
sampling_rate = 1024e3 # 250e3 # Hz
duration = 65536/sampling_rate # 1 # seconds
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
sdr = RtlSdr()
sdr = RtlSdr()
# configure device
sdr.sample_rate = sampling_rate # 250e3 # 2.4e6
#center_frequency = 434.8e6
sdr.center_freq = center_frequency
sdr.gain = 4
sdr.direct_sampling = False
# configure device
sdr.sample_rate = sampling_rate # 250e3 # 2.4e6
#center_frequency = 434.8e6
sdr.center_freq = center_frequency
sdr.gain = 4
sdr.direct_sampling = False
# signal = sdr.read_samples(64*1024) #256
signal = sdr.read_samples(duration*sampling_rate).real #256
# signal = sdr.read_samples(64*1024) #256
signal = sdr.read_samples(duration*sampling_rate).real #256
print(f"Center frequency is {center_frequency}")
print(f"Center frequency is {center_frequency}")
sdr.close()
sdr.close()
# Compute the FFT
fft_result = np.fft.fft(signal)
# Compute the FFT
fft_result = np.fft.fft(signal)
# Calculate the frequencies corresponding to the FFT output
n = len(signal)
frequencies = np.fft.fftfreq(n, d=1/sampling_rate)
# Calculate the frequencies corresponding to the FFT output
n = len(signal)
frequencies = np.fft.fftfreq(n, d=1/sampling_rate)
# Take the absolute value for amplitude spectrum and consider only the positive frequencies
positive_frequencies_indices = np.where(frequencies >= 0)
positive_frequencies = frequencies[positive_frequencies_indices]
amplitude_spectrum = 2/n * np.abs(fft_result[positive_frequencies_indices]) # Normalize for amplitude
# Take the absolute value for amplitude spectrum and consider only the positive frequencies
positive_frequencies_indices = np.where(frequencies >= 0)
positive_frequencies = frequencies[positive_frequencies_indices]
amplitude_spectrum = 2/n * np.abs(fft_result[positive_frequencies_indices]) # Normalize for amplitude
if (graph == 'y'):
if (graph == 'y'):
# Plotting the results
plt.figure(figsize=(12, 6))
@ -73,24 +68,24 @@ if (graph == 'y'):
plt.tight_layout()
plt.show()
# print(amplitude_spectrum)
x = amplitude_spectrum
# print(x)
min_value = min(x)
max_value = max(x)
# print(amplitude_spectrum)
x = amplitude_spectrum
# print(x)
min_value = min(x)
max_value = max(x)
#freq_min = np.argmax(min_value)
# print(np.argmax(x))
# print(np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
# print(sampling_rate)
# print(center_frequency)
#freq_min = np.argmax(min_value)
# print(np.argmax(x))
# print(np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
# print(sampling_rate)
# print(center_frequency)
offset = (np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
freq_max = center_frequency + offset
offset = (np.argmax(x)*(150e3 - 10e3)/(9770 - 709))
freq_max = center_frequency + offset
print(f" {freq_max} {max_value}")
#print(f"The minimum signal is {min_value} at frequency {freq_min}")
print(f" {freq_max} {max_value}")
#print(f"The minimum signal is {min_value} at frequency {freq_min}")
#print(min_value)
#print(max_value)
#print(min_value)
#print(max_value)

Loading…
Cancel
Save

Powered by TurnKey Linux.