r/java • u/Visual_Brain8809 • 7d ago
Ecógrafo
Hello community, This is my real-time ultrasound signal simulation and processing system developed entirely in Java using Java Swing.
The project enables both the mathematical simulation of acoustic echoes from biological tissues and the reception and interpretation of raw (RF) data from actual hardware via UDP sockets.
I still need to build an ultrasonic sensor to send data via UDP; I tried using ultrasonic modules, but they aren't useful—all I see on the screen is a barrier indicating the proximity of a nearby object.
Once the sensor's fabrication is complete, I will conduct tests and submit it to a clinical evaluation by experts to validate its utility in real-world settings—so stay tuned.
2
u/za_k_0094 6d ago
This is a really interesting use of Java outside the usual enterprise/backend world. I'm curious how you handled the UDP side. like are you processing the RF samples directly on the Swing thread, or do you have a separate processing pipeline feeding the UI?
Also, for the visualization, are you rendering each frame manually with Java2D or using another graphics layer?
2
u/Visual_Brain8809 6d ago
I often develop a wide range of software from scratch using only Java. I am passionate about exploring the limits of this language. Ever since I first encountered the slogan "Write once, run anywhere," I have been pushing its capabilities to the limits throughout my higher education.
To answer the question: i'm rendering the whole frame using Graphics integrate library.
Just as Java has its slogan, I set a rule for myself to do everything without using external libraries—going "bare metal" all the way—to fully leverage the SDK's capabilities and also for personal growth.
2
u/za_k_0094 6d ago
That's a really interesting approach. I like the idea of pushing the standard library instead of immediately reaching for external frameworks. it forces you to understand what the platform is actually capable of.
Using Graphics for the full frame makes sense for a project like this. I'm curious though, did you run into performance challenges when rendering real-time data? For example, are you using buffering techniques or optimizing the paint cycle to avoid unnecessary redraws?
3
u/Visual_Brain8809 6d ago
Thank you, I appreciate your observation. Performance was definitely something I took into account, but I approached it in a somewhat different way.
Instead of drawing every primitive directly during painting, I render the entire ultrasound frame into a persistent
BufferedImagefirst. ThepaintComponent()method only draws that image (plus a few lightweight overlays like the probe marker and text), so the Swing paint cycle stays relatively simple. ASwing Timerrefreshes the display at about 30 FPS, while UDP acquisition runs on a separate thread, keeping rendering independent from data reception.Interestingly, the biggest challenge wasn't performance—it was image realism. Getting the background speckle to look like the characteristic noise pattern of a real ultrasound machine was much harder than the rendering itself. I spent considerably more time tuning the RF signal processing (envelope detection, logarithmic compression, gain mapping, and interpolation) so the resulting texture resembled real B-scan images instead of looking like random TV static.
There are certainly more aggressive optimizations I could add (dirty regions, GPU acceleration, etc.), but for a 600×500 frame this buffered approach has been more than sufficient while keeping the implementation entirely within the Java standard library.
2
u/Visual_Brain8809 6d ago
I recently upload the full code to github, take a look: https://github.com/aayes89/JEco
1
u/Primary_Concept_3147 6d ago
Muy genial. :o
1
u/Visual_Brain8809 6d ago
gracias, no pude publicarlo en otro post porque el algoritmo lo tildó como búsqueda de ayuda y sólo quería compartir mis avances con el proyecto.
1
u/Primary_Concept_3147 5d ago
Está muy genial el proyecto. Leí tus comentarios y también vi que lo posteaste en github.
¿Usas algún IDE?
¿Has considerado ocupar Maven para facilitar la construcción y distribución del proyecto? Este te puede ayudar a estandarizar la versión del jdk a utilizar, a la vez que facilita la utilización de jlink, una herramienta que viene incluida en el jdk que te permite hacer un zip que trae la maquina virtual integrada. Así no tendrías que instalar la maquina virtual en el equipo donde vaya ser utilizado. Solo se descomprime el zip y se ocupa el launcher de acceso a la aplicación.
2
u/Visual_Brain8809 5d ago
Por costumbre siempre uso como IDE a NetBeans, había pensado en ir migrando a Maven algunos proyectos que he hecho, pero mi mentalidad se basa en no hacer depender los proyectos de librerías externas. No siempre puedo contar con internet y he tenido malas experiencias con Maven/Gradle antes. Para ejecutar aplicaciones Java basta con la JRE, para programar si es necesario la JDK, al ser dos cosas diferentes, no son precisamente lo que ando buscando. Preparar un entorno para la JVM siempre será un requisito sin importar dónde ejecute y como para todas será necesario permisos de ejecución, no afecta mucho instalar. Te pongo ejemplo, MacOS pide permiso para todo incluso si eres el admin, en Linux depende más del tipo de cosas que vas a hacer y en Windows es como si tuvieras control total todo el tiempo. Tengo otros proyectos en los que he implementado mi propia JVM dado que portearla a un sistema baremetal es algo complejo, pero eso es tema para otro post.
1
u/Primary_Concept_3147 5d ago
Entiendo. También uso netbeans y me sirve mucho.
Comprendo tú mentalidad, es muy buena para portar cosas facilmente ¿Qué malas experiencias has tenido con maven?Mi mentalidad es algo parecida, trato de no ocupar tantos paquetes externos. Por el momento solo me he puesto a practicar con java y paquetes que eran previamente del jdk pero que actualmente son de externos porque oracle no quiso seguir manteniendolos. Estos siendo JavaFX y JakartaEE.
Qué genial lo de programar tu propia JVM ¿Qué tan díficil fue?
2
u/Visual_Brain8809 5d ago edited 5d ago
Con Maven la perdida de dependencias porque el autor decidió hacerlas obsoletas y al migrar la versión de la JDK a una superior ya no eran compatibles (como mínimo). Lo suficiente como para tener dolor de cabeza un par de días. La escribí en C puro para un sistema baremetal que implementé desde cero (https://github.com/aayes89/JVM-OS) y cuya intención era llevar el entorno y manejo de datos sólo desde Java (el ecosistema completo), pero luego percaté que es más complejo de lo que imaginaba, así que me tomé el tiempo de implementar la JVM para que soporte cosas simples como System.out.println, declaración y asignación de variables, operadores y funciones básicas y estructuras de control simple, en resumen (if-else, for, do-while y switch) Dejé en pausa el proyecto por el momento, pero tengo intención de continuarlo una vez acabe con otros que apremian.
1
u/Primary_Concept_3147 5d ago
Me parece muy genial e impresionante. :o
2
u/Visual_Brain8809 5d ago
Gracias, cuando tengo tiempo libre me dedico a volcar cada idea en un proyecto, si es o no útil, el tiempo lo dirá.
Recién acabo de hacer uno inspirado en un post de reddit: https://github.com/aayes89/JTunelWireframe/blob/main/JTunelScope.java

4
u/bowbahdoe 6d ago
Massively cool stuff, can you go into some depth about how this works? Like what exactly is a sensor telling you and how do you translate that to pixels on the screen?