Sie sind auf Seite 1von 9

#include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef #define #endif #ifndef #define #endif min min( a, b ) (a<b?

a:b) max max( a, b ) (a>b?a:b)

void print_int_array_values( int array_of_ints[], const int array_size ) { int i = 0; for( i = 0; i < array_size; i++ ) { printf( "%3d ", array_of_ints[i] ); } printf( "\n" ); } void sort( int array_of_ints[], const int array_size ) { int i = 0; int j = 0; int increment = 3; int temp = 0; while( increment > 0 ) { for( i = 0; i < array_size; i++ ) { j = i; temp = array_of_ints[i]; while( (j >= increment) && (array_of_ints[j - increment] > temp) ) { array_of_ints[j] = array_of_ints[j - increment]; j = j - increment; } array_of_ints[j] = temp; } if( increment/2 != 0 ) { increment = (increment/2); } else if( increment == 1 ) { increment = 0; } else { increment = 1; } } } int minimum( const int array_of_ints[], const int array_size ) { int i = array_size; int temp = array_of_ints[0]; if( i > 0 )

{ do { temp = min( temp, array_of_ints[-1 + i] ); } while( (--i) > 0 ); } else { printf( "usage error: parameter array_size must be greater than zero!\n" ); } return temp; } int maximum( const int array_of_ints[], const int array_size ) { int i = array_size; int temp = array_of_ints[0]; if( i > 0 ) { do { temp = max( temp, array_of_ints[-1 + i] ); } while( (--i) > 0 ); } else { printf( "usage error: parameter array_size must be greater than zero!\n" ); } return temp; } int median( const int array_of_ints[], const int array_size, int print_arrays ) { int i = array_size; int* pInts = 0; int temp = 0; if( i > 0 ) { pInts = malloc( i * sizeof( int ) ); if( pInts ) { memcpy( pInts, &array_of_ints[0], (i * sizeof( int )) ); if( print_arrays != 0 ) { printf( "unsorted: " ); print_int_array_values( pInts, i ); } sort( pInts, i ); if( print_arrays != 0 ) { printf( "sorted: " ); print_int_array_values( pInts, i ); } temp = pInts[((int)i/2)]; } } else

{ printf( "usage error: parameter array_size must be greater than zero!\n" ); } return temp; } int main() { int array_of_ints[] = { 7, 4, 19, -3, 24, 17, 35, 56, 908, -17, 31, 0, 11, 91 }; int minInt = minimum( array_of_ints, (sizeof( array_of_ints )/sizeof( int )) ); int maxInt = maximum( array_of_ints, (sizeof( array_of_ints )/sizeof( int )) ); int medInt = median( array_of_ints, (sizeof( array_of_ints )/sizeof( int )), 1 ); printf( "minimum = %d\n", minInt ); printf( "maximum = %d\n", maxInt ); printf( "median = %d\n", medInt ); return 0; } // output: unsorted: sorted: minimum = maximum = median = 7 -17 -17 908 19 4 -3 19 0 -3 4 24 7 17 11 35 17 56 908 -17 19 24 31 31 35 0 56 11 91 91 908

/** Test program for Fourier transform of sine * functions. */ import uk.ac.ed.ph.signal.*; // Signal classes public class SineSignal { public static void main(String args[]) { // Make a RealSignal of 2048 RealSignal s = new RealSignal(2048); s.setSampleInterval(0.1); //

// Set sample interval

Make second RealSignal with same interval

RealSignal t = s.clone(); // Fill s with sine wave of amp 10 and 0.5 Hz and // DC offset of 12 // t with sine wave of amp 2 and 0.8 Hz s.fillSine(10.0, 0.5, 0.0, 12.0); t.fillSine( 2.0, 0.8, 0.0, 0.0); s.add(t); s.toTextFile("s.data"); // Add t to s // Output s to text file

// Make ComplexSignal with s as the real part ComplexSignal z = new ComplexSignal(s); z.weight(new Hanning()); // Apply Hanning window to stop // Ailiasing z.centreFourier(); // // Take centred FFT

Get the modulus as a RealSignal

RealSignal m = z.getRealSignal(); m.toTextFile("m.data"); } } // Output m to file

Read image

/** Simple demo program real file in a RealImage and display it * in a popup windows * Demo for dia course. * @auther Will Hossack, */ import uk.ac.ed.ph.signal.*; // Signal classes public class ImageDisplay { public static void main(String args[]) { // Check that argument was given. if (args.length == 0) { System.err.println("Usage: java ImageDisplay filename"); System.exit(1); } String file = args[0]; // Read image (type depermined by suffix) RealImage im = RealImage.readImage(file); System.out.println("Read image is : " + im); // Create a display panel ImageFrame display = new ImageFrame("My Image"); display.setVisible(true); display.addImage(im); // Add image with (with autscale defaults) display.centre(); // Display in centre of screen } }

Das könnte Ihnen auch gefallen