diff --git a/Sources/Butterworth/WaveletsWrapper.mm b/Sources/Butterworth/WaveletsWrapper.mm index cffb755..dba98ca 100644 --- a/Sources/Butterworth/WaveletsWrapper.mm +++ b/Sources/Butterworth/WaveletsWrapper.mm @@ -1,6 +1,6 @@ // // WaveletsWrapper.cpp -// +// // // Created by Nikita Charushnikov on 01.08.23. // @@ -11,7 +11,7 @@ @implementation WaveletsWrapper -- (NSMutableArray *)stationaryWaveletTransformation: (double[]) signal :(int) signalSize :(NSString *) wavelet :(int) level { +- (void)stationaryWaveletTransformation: (double[]) signal :(double[]) result :(int) signalSize :(NSString *) wavelet :(int) level { wave_object wave_obj; wt_object wavelet_obj; @@ -26,17 +26,15 @@ @implementation WaveletsWrapper swt(wavelet_obj, signal); - NSMutableArray *waveletsOutput = [NSMutableArray array]; - for (int i = 0; i < wavelet_obj->outlength; ++i) { const double output = wavelet_obj->output[i]; - [waveletsOutput addObject:[NSNumber numberWithDouble:output]]; + result[i] = output; } wave_free(wave_obj); wt_free(wavelet_obj); - return waveletsOutput; } @end + diff --git a/Sources/Butterworth/include/WaveletsWrapper.h b/Sources/Butterworth/include/WaveletsWrapper.h index 6f31133..3db9627 100644 --- a/Sources/Butterworth/include/WaveletsWrapper.h +++ b/Sources/Butterworth/include/WaveletsWrapper.h @@ -11,6 +11,6 @@ @interface WaveletsWrapper : NSObject -- (NSMutableArray *)stationaryWaveletTransformation: (double[]) signal :(int) signalSize :(NSString *) wavelet :(int) level; +- (void)stationaryWaveletTransformation: (double[]) signal :(double[]) result :(int) signalSize :(NSString *) wavelet :(int) level; @end diff --git a/Sources/PeakSwift/Utils/Helper/Wavelets/StationaryWaveletTransformation.swift b/Sources/PeakSwift/Utils/Helper/Wavelets/StationaryWaveletTransformation.swift index 8d10add..db5432f 100644 --- a/Sources/PeakSwift/Utils/Helper/Wavelets/StationaryWaveletTransformation.swift +++ b/Sources/PeakSwift/Utils/Helper/Wavelets/StationaryWaveletTransformation.swift @@ -28,12 +28,14 @@ class StationaryWaveletTransformation { fatalError("For applying stationary wavelets transformation: signal.size% 2^^level == 0") } - var inputSignal = [Double](signal) + let outputWaveletTransformationSize = signalSize * (level + 1) - let outputWaveletTransformationRaw = waveletsWrapper.stationaryWaveletTransformation(&inputSignal, Int32(signalSize), wavelet.rawValue, Int32(level)) + var inputSignal = [Double](signal) + var outputWaveletTransformation = [Double].init(repeating: 0.0, count: outputWaveletTransformationSize) - let outputWaveletTransformation = outputWaveletTransformationRaw as! [Double] + waveletsWrapper.stationaryWaveletTransformation(&inputSignal, &outputWaveletTransformation, Int32(signalSize), wavelet.rawValue, Int32(level)) + return extractCoefficients(waveletOutput: outputWaveletTransformation, level: level) }