Hi,
I've converted the C++ sample filter application from the National
Instruments Measurement Studio for Visual VC++ into Delphi 5. The NI
functions in the DLL of the Active X library are all called with
OleVariant.
Could I get some feedback on how the code is written. The sample
creates an array of 1000 elements and fills it with random Gausian Noise
and then high pass filters it with a 3rd order Butterworth filter.
It then creates a sine wave and adds the noise to that. Filters it with
a band pass filter and finally displays the results.
Given what Delphi created for the ActiveX controls as far as I can see
there is no other way to do all this. Or is there another way?
Thanks
John Dammeyer.
procedure TForm1.OnGenerateDataClick(Sender: TObject);
var
NoiseAmp : OleVariant; //Noise
amplitude
SineAmp : Olevariant; //Sine's
amplitude
Cycles : OleVariant; //Sine's Cycles
phase : Olevariant; //Sine's phase
fs : double;
FreqLowCut : double; //24 Hz cutoff on the
lowpass filter
FreqHighCut : double; //150 Hz cutoff on the
hipass filter
vNoise : array of Variant;
vFNoise : array of Variant;
vData : array of Variant;
vFilter : array of Variant;
i, j : integer; // Loop Counters
begin
vNoise := VarArrayCreate([0, 1000], varVariant); //Noise
Data
vFNoise := VarArrayCreate([0, 1000], varVariant);
//Filtered Noise Data
vData := VarArrayCreate([0, 1000], varVariant); //Raw Data
vFilter := VarArrayCreate([0, 1000], varVariant);
//Filtered Data
NoiseAmp := 1.0; //Noise amplitude
SineAmp := 1.0; //Sine's amplitude
Cycles := 5.0; //Sine's Cycles
phase := 0.0; //Sine's phase
fs := 1000; //sample 1000
points
FreqLowCut := 24; //24 Hz cutoff on the
lowpass filter
FreqHighCut := 150; //150 Hz cutoff on the
hipass filter
// Generate noise
// function TCWDSP.WhiteNoise(n: OleVariant; Amp: OleVariant;
Seed: OleVariant): OleVariant;
vNoise := CWDSP1.WhiteNoise(fs, NoiseAmp, -1.0);
// put the noise through a high pass filter to remove the low
frequency components
// function TCWDSP.BwHPF(x: OleVariant; fs: OleVariant; fc:
OleVariant; Order: OleVariant): OleVariant;
vFNoise := CWDSP1.BwHPF(vNoise, fs, FreqHighCut, 3);
// generate the sine wave
// function TCWDSP.SineWave(n: OleVariant; Amp: OleVariant; f:
OleVariant; var Phase: OleVariant): OleVariant;
vData := CWDSP1.SineWave(fs, SineAmp, (Cycles/
VarArrayHighBound(vData,1)) ,phase);
// Add noise to sine wave to get raw data
j := round(fs - 1);
for i := 0 to j do
vData[i] := double(vData[i]) + double(vFNoise[i]);
// put the resulting waveform (noise + sine) through a low-pass
filter
vFilter := CWDSP1.BwLPF(vData, fs, FreqLowCut, 3);
// Plot the noisey sine wave and the filtered sine wave
// procedure TCWGraph.PlotY(YData: OleVariant);
m_GraphData.PlotY(vData);
m_GraphFilter.PlotY(vFilter);
end;
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi