frequency

Python frequency detection

自作多情 提交于 2019-11-26 06:17:50
问题 Ok what im trying to do is a kind of audio processing software that can detect a prevalent frequency an if the frequency is played for long enough (few ms) i know i got a positive match. i know i would need to use FFT or something simiral but in this field of math i suck, i did search the internet but didn not find a code that could do only this. the goal im trying to accieve is to make myself a custom protocol to send data trough sound, need very low bitrate per sec (5-10bps) but im also

Android audio FFT to retrieve specific frequency magnitude using audiorecord

左心房为你撑大大i 提交于 2019-11-26 04:36:28
问题 I am currently trying to implement some code using Android to detect when a number of specific audio frequency ranges are played through the phone\'s microphone. I have set up the class using the AudioRecord class: int channel_config = AudioFormat.CHANNEL_CONFIGURATION_MONO; int format = AudioFormat.ENCODING_PCM_16BIT; int sampleSize = 8000; int bufferSize = AudioRecord.getMinBufferSize(sampleSize, channel_config, format); AudioRecord audioInput = new AudioRecord(AudioSource.MIC, sampleSize,

How to count the frequency of the elements in a list?

烂漫一生 提交于 2019-11-26 03:14:03
问题 I need to find the frequency of elements in a list a = [1,1,1,1,2,2,2,2,3,3,4,5,5] output-> b = [4,4,2,1,2] Also I want to remove the duplicates from a a = [1,2,3,4,5] 回答1: Since the list is ordered you can do this: a = [1,1,1,1,2,2,2,2,3,3,4,5,5] from itertools import groupby [len(list(group)) for key, group in groupby(a)] Output: [4, 4, 2, 1, 2] 回答2: In Python 2.7 (or newer), you can use collections.Counter: import collections a = [1,1,1,1,2,2,2,2,3,3,4,5,5] counter=collections.Counter(a)

How to find most common elements of a list?

牧云@^-^@ 提交于 2019-11-26 02:37:03
问题 Given the following list [\'Jellicle\', \'Cats\', \'are\', \'black\', \'and\', \'white,\', \'Jellicle\', \'Cats\', \'are\', \'rather\', \'small;\', \'Jellicle\', \'Cats\', \'are\', \'merry\', \'and\', \'bright,\', \'And\', \'pleasant\', \'to\', \'hear\', \'when\', \'they\', \'caterwaul.\', \'Jellicle\', \'Cats\', \'have\', \'cheerful\', \'faces,\', \'Jellicle\', \'Cats\', \'have\', \'bright\', \'black\', \'eyes;\', \'They\', \'like\', \'to\', \'practise\', \'their\', \'airs\', \'and\', \

Python - Is a dictionary slow to find frequency of each character?

笑着哭i 提交于 2019-11-26 02:09:35
问题 I am trying to find a frequency of each symbol in any given text using an algorithm of O(n) complexity. My algorithm looks like: s = len(text) P = 1.0/s freqs = {} for char in text: try: freqs[char]+=P except: freqs[char]=P but I doubt that this dictionary-method is fast enough, because it depends on the underlying implementation of the dictionary methods. Is this the fastest method? UPDATE: there is no increase in speed if collections and integers are used. It is because the algorithm is

Relative frequencies / proportions with dplyr

做~自己de王妃 提交于 2019-11-26 01:46:06
问题 Suppose I want to calculate the proportion of different values within each group. For example, using the mtcars data, how do I calculate the relative frequency of number of gears by am (automatic/manual) in one go with dplyr ? library(dplyr) data(mtcars) mtcars <- tbl_df(mtcars) # count frequency mtcars %>% group_by(am, gear) %>% summarise(n = n()) # am gear n # 0 3 15 # 0 4 4 # 1 4 8 # 1 5 5 What I would like to achieve: am gear n rel.freq 0 3 15 0.7894737 0 4 4 0.2105263 1 4 8 0.6153846 1 5

Frequency counts in R [duplicate]

风格不统一 提交于 2019-11-26 01:40:26
问题 This question already has an answer here: Faster ways to calculate frequencies and cast from long to wide 4 answers How do I get a contingency table? 6 answers This may seem like a very basic R question, but I\'d appreciate an answer. I have a data frame in the form of: col1 col2 a g a h a g b i b g b h c i I want to transform it into counts, so the outcome would be like this. I\'ve tried using table () function, but seem to only be able to get the count for one column. a b c g 2 1 0 h 1 1 0

Item frequency count in Python

强颜欢笑 提交于 2019-11-26 00:55:02
问题 Assume I have a list of words, and I want to find the number of times each word appears in that list. An obvious way to do this is: words = \"apple banana apple strawberry banana lemon\" uniques = set(words.split()) freqs = [(item, words.split().count(item)) for item in uniques] print(freqs) But I find this code not very good, because the program runs through the word list twice, once to build the set, and a second time to count the number of appearances. Of course, I could write a function

Item frequency count in Python

最后都变了- 提交于 2019-11-25 19:26:32
Assume I have a list of words, and I want to find the number of times each word appears in that list. An obvious way to do this is: words = "apple banana apple strawberry banana lemon" uniques = set(words.split()) freqs = [(item, words.split().count(item)) for item in uniques] print(freqs) But I find this code not very good, because the program runs through the word list twice, once to build the set, and a second time to count the number of appearances. Of course, I could write a function to run through the list and do the counting, but that wouldn't be so Pythonic. So, is there a more