Sponsored Content
Full Discussion: Slow FFT in ksh93 and awk.
Operating Systems OS X (Apple) Slow FFT in ksh93 and awk. Post 303023145 by wisecracker on Wednesday 12th of September 2018 12:11:57 PM
Old 09-12-2018
Hi all...

Well guys, it took a while because of the serious limitations of ARexx for a stock AMIGA A1200 but here is a working FFT for it. ARexx has no ARRAY facility but there is a workaround. ;o)
Boy oh boy, ARexx's arithmetic is so convoluted and floating point precision is not the best.
This was a challenge. I could have generated SIN, COS and SQRT in pure ARexx but decided to use an external ARexx math(s) library instead...
It would be just as easy to create SIN, COS and SQRT in ksh too eliminating awk entirely but awk just made it easier...
Just for the record the AMIGA shell/terminal has a large subset of xterm's escape codes.
An exercise in futility? Maybe but serious fun nevertheless...
This is through FS-UAE AMIGA emulation and my real A1200 setup for easy transfer from this Macbook Pro.
ARexx code:
Code:
/* Simple_FFT_DEMO.rexx */

/* This ARexx version needs this dependency: */
/* http://aminet.net/package/util/rexx/RexxMathLib */
CALL ADDLIB('rexxmathlib.library',0,-30,0)

NUMERIC DIGITS 14

SAY ""
SAY "An experimental method to do an FFT in ARexx using the standard test values."
SAY "It requires rexxmathlib.library for the SIN and COS."
SAY "$VER Simple_FFT_DEMO.rexx_(C)06-09-2018_B.Walker_issued_under_GPL2."
SAY ""

/* Create standard test _ARRAYS_ REAL and IMAGINARY. */
/* These MUST be powers of 2 and greater than 2 in size. */
/* Real values, '1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0' */
/* Imag values, '0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0' */
/* Not really ARRAYS but good enough for this DEMO! */
DO N=0 TO 3 BY 1
	REAL_ARRAY.N=1.0
END
DO N=4 TO 7 BY 1
	REAL_ARRAY.N=0.0
END
DO N=0 TO 7 BY 1
	IMAG_ARRAY.N=0.0
END

/* Display them. */
SAY "Input, REAL: IMAG:"
DO N=0 TO 7 BY 1
	SAY "        "||REAL_ARRAY.N||"   "||IMAG_ARRAY.N
END

/* Only constant required, 14 decimal places. */
PI=3.14159265358979 
/* N should be 8 by default in this DEMO. */
/* SAY "Number of elements = "||N||"..." */
N=N-1

CALL FFT

SAY ""
DO N=0 TO 7 BY 1
	SAY "REAL: "||+OUT_REAL.N||",    IMAG: "||+OUT_IMAG.N
END

SAY ""
SAY "Final FFT values to 5 decimal places:"
STR=""
DO N=0 TO 7 BY 1
	CALL ABS_COMPLEX
	NUMERIC DIGITS 14
	IF +ABS <= 0.000000000001
	THEN
		ABS=0
	ENDIF
	NUMERIC DIGITS 6
	STR=STR||+ABS||" "
END
SAY STR
SAY ""
EXIT

/* Create the subroutines required. */
/* FFT subroutine. */
FFT:
DO K=0 TO N BY 1
	SUMREAL=0.0
	SUMIMAG=0.0
	DO T=0 TO N BY 1
		ANGLE=(2.0*PI*T*K)/(N+1)
		SUMREAL=SUMREAL+(REAL_ARRAY.T*COS(ANGLE))+(IMAG_ARRAY.T*SIN(ANGLE))
		SUMIMAG=SUMIMAG-(REAL_ARRAY.T*SIN(ANGLE))+(IMAG_ARRAY.T*COS(ANGLE))
	END
	OUT_REAL.K=SUMREAL
	OUT_IMAG.K=SUMIMAG
END
RETURN
/* FFT subroutine end. */

/* Absolute value of complex number subroutine. */
ABS_COMPLEX:
	ABS=SQRT( (OUT_REAL.N**2)+(OUT_IMAG.N**2) )
RETURN
/* Absolute value of complex number subroutine end. */

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

echo is too slow. HELP with Awk

Hello All, Below is a simple script i worte to find the 208th char in a file. If the char = "C" then I re-direct the line to a file called change.txt. If it is not "C" then I re-direct it to a file called delete.txt. My problem is I have a file 0f 500K lines. this script is very slow. I am... (4 Replies)
Discussion started by: eja
4 Replies

2. Shell Programming and Scripting

ksh93 deprecation...

Any means of running ksh93 in a ksh88-mode? Might sound odd, but I want/need to restrict U/Win-developed scripts to correspond to the ksh88 version on my Solaris environment(s). Thanks. (2 Replies)
Discussion started by: curleb
2 Replies

3. Shell Programming and Scripting

ksh88 or ksh93

Hi all! Does anybody know how can I check if any UNIX installation has implemented ksh88 or ksh93? Thanks in advance. Néstor. (3 Replies)
Discussion started by: Nestor
3 Replies

4. Shell Programming and Scripting

The builtin split function in AWK is too slow

I have a text file that contains 4 million lines, each line contains 2 fields(colon as field separator). as shown: 123:444,555,666,777,888,345 233:5444,555,666,777,888,345 623:454,585,664,773,888,345 ...... Here I have to split the second field(can be up to 40,000 fields) by comma into an... (14 Replies)
Discussion started by: kevintse
14 Replies

5. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

6. Shell Programming and Scripting

Making a faster alternative to a slow awk command

Hi, I have a large number of input files with two columns of numbers. For example: 83 1453 99 3255 99 8482 99 7372 83 175 I only wish to retain lines where the numbers fullfil two requirements. E.g: =83 1000<=<=2000 To do this I use the following... (10 Replies)
Discussion started by: s052866
10 Replies

7. UNIX for Advanced & Expert Users

Ksh93 on Linux compatible with ksh93 on AIX

Hi Experts, I have several shell scripts that have been developed on a Linux box for korn ksh93. If we want to run this software on an AIX 6.1 box that runs ksh88 by default can we just change the she-bang line to reference /bin/ksh93 which ships with AIX as its "enhanced shell" to ensure... (6 Replies)
Discussion started by: Keith Turley
6 Replies

8. OS X (Apple)

FFT for the AMIGA through ksh88 shell.

I don't know if anyone is interested but I have been meddling with FFT for the AMIGA. (Sadly we AMIGAns don't have these luxuries through any scripting language. Below is a Python snippet that uses the builtin 'cmath' module to work with the lowly Python 2.0.1 for the AMIGA. It is part of a... (0 Replies)
Discussion started by: wisecracker
0 Replies

9. AIX

Ksh93/AIX compatibility

Hi everyone ! Im trying to know from wich version of AIX KSH93 is available ? Internet tell me 6.x and 7.x AIX are available, bue what about 5.x ? Is KSH93 available on AIX 5.x ? Is it the same way to manipulate variables as KSH93 on 7.x ? Thanks for your support and have a nice day ! (2 Replies)
Discussion started by: majinfrede
2 Replies

10. OS X (Apple)

FFT for Python 2.0.x to 3.7.0.

Hi guys... This is code that was originally designed to work on an upgraded AMIGA A1200 using Python 2.0.x. Unfortunately it broke inside much later versions, NOT because of the print statement/function but other minor subtleties. So this is the final result tested on various machines including... (0 Replies)
Discussion started by: wisecracker
0 Replies
shell_builtins(1)						   User Commands						 shell_builtins(1)

NAME
shell_builtins, case, for, foreach, function, if, repeat, select, switch, until, while - shell command interpreter built-in commands DESCRIPTION
The shell command interpreters csh(1), ksh(1), ksh93(1), and sh(1) have special built-in commands. The commands case, for, foreach, func- tion, if, repeat, select, switch, until, and while are commands in the syntax recognized by the shells. They are described in the Commands section of the manual pages of the respective shells. In ksh93(1), fc, hash, stop, suspend, times, and type are aliases by default. In ksh93, the following built-ins are bound to the /bin pathname by default and are invoked if the pathname search encounters an executable command of that name in the /bin or /usr/bin directory: cat, chown, getconf, head, mkdir, rmdir, tee, uniq, and wc. The remaining commands listed in the following table are built into the shells for reasons such as efficiency or data sharing between com- mand invocations. They are described on their respective manual pages. Command Shell ----------------------------------------------------------- ++**alias csh, ksh, ksh93 bg csh, ksh, ksh93, sh +*break csh, ksh, ksh93, sh builtin ksh93 case csh, ksh, ksh93, sh cat ksh93 cd csh, ksh, ksh93, sh chdir csh, sh chown ksh93 command ksh93 +*continue csh, ksh, ksh93, sh dirs csh disown ksh93 echo csh, ksh, ksh93, sh +*eval csh, ksh, ksh93, sh +*exec csh, ksh, ksh93, sh +*exit csh, ksh, ksh93, sh ++**export ksh, ksh93, sh false ksh, ksh93 fc ksh, ksh93 fg csh, ksh, ksh93, sh for ksh, ksh93, sh foreach csh function ksh, ksh93 getconf ksh93 getopts ksh, ksh93, sh glob csh goto csh hash ksh, ksh93, sh hashstat csh head ksh93 hist ksh93 history csh if csh, ksh, ksh93, sh jobs csh, ksh, ksh93, sh kill csh, ksh, ksh93, sh let ksh, ksh93, limit csh login csh, ksh, ksh93, sh logout csh mkdir ksh93 nice csh +*newgrp ksh, ksh93, sh nohup csh notify csh onintr csh popd csh print ksh, ksh93 printf ksh93 pushd csh pwd ksh, ksh93, sh read ksh, ksh93, sh ++**readonly ksh, ksh93, sh rehash csh repeat csh +*return ksh, ksh93, sh select ksh, ksh93 +set csh, ksh, ksh93, sh setenv csh shift csh, ksh, ksh93, sh sleep ksh93 source csh stop csh, ksh, ksh93, sh suspend csh, ksh, sh switch csh tee ksh93 test ksh, ksh93, sh time csh *times ksh, ksh93, sh *+trap ksh, ksh93, sh true ksh, ksh93 type ksh, ksh93, sh ++**typeset ksh, ksh93 ulimit ksh, ksh93, sh umask csh, ksh, ksh93, sh +unalias csh, ksh, ksh93 unhash csh uniq ksh93 unlimit csh +unset csh, ksh, ksh93, sh unsetenv csh until ksh, ksh93, sh *wait csh, ksh, ksh93, sh whence ksh, ksh93 while csh, ksh, ksh93, sh Bourne Shell, sh, Special Commands Input/output redirection is now permitted for these commands. File descriptor 1 is the default output location. When Job Control is enabled, additional Special Commands are added to the shell's environment. In addition to these built-in reserved command words, sh also uses: : No effect; the command does nothing. A zero exit code is returned. .filename Read and execute commands from filename and return. The search path specified by PATH is used to find the directory contain- ing filename. C shell, csh Built-in commands are executed within the C shell. If a built-in command occurs as any component of a pipeline except the last, it is exe- cuted in a subshell. In addition to these built-in reserved command words, csh also uses: : Null command. This command is interpreted, but performs no action. Korn Shell, ksh, Special Commands Input/Output redirection is permitted. Unless otherwise indicated, the output is written on file descriptor 1 and the exit status, when there is no syntax error, is zero. Commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. In addition to these built-in reserved command words, ksh also uses: * : [ arg ... ] The command only expands parameters. * .file [ arg ... ] Read the complete file then execute the commands. The commands are executed in the current shell environment. The search path specified by PATH is used to find the directory containing file. If any arguments arg are specified, they become the positional parameters. Otherwise, the positional parameters are unchanged. The exit status is the exit status of the last command executed. the loop termination test. Korn Shell, ksh93, Special Commands Input/Output redirection is permitted. Unless otherwise indicated, the output is written on file descriptor 1 and the exit status, when there is no syntax error, is zero. Except for :, true, false, echo, newgrp, and login, all built-in commands accept -- to indicate end of options. They also interpret the option --man as a request to display the manual page onto standard error and -? as a help request which prints a usage message on standard error. Commands that are preceded by one or two + are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. They are not valid function names. 5. Words, following a command preceded by ++ that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name genera- tion are not performed. In addition to these built-in reserved command words, ksh93 also uses: : [ arg ... ] The command only expands parameters. .name [ arg ... ] If name is a function defined with the function name reserved word syntax, the function is executed in the cur- rent environment (as if it had been defined with the name() syntax.) Otherwise if name refers to a file, the file is read in its entirety and the commands are executed in the current shell environment. The search path specified by PATH is used to find the directory containing the file. If any arguments arg are specified, they become the positional parameters while processing the . command and the original positional parameters are restored upon completion. Otherwise the positional parameters are unchanged. The exit status is the exit status of the last command executed. SEE ALSO
Intro(1), alias(1), break(1), builtin(1), cd(1), chmod(1), csh(1), disown(1), echo(1), exec(1), exit(1), find(1), getoptcvt(1), getopts(1), glob(1), hash(1), history(1), jobs(1), kill(1), ksh(1), ksh93(1), let(1), limit(1), login(1), logout(1), newgrp(1), nice(1), nohup(1), print(1), printf(1), pwd(1), read(1), readonly(1), set(1), sh(1), shift(1), sleep(1), suspend(1), test(1)test(1), test(1B), time(1), times(1), trap(1), typeset(1), umask(1), wait(1), chdir(2), chmod(2), creat(2), umask(2), getopt(3C), profile(4), environ(5) SunOS 5.11 20 Nov 2007 shell_builtins(1)
All times are GMT -4. The time now is 01:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy