08-07-2016 05:29 PM
Hello,
I am not familiar with C# but I need to build a waveform of array of samples with known sample interval (dt) and start date/time (t0).I have managed to plot the array eith the PlotY method. I even managed to initializa a waveform of the samples but am not able to comprehend how to put dt and t0 in the wavefot. The classes are too much of a complication to me.
Following works so far but with not proper timing:
--------------------
AnalogWaveform<double> waveform = new AnalogWaveform<double>(0);
waveform.Append(AnalogWaveform<double>.FromArray1D(probna));
waveform.Timing = WaveformTiming.CreateWithRegularInterval(TimeSpan.FromSeconds(10));
graph1.PlotWaveform<double>(waveform, new AnalogWaveformPlotOptions(AnalogWaveformPlotDisplayMode.Time, AnalogWaveformPlotScaleMode.Raw));
--------------------
SInce there a re (surprisingly) no examples in the MeasurementStudio help, I would appreciate if somebody can write the code lines for building a waveform with proper timing of the samples array and plotting it.
Thanks in advance,
08-08-2016 10:24 AM
You were very close with your current approach. What you want to do is use the overload to WaveformTiming.CreateWithRegularInterval
that takes both an interval and a time stamp:
DateTime timeStamp = ...;
waveform.Timing = WaveformTiming.CreateWithRegularInterval( TimeSpan.FromSeconds( 10 ), timeStamp );
(Also, if you are only creating one waveform, you do not need to use both FromArray1D
and Append
.)
08-09-2016 05:27 AM
Hello Phansen,
Thank you for the prompt response. I still cannot solve this, there are no examples at all?! Anyway, this is the context of my trouble - I have an array "signal[int]", I know the "dt" sampling interval and I know the "t0" starting DateTime. In LabVIEW I would just bundle the three and I would build the waveform. As I already said, I can plot the signal[], but am unable to bundle the waveform.
Can you please write the bundling code for dt = 10ms and a t0 = 10 Aug 2016 + 1300h?
I just need to perform a FFT to it and plot on different graphs the waveform and the spectrum. (I'd appreciate the FFT part also).
Thanks in advance,
08-09-2016 10:24 AM
I believe our examples assume users will be reading waveform data from a device, rather than constructing it themselves. The best example I could for the Windows Forms graph was UI\WindowsForms\Graph\PlotWaveforms
in the Measurement Studio installed Examples directory, which uses regular timing with a time stamp for the chart/append case.
For the specific values you mentioned (dt = 10ms and t₀ = 10 Aug 2016 + 1300h) and your earlier sample code, this is what you would do to create a waveform with the appropriate timing:
double[] probna = ...
TimeSpan interval = TimeSpan.FromMilliseconds( 10 );
DateTime timeStamp = new DateTime( year: 2016, month: 08, day: 10, hour: 13, minute: 0, second: 0 );
var waveform = AnalogWaveform<double>.FromArray1D( probna );
waveform.Timing = WaveformTiming.CreateWithRegularInterval( interval, timeStamp );
08-09-2016 03:16 PM
Phansen,
Thanks again, graph works with date/time on x axis 🙂 Now I have an issue with the FFT. I am trying to locate the (LV has it) method "FFT Magnitude and Phase" but I see only "ComplexDouble FFT Re & Im" method in the "Transforms" class.
I have no problem to calculate magnitude from real and imaginary parts but what would be the X-axis unit df? Is it 1/dt? Is there a way to pass a waveform to get FFTed instead of the "raw" array of samples without notion of time (dt)? In LV waveform carries dt so FFT knows what is df... Documentation is really lacking examplary details.
Thanks again,
08-09-2016 03:43 PM
Glad to hear the graph is working now!
I'm afraid I am not familiar with our analysis methods. To make sure your new question is visible to others, I suggest you copy it to a new forum post.
08-09-2016 03:51 PM
Thank you Phanesen,
I will.