examples/UDP Function Generator/README.md
This project demonstrates how to use the UDP Function Generator program to generate and transmit multiple real-time waveforms (sine, triangle, sawtooth, and square) over a UDP network. The program is designed to feed CSV-formatted data to Serial Studio, allowing users to visualize the generated waveforms in real-time.
With Serial Studio, you can use the Quick Plot feature to easily visualize data transmitted via the UDP socket. This provides an intuitive way to test and analyze waveform generation.
A function generator creates electrical waveforms that can be used for testing circuits, analyzing systems, and generating real-time signals for processing. This program simulates such a generator but transmits its output over a UDP socket instead of generating physical signals.
The waveforms can be used for:
To compile the program in UNIX systems, use the following command:
gcc -o udp_function_generator udp_function_generator.c -lm
On Windows, you will need to use:
gcc -o udp_function_generator.exe udp_function_generator.c -lws2_32 -lm
Use the following command to execute the program:
./udp_function_generator [-p port] [-i interval] [-n num_functions] [-v]
-p <port>: UDP port (default: 9000).-i <interval>: Transmission interval in milliseconds (default: 1.0 ms).-n <num_functions>: Number of waveforms to generate (default: 1).-v: Enable verbose output (prints generated data to the console)../udp_function_generator -p 9000 -i 5 -n 3 -v
To visualize the transmitted data:
Download and Install Serial Studio: Visit the official website to download and install the software.
Configure Serial Studio:
Network Socket.UDP as the Socket Type.localhost.-p option (default: 9000).Enable Quick Plot:
Run the Program:
Execute the udp_function_generator program. Waveforms will be displayed in Serial Studio's real-time plot.
When you run the program, it prompts you to configure the waveforms:
sine, triangle, saw, or square).The program validates your input and warns about aliasing or distortion if the frequency is too high relative to the sampling rate.
The program formats the waveform data into a comma-separated string and transmits it via UDP at the specified interval. You can view this data in Serial Studio or analyze it using any UDP-compatible client.
localhost.Command:
./udp_function_generator -p 9000 -i 1 -n 1 -v
Configuration:
sine10 Hz0 radiansCommand:
./udp_function_generator -p 8000 -i 5 -n 3 -v
Configuration:
triangle, 5 Hz, 0 radians.saw, 20 Hz, 1.5 radians.square, 50 Hz, 0 radians.Visualization:
If the frequency exceeds 80% of the Nyquist rate, the program displays a warning:
Warning: Frequency 450.00 Hz approaches the Nyquist rate (500.00 Hz).
Consider reducing it below 400.00 Hz to ensure smooth waveform reconstruction.
This ensures a smooth visualization of waveforms.
For more advanced use cases, refer to the source code and explore the customizable options. You're welcome to make a PR with an improved version of this code.