IBM Streams 4.2

Examples

These examples demonstrate how to use the DWT operator.

The following example uses the DWT operator to detect fine grained details in a signal:

//Perform a DWT transform on a sequence of time series
stream <list<float64> sineWavelet> sineWaveletStream2 = DWT(sineStream2){
	window    
		sineStream2:
			tumbling, count(32);

	param
		inputTimeSeries: sineWave;
		order: four;
	output
		sineWaveletStream2: sineWavelet=DWTTransform();	
}         

//Retain the last 8 coefficients(details). Set the rest to nil.
stream<list<float64> cutSineWavelet> cutSineWaveletStream2=
Functor(sineWaveletStream2){
	output
		cutSineWaveletStream2:
		cutSineWavelet=concat(makeSequence(0f, 28, 0f), 
		sineWavelet[28:]);
}	

The following graph illustrates a sine wave and the glitches that are detected in the sine wave by the example code:

The following example uses the DWT operator to compress a time series:

//Use the DWT operator to approximate a waveform
//Read a noisy sine wave
stream <uint64 timestampp, float64 sineWave> sineStream=FileSource(){
	param
		file: "noisysine.csv";
		format: csv;
	}
//Use DWT on a tumbling window of size 32
stream<list<float64> sineWavelet> sineWaveletStream=DWT(sineStream){
	window
		sineStream: tumbling, count(32);
	param
		inputTimeSeries: sineWave;
		order: four;
	output
		sineWaveletStream: sineWavelet=DWTTransform();
}
//Remove the last 16 details coefficients
stream<list<float64> cutSineWavelet> filteredSineWaveletStream=Functor(sineWaveletStream){
	output
		filteredSineWaveletStream: cutSineWavelet=
		concat(sineWavelet[:8], makeSequence(0f, 24, 0f));
}
//Do the inverse DWT to get back to the time domain
stream<list<float64> smoothSine> smoothSineStream=
DWT(filteredSineWaveletStream){
	param
		inputTimeSeries: cutSineWavelet;
		order: four;
		algorithm: IDWT;
	output
		smoothSineStream: smoothSine=DWTTransform();
}

The following graph illustrates the input noisy sine wave and the output smooth sine wave: