The original AF counter that has yet to be modified.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers The original AF counter that has yet to be modified.
Prev   Next
# 1  
Old 07-04-2013
The original AF counter that has yet to be modified.

Hi guys...

This was my original attempt at the AF Frequency Counter for the AudioScope.sh project...

Code:
#!/bin/bash

# Set the startup values...
data="?"
freq=0
number=""
subscript=0
waveform=0

# An initial screen...
clear
printf "\nA simple 50 Hz to 3500 Hz audio frequency counter.\n"
printf "(C)2013, B.Walker, G0LCU. Issued as Public Domain.\n"
printf "Accuracy is within 0.1 percent of the displayed frequency...\n"
printf "\nFrequency is "$freq"Hz...\n\n"

while true
do
	# This is a demo mode so that there is no need to access HW.
	> /tmp/sinewave.raw
	# This is the binary byte data list for the crude sinewave.
	data="\\x80\\x26\\x00\\x26\\x7F\\xD9\\xFF\\xD9"
	# Generate an 8000 byte file...
	for waveform in {0..999}
	do
	        printf "$data" >> /tmp/sinewave.raw
	done
	# These two modes are for various *NIX flavours using the sound sources as required.
	# dd if=/dev/dsp of=/tmp/sinewave.raw bs=8000 count=1
	# /Users/barrywalker/Downloads/sox-14.4.0/sox -q -V0 -d -t raw -r 8000 -b 8 -c 1 -e unsigned-integer -> /tmp/sinewave.raw trim 0 00:01
	subscript=0
	freq=0
	number=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/sinewave.raw`
	while true
	do
		# Assume a square wave "mark to space" ratio of 1 to 1 is used,
		# then "wait" until a "space" is found.
		# (For those that don't know.)
		#
		#                  +------+      +---
		# Square wave:-    | Mark |Space |
		#               ---+      +------+
		#
		# This ensures that the loop cycles when NO input is
		# applied to the microphone socket.
		# Exit this loop when "mark" is found or n >= 8000...
		while [ $number -le 127 ]
		do
			number=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/sinewave.raw`
			subscript=$[ ( $subscript + 1 ) ]
			# Ensure as soon as subscript >= 8000 occurs it drops out of the loop.
			if [ $subscript -ge 8000 ]
			then
				break
			fi
		done
		# Ensure as soon as subscript >= 8000 occurs it drops completely out of this loop.
		if [ $subscript -ge 8000 ]
		then
			break
		fi
		# Now the "mark" can loop until a "space" is found again and the whole
		# can cycle until subscript >= 8000...
		while [ $number -ge 128 ]
		do
			number=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/sinewave.raw`
			subscript=$[ ( $subscript + 1 ) ]
			# Ensure as soon as subscript >= 8000 occurs it drops out of the loop.
			if [ $subscript -ge 8000 ]
			then
				break
			fi
		done
		# Ensure as soon as subscript >= 8000 occurs it drops completely out of this loop.
		if [ $subscript -ge 8000 ]
		then
			break
		fi
		# "freq" will become the frequency of a symmetrical waveform
		# when the above loops are finally exited, subscript >= 8000...
		# Tick up the freq(uency) per "mark to space" cycle.
		freq=$[ ( $freq + 1 ) ]
		done
	clear
	printf "\nA simple 50 Hz to 3500 Hz audio frequency counter.\n"
	printf "(C)2013, B.Walker, G0LCU. Issued as Public Domain.\n"
	printf "Accuracy is within 0.1 percent of the displayed frequency...\n"
	printf "\nFrequency is "$freq"Hz...\n\n"

done
# End of Freq_Counter.sh DEMO.
# Enjoy finding simple solutions to often very difficult problems.

It is SSLLOOWW man but works.
I only need to read 1990 to 2010 Hz and this sampling speed is more than good enough.
I have yet to do it using one of you guys ideas using an array, (forgot his name), but I will proceed with it again soon...

This code is a derivative of Python code I wrote about 1.5+ years ago here:-

A DEMO Frequency Counter With A Difference - Text Mode Python. Python recipes ActiveState Code

Another freebie give away... ;o)

EDIT:

I forgot to add the Python version does each take in less than 1.2 seconds INCLUDING the 1 second grab.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Do i miss counter or what

hello this script should show all users and space they used without problem : ls /home >> /root/users.txt cat /root/users.txt | while read line; do space=`du -s /home/$line` echo "$line space is $space" shift done but when i remove pipe ,script run without any output: ls /home... (4 Replies)
Discussion started by: nimafire
4 Replies

2. UNIX for Dummies Questions & Answers

Is original file modified when pigz is interrupted?

I had to stop a pigz (parallel gzip) compression before it completed. Is the original uncompressed file changed/corrupted? I was under the impression that the original file is not changed during compression, though it is deleted if the compression is successful. (1 Reply)
Discussion started by: colin123
1 Replies

3. UNIX for Dummies Questions & Answers

Pegging counter

Hi Experts, I am in need for some help. My competence level on unix is not at all helping me to resolve this. Please help. My Input for a system command is as under: Counters are getting pegged each hour. I need to have a difference printed rather than pegged counter values. Counter... (2 Replies)
Discussion started by: vanand420
2 Replies

4. Shell Programming and Scripting

Counter

if ;then echo "mrnet greater 5000" gzip /var/log/mrnet.log mv /var/log/mrnet.log.gz /var/log/mrnet.log.1.gz if ];then i=1 let i++ mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz else echo "theres no... (1 Reply)
Discussion started by: Froob
1 Replies

5. Shell Programming and Scripting

DelimiterCount: how to use a counter

Hi, I am new to shell script. I want to count to Delimiter count for my source file. For that I have written script. When I tried to execute the script I could not able to view the results. It throws errors. I don't know what the problem is. My aim is I want to store the delimiter count in one... (4 Replies)
Discussion started by: suresh01_apk
4 Replies

6. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

7. Shell Programming and Scripting

counter

Hi, I need some help. Shell script counter. i need to add condition to check if counter is more than 10 and longer than 3 hours? it runs every 5 mins. it only check count and send email right now. it runs in cron as below gregcount.ksh gregdb 10 > /tmp/gregcount.out 2> /tmp/gregcount.err ... (1 Reply)
Discussion started by: pega
1 Replies

8. Shell Programming and Scripting

How to get a filename modified by attaching modified timestamp

Hi, I want to modify a filename in AIX by attaching the last modified timestamp. I want the timestamp completely in numerical format (eg:200905081210. yr-2009, mnth - 05, date -08, hr - 12, mins - 10). For example if the filename is a.log and it was modified on April 6th 2008 at 21.00. I... (16 Replies)
Discussion started by: Ruks
16 Replies

9. Shell Programming and Scripting

counter in a variable - can it be done?

I have the following for(( i=1; 1<=2; i++)) do e1=123 n1=123 e2=456 n2=456 coord= $e1,$n1 echo "coordinate=$coord" done exit this echos coordinate=123,123 I need it to loop so: loop1 coord=$e1,$n1 loop2 (3 Replies)
Discussion started by: gazz1982
3 Replies

10. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies
Login or Register to Ask a Question