diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-01-06 12:30:49 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-01-06 12:30:49 +0000 |
commit | a0d12ecbac8fe327d1dcd4580fee594e24d4191b (patch) | |
tree | 9a7cef9ed0de080bb8c19912f678497a4fca6a86 /Radio/Utils/WaterfallFile/NaiveFFT512.swift | |
parent | f923a3824561c6cf200c638e3d44d1cbf4adf7d8 (diff) | |
download | PrySDR-main.tar.gz PrySDR-main.zip |
Waterfall: UI drawing from filemain
Diffstat (limited to 'Radio/Utils/WaterfallFile/NaiveFFT512.swift')
-rw-r--r-- | Radio/Utils/WaterfallFile/NaiveFFT512.swift | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Radio/Utils/WaterfallFile/NaiveFFT512.swift b/Radio/Utils/WaterfallFile/NaiveFFT512.swift new file mode 100644 index 0000000..b4dca7e --- /dev/null +++ b/Radio/Utils/WaterfallFile/NaiveFFT512.swift @@ -0,0 +1,49 @@ +// +// NaiveFFT.swift +// PrySDR +// +// Created by Jacky Jack on 05/01/2025. +// + +import Foundation +import Accelerate + +//SUpports now only fixed sizes and not flexible implementation just a PoC +class NaiveFFT512 { + + static let sampleCount = 512 + let forwardDCT = vDSP.DCT(count: sampleCount, transformType: .II)! + + init() { + + } + + func getSampleCount() -> Int { + return NaiveFFT512.sampleCount + } + + func computeLine(_ processingArray: [Int8]) -> [Float] { + + var dataFloat = [Float](repeating: 0.0, count: NaiveFFT512.sampleCount) + + if processingArray.count != NaiveFFT512.sampleCount { + print("Not supporting arrays not equail to \(NaiveFFT512.sampleCount)") + return [] + } + + vDSP.convertElements(of: processingArray, to: &dataFloat) + //dataFloat = vDSP.add(127.0, dataFloat) + //print(dataFloat) + + //move from -127.0 to 128.0 range -1.0...1.0 + //var adjusted = vDSP.divide(dataFloat, Float(sampleCount)) + var adjusted = dataFloat + //print(adjusted) + + var transform_result = forwardDCT.transform(adjusted) + transform_result = vDSP.absolute(transform_result) + + return transform_result + } + +} |