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

Loading…
Cancel
Save

Powered by TurnKey Linux.