16 lines
		
	
	
		
			384 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			16 lines
		
	
	
		
			384 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 
								 | 
							
								var FFT = numerics.fft;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								var signal = [1,0,1,0];
							 | 
						||
| 
								 | 
							
								var phasors = FFT.fft(signal);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								log(phasors);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								var frequencies = FFT.fftFreq(phasors, 8000), // Sample rate and coef is just used for length, and frequency step
							 | 
						||
| 
								 | 
							
								     magnitudes = FFT.fftMag(phasors); 
							 | 
						||
| 
								 | 
							
								var both = frequencies.map(function (f, ix) {
							 | 
						||
| 
								 | 
							
								        return {frequency: f, magnitude: magnitudes[ix]};
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								log(inspect(both));
							 | 
						||
| 
								 | 
							
								
							 |