Sponsored Content
Operating Systems OS X (Apple) Plotting A Sine Curve Inside A Bash Shell... Post 302914568 by wisecracker on Tuesday 26th of August 2014 04:52:18 PM
Old 08-26-2014
Plotting A Sine Curve Inside A Bash Shell...

Hi all...

After mentioning the generation of a sinewave sweep generator in a previous thread in this forum this is the method I decided upon.

It plots a sinewave inside an 80 x 24 terminal window.
Although the original used bc (and the line is in the code but commented out) it is now changed to use awk as CygWin has NOT got "bc" in a default install.

It is __relatively__ simple now to create a swept frequency generator from 4 KHz to around 50 Hz and back using the default '/dev/dsp' mode for CygWin and/or 'aplay' or 'afplay' using a .WAV variant...

Enjoy finding simple solutions to often very difficult problems...
Code:
#!/bin/bash
# plotsine.sh
# A DEMO to display a sinewave inside a standard bash terminal.
# Issued as Public Domain, 2014, B.Walker, G0LCU.
# Device: Macbook Pro 13", OSX 10.7.5, default bash terminal.
# Use variables so that you can see how it works.
angle=0
step_angle=5
vert_plot=0
horiz_plot=5
centreline=12
amplitude=11
PI=3.14159
clear
# Do a single cycle, quantised graph.
while [ $angle -le 359 ]
do
	# Create each floating point value...
	# CygWin does not have the 'bc' command but it is now catered for... ;o)
	vert_plot=$(awk "BEGIN{ printf \"%.12f\", ((sin($angle*($PI/180))*$amplitude)+$centreline)}")
	# vert_plot=$(bc -l <<< "{print ((s($angle*($PI/180))*$amplitude)+$centreline)}")
	# Truncate the floating point value to an integer then invert the plot to suit the x y co-ordinates inside a terminal...
	vert_plot=$((24-${vert_plot/.*}))
	# Plot the point(s) and print the angle at that point...
	printf "\x1B["$vert_plot";"$horiz_plot"f*"
	printf "\x1B[22;1fAngle is $angle degrees... "
	sleep 0.1
	# Increment values...
	angle=$((angle+step_angle))
	horiz_plot=$((horiz_plot+1))
done
printf "\x1B[23;1fSinewave plotted as a quantised text mode graph.\n"
exit 0
# The results printed inside an 80 x 24 terminal window...
#
#                  *********
#               ***         ***
#              *               *
#            **                 **
#           *                     *
#          *                       *
#         *                         *
#        *                           *
#       *                             *
#      *                               *
#    **                                 **
#                                         *                                 *
#                                          *                               *
#                                           *                             *
#                                            *                           *
#                                             *                         *
#                                              *                       *
#                                               *                     *
#                                                **                 **
#                                                  *               *
#Angle is 355 degrees...                            ***         ***
#Sinewave plotted as a quantised text mode graph.      *********

 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] redirect standard error and use it inside

Hi all, Maybe my question is too simple but till now i couldn't figure about a solution :( I have a bash script scheduled in cron: <cron time parameters> my_script.sh > result.log 2>&1 By this way i can have standard output and standard error in my result.log file Now i want my script... (2 Replies)
Discussion started by: Pescator
2 Replies

2. Shell Programming and Scripting

running bash command inside awk

Org file 192.168.1.10 d:\adir\xdir 192.168.1.11 d:\bdir\ydir want to covert it into robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\adir robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\bbdir (5 Replies)
Discussion started by: ydk
5 Replies

3. UNIX for Dummies Questions & Answers

using awk inside bash script?

Hello, I'm trying to write a bash script that will query the current system time (OS X 10.6.6) and then convert the output from HH:MM:SS into time in seconds. The output of the system time command (systemsetup -gettime) is returned as: Time: HH:MM:SS so I wanted to use awk -F: to grab... (5 Replies)
Discussion started by: xaiu
5 Replies

4. Shell Programming and Scripting

Learning curve to understand bash iteration

Hi Folks, I know on one side there is script and on another side there is smart script. I am able to achieve what I got but thought there has to be a code which doesn't require multiple lines. So if you guys can help me out than it will be awesome. Also I wrote in cshell but if can get both the... (4 Replies)
Discussion started by: dixits
4 Replies

5. Shell Programming and Scripting

Hide bash code which is inside C plus plus program

I am embedding bash in cpp. Can the bash code be hidden (when we cat the executable to not be able to see the bash code) The simple code I am using: #include <iostream> #include <cstdlib> using namespace std; #define test1 "\ #!/bin/sh --posix \n\ echo... (1 Reply)
Discussion started by: frad
1 Replies

6. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

7. Shell Programming and Scripting

Need Multiple checks inside if condition in a bash shell script

Hi, I need to perform the untar and rm operation if the file found is a .tar and does not have test.tar or hello.tar as the file names. Below is the loop to check the same. for tf in *.tar do if ] then found=1 ... (1 Reply)
Discussion started by: mohtashims
1 Replies
Gtk2::Curve(3pm)					User Contributed Perl Documentation					  Gtk2::Curve(3pm)

NAME
Gtk2::Curve - wrapper for GtkCurve HIERARCHY
Glib::Object +----Glib::InitiallyUnowned +----Gtk2::Object +----Gtk2::Widget +----Gtk2::DrawingArea +----Gtk2::Curve INTERFACES
Glib::Object::_Unregistered::AtkImplementorIface Gtk2::Buildable METHODS
widget = Gtk2::Curve->new $curve->set_curve_type ($type) o $type (Gtk2::CurveType) $curve->set_gamma ($gamma) o $gamma (double) $curve->set_range ($min_x, $max_x, $min_y, $max_y) o $min_x (double) o $max_x (double) o $min_y (double) o $max_y (double) $curve->reset list = $curve->get_vector ($veclen=32) o $veclen (integer) Returns a list of real numbers, the curve's vector. $curve->set_vector (...) o ... (list) of float's, the points of the curve PROPERTIES
'curve-type' (Gtk2::CurveType : default "spline" : readable / writable / private) Is this curve linear, spline interpolated, or free-form 'max-x' (float : default 1 : readable / writable / private) Maximum possible X value 'max-y' (float : default 1 : readable / writable / private) Maximum possible value for Y 'min-x' (float : default 0 : readable / writable / private) Minimum possible value for X 'min-y' (float : default 0 : readable / writable / private) Minimum possible value for Y SIGNALS
curve-type-changed (Gtk2::Curve) ENUMS AND FLAGS
enum Gtk2::CurveType o 'linear' / 'GTK_CURVE_TYPE_LINEAR' o 'spline' / 'GTK_CURVE_TYPE_SPLINE' o 'free' / 'GTK_CURVE_TYPE_FREE' SEE ALSO
Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::DrawingArea COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice. perl v5.14.2 2012-05-27 Gtk2::Curve(3pm)
All times are GMT -4. The time now is 09:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy