Does anyone know a little bit of Java? I am trying to compile and run a java program. I can't manage to get in the JEdit folder using the command prompt. (cd JEdit) it says that the path doesn't exit. and I am sure 100% that it exists.
So, I got this code off a website, but when I run it a blank window pops-up but nothing happens.
It was supposed to show some graphs and when you move the mouse over it the sine waves would change into frequency responses, or something similar. Anyway, can someone run the code and tell me if it works on your computer? I ve been trying to 'de-bug' it since last week and I don't see why it's not working.
Thank you very much!
Daniela
// fft utils for amit // based on nullsoft VMS and stephan sprenger's FFT paper
class FFTutils { int WINDOW_SIZE,WS2; int BIT_LEN; int[] _bitrevtable; float _normF; float[] _equalize; float[] _envelope; float[] _fft_result; float[][] _fftBuffer; float[] _cosLUT,_sinLUT; float[] _FIRCoeffs; boolean _isEqualized, _hasEnvelope;
// taken from nullsoft VMS // reduces impact of bassy freqs and slightly amplifies top range void useEqualizer(boolean on) { _isEqualized=on; if (on) { int i; float scaling = -0.02f; float inv_half_nfreq = 1.0f/WS2; _equalize = new float[WS2]; for (i=0; i<WS2; i++) _equalize[i] = scaling * (float)Math.log( (double)(WS2-i)*inv_half_nfreq ); } }
// bell filter envelope to reduce artefacts caused by the edges of standard filter rect // 0.0 < power < 2.0 void useEnvelope(boolean on, float power) { _hasEnvelope=on; if (on) { int i; float mult = 1.0f/(float)WINDOW_SIZE * TWO_PI; _envelope = new float[WINDOW_SIZE]; if (power==1.0f) { for (i=0; i<WINDOW_SIZE; i++) _envelope[i] = 0.5f + 0.5f*sin(i*mult - HALF_PI); } else { for (i=0; i<WINDOW_SIZE; i++) _envelope[i] = pow(0.5f + 0.5f*sin(i*mult - HALF_PI), power); } } }
// compute actual FFT with current settings (eq/filter etc.) float[] computeFFT(float[] waveInData) { float u_r,u_i, w_r,w_i, t_r,t_i; int l, le, le2, j, jj, ip, ip1, i, ii, phi;
// check if we need to apply window function or not if (_hasEnvelope) { for (i=0; i<WINDOW_SIZE; i++) { int idx = _bitrevtable[i]; if (idx < WINDOW_SIZE) _fftBuffer[i][0] = waveInData[idx]*_envelope[idx]; else _fftBuffer[i][0] = 0; _fftBuffer[i][1] = 0; } } else { for (i=0; i<WINDOW_SIZE; i++) { int idx = _bitrevtable[i]; if (idx < WINDOW_SIZE) _fftBuffer[i][0] = waveInData[idx]; else _fftBuffer[i][0] = 0; _fftBuffer[i][1] = 0; } }
float I0 (float x) { // zero order Bessel function of the first kind float eps = 1.0e-6f; // accuracy parameter float fact = 1.0f; float x2 = 0.5f * x; float p = x2; float t = p * p; float s = 1.0f + t; for (int k = 2; t > eps; k++) { p *= x2; fact *= k; t = sq(p / fact); s += t; } return s; }
int computeOrder() { // estimate filter order order = 2 * (int) ((atten - 7.95) / (14.36*trband/fN) + 1.0f); // estimate Kaiser window parameter if (atten >= 50.0f) kaiserV = 0.1102f*(atten - 8.7f); else if (atten > 21.0f) kaiserV = 0.5842f*(float)Math.exp(0.4f*(float)Math.log(atten - 21.0f))+ 0.07886f*(atten - 21.0f); if (atten <= 21.0f) kaiserV = 0.0f; println("filter oder: "+order); return order; }
void initialize() { computeOrder(); // window function values float I0alpha = 1f/I0(kaiserV); int m = order>>1; float[] win = new float[m+1]; for (int n=1; n <= m; n++) win[n] = I0(kaiserV*sqrt(1.0f - sq((float)n/m))) * I0alpha;
// filter coefficients (NB not normalised to unit maximum gain) a = new float[order+1]; a[0] = w1 / PI; for (int n=1; n <= m; n++) a[n] = sin(n*w1)*cos(n*w0)*win[n]/(n*PI); // shift impulse response to make filter causal: for (int n=m+1; n<=order; n++) a[n] = a[n - m]; for (int n=0; n<=m-1; n++) a[n] = a[order - n]; a[m] = w1 / PI; }
float[] apply(float[] ip) { float[] op = new float[ip.length]; x=new float[order]; float sum; for (int i=0; i<ip.length; i++) { x[0] = ip[i]; sum = 0.0f; for (int k=0; k<order; k++) sum += a[k]*x[k]; op[i] = sum; for(int k=order-1; k>0; k--) x[k] = x[k-1]; } return op; } }
FFTutils fft; FIRFilter filter;
float[] signal,filtered; float[] fft_result;
void setup() { size(1024,256); fft=new FFTutils(width); fft.useEqualizer(true); fft.useEnvelope(true,1); // setup new lowpass filter to cut off after 18.6kHz filter=new FIRFilter(FIRFilter.LOW_PASS,44100f,0,18600,60,3400); signal=new float[width]; }
void loop() { background(50);
// synthesize some basic sine wave as test signal for(int i=0; i<fft.WINDOW_SIZE; i++) { // mouseX as base frequency float phi=TWO_PI*mouseX*10/44100*i; // use 4 oscillators which should show up in the spectrum // watch how the highest osc. gets mirrored in the spectrum when pitch is greater than nyquist freq // use mouseY to control amplitude signal[i]=(mouseY/256f)*(0.5*sin(phi)-0.25*sin(phi*1.5)+0.12*sin(phi*2)-0.1825*sin(phi*PI)); }
// show waveform in red for(int i=0; i<signal.length; i++) { stroke(128+abs(signal[i])*128,0,0); line(i,128,i,128+signal[i]*128); }
//show filtered signal in orange (you can see the filter impact at the beginning of the buffer) stroke(255,200,0,140); for(int i=0; i<filtered.length; i++) line(i,128,i,128+filtered[i]*128);
// compute fft and show spectrum fft_result=fft.computeFFT(filtered);
// only display the real part spectrum (freq <= WINDOW_SIZE/2) for(int i=0; i<fft.WS2; i++) { stroke(255,255,0); line(i*2,255,i*2,255-fft_result[i]*256); stroke(0,255,0); line(i*2,255,i*2,255-fft._fftBuffer[i][0]);
// show bellcurve of filter window if (fft._hasEnvelope) { stroke(255); point(i*2,255-fft._envelope[i*2]*255); }
// show EQ function in cyan if (fft._isEqualized) { stroke(0,255,255); point(i*2,255-fft._equalize[i]*255); } } }
So, after finishing the csv reading and calculations etc etc, my new 'project' is to calculate FFT (frequency spectrum) of a csv file (of course it includes a series of values). Yes, I've been spending the last hours researching into it...I found a code example in java but it doesn't work so far and one in C++, which I have no idea if it works 'cus I don't have C++ installed and to be honest haven't used it since....4 years ago. Do any of you have an idea on how to calculate FFT (frequency spectrum) of data in a csv file using processing?? Let's just say, FFT of data, I'll manage the csv file thing now.
I am more than new to this processing world. At the first look it seems hard an confusing. To be honest I preffer java or python. But, I have to do this project and I need to use processing. To start with, I am trying to read data from a csv file (i.e. excel file). The csv file has just a column of numbers inside, nothing complicated. Do you have any idea how to do that? and do you know any online good tutorials on processing? Thank you!