x=ReadDataSample(1.); // x is a pointer to object WaveDataRead data and plot power spectrum:
// created by function ReadDataSample()
Plot(x,0.,0.1);
x=ReadDataSample(100.);Extract periodic interference signal with base frequency f:
Spectrum(x);
x=ReadDataSample(5.);Get signal cleaned from periodic interference with base frequency f:
x->TuneF(60.);
float f=x->fLine; // x->fLine contains actual estimation
// of interference frequency
Plot(x,0.,1./f); // plot portion of original data in blue
x->Interference(); // *x now contains interference signal
Plot(x,0.,1./f,1,2); // overlap the plot of the one cycle of // the interference, red color
x=ReadDataSample(100.);Write object to file:
Spectrum(x,1.,0.,20000,2,4); // plot spectrum of original
// signal
Clean(x,60.);
Spectrum(x,1.,0.,20000,4,2); // plot cleaned signal spectrum
// over original
TFile f("my_object.root","new");Read object from file:
x=ReadDataSample(100.);
Clean(x,60.);
x->Write("cleaned_60"); // write cleaned data with
// key "cleaned_60"
f.Close();
WaveData wd;Note: by default ROOT uses compression for writing objects. For more information about writing/reading objects to file in ROOT see http://root.cern.ch/root/HowtoWrite.html and http://root.cern.ch/root/HowtoRead.html.
TFile f("my_object.root","read");
wd.Read("cleaned_60"); // read cleaned data using
// key "cleaned_60"
Simulate sinusoidal signal with noise:
WaveData wd(100000);Exchange data with the other programs,
wd = 0.; // set all object's data array elements to zero
wd.Rate = 10000; // set sampling rate to 10 kHz
AddSine(wd, 10., 1713.27); // add sine wave with amplitude 10 and frequency 1713.27 Hz
AddGauss(wd,1.); // add white noise with RMS=1
Spectrum(wd,1,0,2000); // how it looks?
Spectrum(wd,1,0,2000,128+4,2); // how it looks with Hann window?
wd=ReadDataSample(100.);b) fill data array from text file:
Clean(wd,60.);
wd->N // no ; at the end of string,to see how long data array is
wd->Rate // what is sampling rate?
wd->Dump("cleaned_60.txt"); // creating file containing one column of data of length
FILE *fp;Do forward and backward Wavelet transformations:
fp=fopen("cleaned_60.txt","r");
float x;
WaveData wd(986842); // you should create wd with correct
// length to acquire data from filefor (int i=0; i < wd.N; i++) {fscanf(fp, "%f", &x); wd.data[i] = x;}
wd->Rate=9868.42105263157828; // you must set correct sampling rate
fclose("cleaned_60.txt");
x=ReadDataSample(8.);Draw histogram of data stored in object:
// n - is number of samples in signal, 16384 Hz sampling rate is assumed,
// number of data samples for lifting wavelet transform always must be 2^k
int n = 8*16384;
WaveletL wl(4); // create wavelet of 3-th order
WaveData wd(n);
wl.t2w(*x,1); // one-step Wavelet decomposition of signal from *x
wl.t2w(1); // further one-step decomposition
wl.t2w(-1); // full Wavelet decomposition of signal from *x
wl.w2t(wd,-1); // full recomposition of original signal in 'wd'
// continuing previous examplePlot lifting wavelet function:
Histogram(*x); // draw histogram of original signal
wl.t2w(-1); // do full Wavelet decomposition again
WaveData layer;
wl.getLayer(layer,2); // copy 2-nd layer data to object 'layer'
Histogram(layer); // draw histogram of 2-nd layer
wl.getLayer(layer,1); // copy 1-st layer data to object 'layer'
Histogram(layer,0,1,2); // draw histogram of 1-st layer over previous plot
WaveletL wl(128*1024, 6, 0); // create wavelet of 5-th order (NP=6)Plot lifting wavelet scaling function
*(wl.pWDC) = 0.; // set all data elements to zero
wl.Level = wl.getMaxLevel(); // set level of decomposition to maximum
WaveData layer;
wl.getLayer(layer,10); // get layer 10 of detail coefficients
layer.data[63] = 1.; // set one detail coefficient to 1
wl.putLayer(layer,10); // put modified layer 10 back
WaveData wd;
wl.w2t(wd,-1);
Plot(wd);
WaveletL wl(128*1024, 6, 0); // create wavelet of 5-th order (NP=6)
*(wl.pWDC) = 0.; // set all data elements to zero
wl.Level = 10; // set current level of decomposition to 10
WaveData layer;
wl.getLayer(layer, 0); // get "approximation" level (selected by zero)
layer.data[63] = 1.; // set one element of "approximation" level to 1
wl.putLayer(layer, 0); // put layer back to array of wavelet coefficients
WaveData wd;
wl.w2t(wd,-1);
Plot(wd);
Last update : Feb 5 2001