Python code matrix ohne GUI

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hallo,

ich habe einen Radar Chip von acconeer. Der läuft an sich am Windows PC uns zeigt grafisch die Geschwindigkeit an. Der Code ist open source.

Nun muss ich aber den Code auf einem Raspi laufen lassen, wo keine GUI existiert. Ich bräuchte immer nur als "print" Ausgabe kontinuirlich die max Speed in dem empfangen Array. Aber das wird wohl über den Plot skaliert und da blicke ich leider nicht durch:

Hier ist der python code:
https://github.com/acconeer/acconeer-py ... rse_fft.py

Geschrieben wird der Plot wohl ganz sicher bei:

Code: Alles auswählen

def update(self, data):
        frame = data["sweep"]

        for i, ys in enumerate(frame.T):
            self.curves[i].setData(ys)

        m = np.max(data["abs_fft"])
        m = max(m, 1e4)
        m = self.smooth_max.update(m)
        self.ft_im.updateImage(data["abs_fft"], levels=(0, m * 1.05))
Die Ausgabe am Windows PC sieht so aus:
https://ibb.co/0DX7gg5

Die farbige Matrix am linken unteren Rand zeigt den Speed an und ändert sich farblich je nach Geschwindigkeit.

Wie bekomme ich aber nun die GUI weg und von den Daten den maximalen Wert?

Vielen Dank!

Georg
Benutzeravatar
ThomasL
User
Beiträge: 1366
Registriert: Montag 14. Mai 2018, 14:44
Wohnort: Kreis Unna NRW

Der max-Wert wird hier ermittelt:

Code: Alles auswählen

m = np.max(data["abs_fft"])
m = max(m, 1e4)
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hallo Thomas,

ok, aber die werte sind nicht in m/s wie in der Grafik ... die werden im Plot wohl noch skaliert?
__deets__
User
Beiträge: 14543
Registriert: Mittwoch 14. Oktober 2015, 14:29

Das hier sieht nach dem Kandidaten dafuer aus: https://github.com/acconeer/acconeer-py ... ft.py#L154

Daraus musst du dir mal mit Stift und Papier die Formel bauen, die eine gegebene Frequenz in eine Geschwindigkeit umrechnet.
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hallo,

hmmm ... aber in der Software wird mir das doch angezeigt. Eventuell muss ich die Skalierung anpassen. So kann ein Wert mit 10500 im Plot bei 2.6m/s stehen.

Diese Skalierung müsste doch durch die y Achse im Code zu sehen sein, oder?

Das ist die GUI die gestartet wird. Danach wählt man "Sparse FFT (sparse)":
https://github.com/acconeer/acconeer-py ... ui/main.py
__deets__
User
Beiträge: 14543
Registriert: Mittwoch 14. Oktober 2015, 14:29

Ich verstehe die Frage nicht. Hast du den von mir verlinkten Code betrachtet? Was daran ist dir unklar? Ich sehe da diverse Groessen wie Wellenlaenge und Aufloesungen, welche die Transformation der Daten bestimmen. Und danach fragst du doch.
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hallo,

leider ist mir python und co nicht so vertraut, aber könnte folgendes stimmen?:

Für m/s wird diese Skalierung genutzt:

Code: Alles auswählen

self.ft_im.scale(self.fft_x_scale, self.f_res * half_wavelength)
Um nun den maximal wert des Sensor von:

Code: Alles auswählen

m = max(m, 1e4)
muss ich durch diese Skalierung laufen lassen?

Ich hatte da mal etwas versucht, aber das wird im Plot skaliert? Die grafische Ansicht kann ich aber nicht nutzen.

Zeitgleich scheint der Hersteller das Projekt zu erweitern.

Danke!
__deets__
User
Beiträge: 14543
Registriert: Mittwoch 14. Oktober 2015, 14:29

Hast du mal die betreffenden Zahlen eingesetzt? Ich habe die hier ja auch nicht vorliegen. Und auch nicht den Sensor, kann also die Software beim besten Willen nicht laufen lassen. Gib dir die verdaechtigen Werte dann mal mit print an der entsprechenden Stelle aus.
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hallo,

ja natürlich mach ich das sehr gerne. Aber erst ab Montag möglich.
Aber magst mir bitte noch einen Tipp wegen der Skalierung geben?

Die Werte werden ja skaliert in den Plot geschrieben:
self.ft_im.scale(self.fft_x_scale, self.f_res * half_wavelength)

und ich hab damals werte von 700 - 2000 bei m bekommen
erik
User
Beiträge: 1
Registriert: Freitag 11. Oktober 2019, 16:33

Hi, Erik here, developer at Acconeer,

My German knowledge is very limited, so I'll reply in English. Hope that's ok!

First off, if you want to run the module without the GUI, you can do so by running its script directly:

Code: Alles auswählen

python3 examples/processing/sparse_fft.py -u /dev/ttyUSB0
Then, if you don't want the plotting, you can remove everything PyQtGraph-related. That is line 105-192, 51, 44-48, 29-31, 7, 2.

Now, you're right in that you have to use same scaling that was used for the plotting to get your speed. You basically want the physical frequency multipled with the half wavelength. To get there, we need to work with the Processor, starting at line 90:

Code: Alles auswählen

class Processor:
    def __init__(self, sensor_config, processing_config, session_info):
        pass

    def process(self, sweep):
        zero_mean_sweep = sweep - sweep.mean(axis=0, keepdims=True)
        fft = np.fft.rfft(zero_mean_sweep.T * np.hanning(sweep.shape[0]), axis=1)
        abs_fft = np.abs(fft)

        return {
            "sweep": sweep,
            "abs_fft": abs_fft,
        }
To calculate the bin index to speed scaling factor, can do something like this (in the init function):

Code: Alles auswählen

half_wavelength = 2.445e-3  # m
subsweep_rate = sensor_config.subsweep_rate
num_subsweeps = sensor_config.number_of_subsweeps
self.bin_index_to_speed = half_wavelength * subsweep_rate / num_subsweeps
To get the maximum bin index itself (in the process function):

Code: Alles auswählen

# abs_fft is a matrix with dims abs_fft[depth, freq_bin]
# we don't care about the depth, so take max over all depths
asd = np.max(abs_fft, axis=0)

# asd becomes a vector (asd[freq_bin])
# now we take the argmax of that
max_bin = np.argmax(asd)
Then you can obtain the speed (in m/s) by

Code: Alles auswählen

speed = max_bin * self.bin_index_to_speed
Hope this helps!

We recently released a speed example script which does this whole thing a bit smarter. Probably quite useful to you. Have a look!

Just for future reference, the version (of sparse_fft.py) as of writing this is be9251f.

Finally, please feel free to open issues and ask questions on GitHub!

Best regards
Erik
unique24
User
Beiträge: 65
Registriert: Donnerstag 5. Juli 2018, 14:51

Hi Erik,

oh, thank you so much. I wrote Magnus by mail and he support all the time fine. My last question about the speed at console in km/h was still open, so ask the community here for help :-)
Yes, I see you are working on a update on GitHub

I will test your code examples on Monday/Tuesday and give a feedback soon.
But I need the distance of the current max speed.
Because I made a picture with a Canon EOS 80D with a 10-20mm lens and full open aperture, to get maximum light. But, this means I have a minimal deep sharpness in my photos and I guess I have, before I made the picture, to optimize the focus point.

Magnus wrote me, with one A111, the speed measuring is not 100% perfect, because of the angle of the movements in front of the radar antenna. So in my housing I reserve a second place for a second module, if I decide to optimize the measurements.

I wrote in GitHub about this optimizing function instead of here, ok?

Thank you!
Antworten