frequency

Confusion in figuring out the relation between actual frequency values and FFT plot indexes in MATLAB

别来无恙 提交于 2019-12-01 04:49:17
问题 I know that there are a lot of similar questions to this, I am still unable to figure out the answer. Let's say we have time signal in MATLAB: t=0:1/44100:1 and a cosine signal with frequency 500Hz: x=cos(2*pi*500*t); Now, I am trying to plot the magnitude spectrum obtained using the fft command on signal x FFT=abs(fft(x)) plot(FFT) According to the theory, we should get two peaks in the plot, one at -500 Hz and the other at 500Hz. What I don't understand is that I do get two peaks but I can

Calculating CPU frequency in C with RDTSC always returns 0

空扰寡人 提交于 2019-12-01 04:45:50
问题 The following piece of code was given to us from our instructor so we could measure some algorithms performance: #include <stdio.h> #include <unistd.h> static unsigned cyc_hi = 0, cyc_lo = 0; static void access_counter(unsigned *hi, unsigned *lo) { asm("rdtsc; movl %%edx,%0; movl %%eax,%1" : "=r" (*hi), "=r" (*lo) : /* No input */ : "%edx", "%eax"); } void start_counter() { access_counter(&cyc_hi, &cyc_lo); } double get_counter() { unsigned ncyc_hi, ncyc_lo, hi, lo, borrow; double result;

Counting phrase frequency in Python 3.3.2

依然范特西╮ 提交于 2019-12-01 04:27:02
I have been examining different sources on the web and have tried various methods but could only find how to count the frequency of unique words but not unique phrases. The code I have so far is as follows: import collections import re wanted = set(['inflation', 'gold', 'bank']) cnt = collections.Counter() words = re.findall('\w+', open('02.2003.BenBernanke.txt').read().lower()) for word in words: if word in wanted: cnt [word] += 1 print (cnt) If possible, I would also like to count the number of times the phrases 'central bank' and 'high inflation' is used in this text. I appreciate any

Creating a table with individual trials from a frequency table in R (inverse of table function)

二次信任 提交于 2019-12-01 03:46:54
I have a frequency table of data in a data.frame in R listing factor levels and counts of successes and failures. I would like to turn it from frequency table into a list of events - i.e. the opposite of the "table" command. Specifically, I would like to turn this: factor.A factor.B success.count fail.count -------- -------- ------------- ---------- 0 1 0 2 1 1 2 1 into this: factor.A factor.B result -------- -------- ------- 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 It seems to me that reshape ought to do this, or even some obscure base function that I have not heard of, but I've had no luck. Even

Java equivalent of C# system.beep?

十年热恋 提交于 2019-12-01 02:07:59
I am working on a Java program, and I really need to be able to play a sound by a certain frequency and duration, similarly to the c# method System.Beep, I know how to use it in C#, but I can't find a way to do this in Java. Is there some equivalent, or another way to do this? using System; class Program { static void Main() { // The official music of Dot Net Perls. for (int i = 37; i <= 32767; i += 200) { Console.Beep(i, 100); } } } I don't think there's a way to play tunes 1 with "beep" in portable 2 Java. You'll need to use the javax.sound.* APIs I think ... unless you can find a third

subset based on frequency level [duplicate]

柔情痞子 提交于 2019-12-01 00:21:18
This question already has an answer here: Subset data frame based on number of rows per group 2 answers I want to generate a df that selects rows associated with an "ID" that in turn is associated with a variable called cutoff. For this example, I set the cutoff to 9, meaning that I want to select rows in df1 whose ID value is associated with more than 9 rows. The last line of my code generates a df that I don't understand. The correct df would have 24 rows, all with either a 3 or a 4 in the ID column. Can someone explain what my last line of code is actually doing and suggest a different

How to extract counts as a vector from a table in R?

99封情书 提交于 2019-11-30 20:55:01
I'm trying to write a function to extract the frequencies of this table: 0 1 2 3 4 5 6 7 30 22 9 12 2 5 1 16 So I want to get c(30, 22, 9, 12, 2, 5, 1, 16) . The table changes each time I run the function, so I need something that can extract the information from the table automatically, so I don't have write a c() function each time. It honestly could not be any simpler. If you cannot figure this out, you will have lots of other problems: > set.seed(42) ## be reproducible > X <- sample(1:5, 50, replace=TRUE) ## our data > table(X) ## our table X 1 2 3 4 5 7 6 9 10 18 > str(table(X)) ## look

Create wordcloud from a data frame in R

最后都变了- 提交于 2019-11-30 20:05:03
问题 I made a sample data frame. I try to make a wordcloud from the Projects column. Hours<-c(2,3,4,2,1,1,3) Project<-c("a","b","b","a","c","c","c") Period<-c("2014-11-22","2014-11-23","2014-11-24","2014-11-22", "2014-11-23", "2014-11-23", "2014-11-24") cd=data.frame(Project,Hours,Period) Here is my code: cd$Project<-as.character(cd$Project) wordcloud(cd$Project,min.freq=1) but I get the following error: Error in strwidth(words[i], cex = size[i], ...) : invalid 'cex' value In addition: Warning

Displaying a double (frequency) that is updated constantly while recording with Android

谁说胖子不能爱 提交于 2019-11-30 16:33:19
I am building an android application that displays the Frequency of a sustained note with the FFT algorithm. I am using Jtransform methods. My issue currently is that I can't display the frequency on screen. The following code is the fft freqency calculation and the AsynchTask which should display the frequency in a text box import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D; public class Tuning extends Activity implements OnClickListener{ int audioSource = MediaRecorder.AudioSource.MIC; // Audio source is the device mic int channelConfig = AudioFormat.CHANNEL_IN_MONO; // Recording in mono

Extract audio frequency from instrument to find a musical note

≯℡__Kan透↙ 提交于 2019-11-30 16:31:38
I'm trying to develop an Android app that extracts audio frequency from an instrument. I'm using Fast Fourier Transform method with Jtransforms. Here is what I have so far: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new readFrequencies().execute(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private class