RF Measurement [Magnitude(frequency)]

Add useful snippets of code or links to entire SDR projects.
Jim-Alt
Posts: 1
Joined: Mon Mar 26, 2018 9:51 am

RF Measurement [Magnitude(frequency)]

Postby Jim-Alt » Mon Mar 26, 2018 12:23 pm

Hello,

I'm using GRC with a DVB-T tuner Chip.
I would like to know if there is a way to extract the Magnitude and the frequencies from a GT GUI Frequency Sink ?

I have also recorded the signal with a File Sink in order to process the data myself to get the same result but everytime I get something different than the result plot on the QT GUI Frequency Sink.

In the attachments you'll found the recorded signal as a binary file and a Python generated code from GRC corresponding to the display I want to be able either to generate or to extract data from it.

You'll find the code I have develop to process those data below :

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import numpy as np
import scipy.io

#Variables
sample_rate = 800000.0
FFT_size = 2048

delta_sample = (1.0 / sample_rate)
#print("delta_sample [s]=",delta_sample)


#File Recovery
signal = scipy.fromfile(open("/home/jalibert/Documents/3-GRC/2-Data_Output/Data_Recorded.bin"), dtype=scipy.float32)

#Check the lenght of the sample recorded
length_signal = len(signal)

#Calcul the duration of the sample recorded in [s]
sample_time = length_signal * delta_sample


#Creation of the abscissa axis in a list
t=[]
for index,data in enumerate (signal) :
   time = delta_sample * index
   t.append(time)


#Display Temporal Signal
#Slicing the sample to reduce the duration of the process
t_slice = t[0:FFT_size]
signal_slice = signal[0:FFT_size]

plt.figure()
plt.plot(t_slice,signal_slice)
plt.title('Temporal Signal Sample 1')
plt.ylabel('Amplitude')


#fft process
signal_fft_slice = np.fft.fft(signal_slice)
freq_slice= np.fft.fftfreq(len(signal_fft_slice))


#Amplitude Calculation (Linear)
signal_fft_slice_magnitude_Lin = np.sqrt(np.square(signal_fft_slice.real)+np.square(signal_fft_slice.imag))
#Amplitude Calculation (dB)
signal_fft_slice_magnitude_dB = 10 * np.log10(signal_fft_slice_magnitude_Lin/1000)

plt.figure()
plt.plot(freq_slice,signal_fft_slice_magnitude_Lin)
plt.title('FFT')
plt.ylabel('Amplitude [Lin]')
plt.figure()
plt.plot(freq_slice,signal_fft_slice_magnitude_dB)
plt.title('FFT')
plt.ylabel('Amplitude [dB]')


#Peack Searching
max_mag = -100
index_f_max = 0
for index, mag in enumerate (signal_fft_slice_magnitude_dB):
   if mag > max_mag :
      max_mag = mag
      index_f_mag = index

print("Peak :")
print("Amplitude Lineaire :",signal_fft_slice_magnitude_Lin[index_f_mag])
print("Amplitude : [dB]",max_mag)
print("Frequence : [Hz]",freq_slice[index_f_mag]*sample_rate)


plt.show()




Edit :
I haven't been able to attach the files I wanted to, due to the format.
If you need this file, I'll gladly send them to your email.

Any help will be really appreciated.

Cordially

J.Alt
Last edited by Jim-Alt on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 848
Joined: Wed Jan 07, 2015 7:58 am

Re: RF Measurement [Magnitude(frequency)]

Postby sdrplay » Mon Mar 26, 2018 2:56 pm

I have moved this thread from the SDRplay Related forum, as it's not SDRplay related. Please also note that this is not a help group for Gnu Radio, you may get more specific responses from the Gnu Radio forums.

Reason: No reason


Return to “Code Corner”

Who is online

Users browsing this forum: No registered users and 1 guest