0

I am trying to test some signal processing functions that I have written and I want to simulate real time streaming data of signed 16-bit values representing a Sine wave sampled at 960 Hz. So I imagine somewhere along the way there will be something along the lines of

short output = (short)32000*Math.Sin(2 * Math.PI * time);

where time would be some single or double precision floating point number in seconds.

Is there someway to do this with C#, a Windows PowerShell script or otherwise? And how would I capture that data? I've seen this but I don't know Perl and I'm not sure I understand.

Or am I understanding how real time data streams work wrong?

Community
  • 1
  • 1
skwear
  • 563
  • 1
  • 5
  • 24
  • If you are sampling at 960Hz you will be producing 1 sample/ms (roughly!) - the normal timers in C# typically have a resolution of around 15ms, so are unsuitable. You will probably need to use a High Resolution Timer: see http://stackoverflow.com/questions/7137121/high-resolution-timer for more info. – RB. Dec 21 '16 at 15:11
  • @RB. Does `DataTime.ToOADate()` not go down to that resolution? If a day is one unit, then 1/24/60/60/960 is on the order of 10^(-8), but the return value of `ToOADate()` is a `double` which goes down to ~15 decimal places, or am I not understanding something correctly? – skwear Dec 21 '16 at 15:18
  • Well, what do you want to test? The algorithm? The sampling? If the latter, what's the way the function obtains the data? – Peter - Reinstate Monica Dec 21 '16 at 15:19
  • @PeterA.Schneider I want to test my signal processing functions. I need a data stream of 16-bit values to feed into it. – skwear Dec 21 '16 at 15:20
  • How does the function obtain the data? – Peter - Reinstate Monica Dec 21 '16 at 16:02
  • I'm not sure. I've never done anything with streaming data before, but I imagine I would open a stream to the data. The actual signal processing function just takes a `short` value as an argument and outputs a processed value and it would be called every time the stream streams a data value. – skwear Dec 21 '16 at 16:09

0 Answers0