fft - can't catch a tone frequency of 15k with microphone c# naudio -


i record sound naudio float array , after getting recorded audio want convert float array wav check it.

i wrote method i'm not sure because: try record 15khz tone of 5 seconds , pass through fft check spectrum ensure 15k catched. these steps:

  1. i generate tone matlab firstly , record audacity right tone. audacity shows nice spectrum peak in 15k -30db.

  2. i try record naudio tone , converting recorded float array wav check in audacity. unfortunately, show nothing noise 12k , no more(-80db @ 12k).

here regular recording convertion when data available:

void mywavein_dataavailable(object sender, waveineventargs e)     {         mymemorystream.write(e.buffer, 0, e.bytesrecorded);//this playing mymemorystream         (int index = 0; index < e.bytesrecorded; index += 2)//here convert in loop stream floating number samples         {              short sample = (short)((e.buffer[index + 1] << 8) |                                     e.buffer[index + 0]);             samples32.add(sample / 32768f);//ieee 32 floating number          }     } 

this code converting back:

void floatbacktostream(float[] myfloatarray)     {         short[] myshort = new short [myfloatarray.length];         mymemorystream2 = new memorystream();         (int = 0; < myfloatarray.length; i++)         {             myshort[i] = (short)(myfloatarray[i] * 32768f);             mymemorystream2.writebyte((byte)(myshort[i] & 255));             mymemorystream2.writebyte((byte)(myshort[i] >> 8));         }          mymemorystream2.position = 0;         myraw2 = new rawsourcewavestream(mymemorystream2, new waveformat(44100,1));         wavefilewriter.createwavefile("c:/users/alon/desktop/myrecordings/mycalibration.wav", myraw2);      } 

ok, so: created band-pass filter, peaks @ 15 khz. peak value +80db since said have -80db @ 12 khz. if want filter work well, needs high order transfer function. equations quite long, multiplication , addition, therefore won't take long time cpu perform. assumed sampling rate 44,1 khz. equation follows:

y[k]=a7*u[k-1]+a6*u[k-2]+a5*u[k-3]+a4*u[k-4]+a3*u[k-5]+a2*u[k-6]+a1*u[k-7]+a0*u[k-8] -b7*y[k-1]-b6*y[k-2]-b5*y[k-3]-b4*y[k-4]-b3*y[k-5]-b2*y[k-6]-b1*y[k-7]-b0*y[k-8]; 

where u measured signal , y new vector contain 15 khz frequency. there 2 approaches estimate coefficients:

  1. pulse [rad/s] = 2*pi * frequency [hz]

this proper physical equation. coeffecients:

a7=207.5;  a6=-578.1; a5=546.6; a4=-149.8; a3=-49.39; a2=22.21; a1=1.349; a0=0.006915; b7=-0.945; b6=0.3907; b5=-0.09229; b4=0.01363; b3=-0.001288; b2=0.00007605; b1=-2.567*10^(-6); b0=3.79*10^(-8); 
  1. the second way assume pulses in [hz]. don't blame me, ide programs follow inappropriate approach.

for case have following coefficients:

a7=3.301; a6=8.643; a5=-51.47; a4=59.35; a3=-5.498; a2=-23.56; a1=8.625; a0=0.6114; b7=-5.693; b6=14.18; b5=-20.19; b4=17.96; b3=-10.22; b2=3.638; b1=-0.7397; b0=0.0658; 

just try both of them , see get. make sure use datatype of sufficient precision, make sure wont multiply times 0.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -