diff options
Diffstat (limited to 'Gen')
-rw-r--r-- | Gen/GenAM.swift | 7 | ||||
-rw-r--r-- | Gen/GenCW.swift | 7 | ||||
-rw-r--r-- | Gen/GenFM.swift | 7 | ||||
-rw-r--r-- | Gen/GenMFSK.swift | 7 | ||||
-rw-r--r-- | Gen/GenTrig.swift | 31 |
5 files changed, 59 insertions, 0 deletions
diff --git a/Gen/GenAM.swift b/Gen/GenAM.swift new file mode 100644 index 0000000..b194c83 --- /dev/null +++ b/Gen/GenAM.swift @@ -0,0 +1,7 @@ +// +// GenAM.swift +// PrySDR +// +// Created by Jacky Jack on 22/05/2025. +// + diff --git a/Gen/GenCW.swift b/Gen/GenCW.swift new file mode 100644 index 0000000..7699f9a --- /dev/null +++ b/Gen/GenCW.swift @@ -0,0 +1,7 @@ +// +// GenCW.swift +// PrySDR +// +// Created by Jacky Jack on 22/05/2025. +// + diff --git a/Gen/GenFM.swift b/Gen/GenFM.swift new file mode 100644 index 0000000..6d8268e --- /dev/null +++ b/Gen/GenFM.swift @@ -0,0 +1,7 @@ +// +// GenFM.swift +// PrySDR +// +// Created by Jacky Jack on 22/05/2025. +// + diff --git a/Gen/GenMFSK.swift b/Gen/GenMFSK.swift new file mode 100644 index 0000000..8b99c81 --- /dev/null +++ b/Gen/GenMFSK.swift @@ -0,0 +1,7 @@ +// +// GenMFSK.swift +// PrySDR +// +// Created by Jacky Jack on 22/05/2025. +// + diff --git a/Gen/GenTrig.swift b/Gen/GenTrig.swift index cc4abb5..fa0cd57 100644 --- a/Gen/GenTrig.swift +++ b/Gen/GenTrig.swift @@ -6,6 +6,7 @@ // import Foundation +import ComplexModule /// Generate sin function as float array /// - Parameters: @@ -31,6 +32,22 @@ func genSin(_ sample_rate: Int,_ freq: Int,_ ampl: Float,_ phase: Float,_ sample return out_signal } +func genSin(_ sample_rate: Int,_ freq: Int,_ ampl: Float,_ phase: Float,_ sample_num: Int) -> Array<Complex<Float32>> { + + //let one_sec = sample_num/sample_rate + let sample_per_hz:Float32 = Float32(sample_rate)/Float32(freq) + let hz_step: Float32 = 2*Float32.pi/sample_per_hz + var out_signal:[Complex<Float32>] = Array(repeating: Complex<Float32>(Float(0.0)), count: sample_num) + var start = phase + for i in 0..<sample_num { + out_signal[i].real = ampl * sin(start) + out_signal[i].imaginary = 0.0 + start += hz_step + } + + return out_signal +} + /// Generate Cos function as float array /// - Parameters: /// - sample_rate: sample rate, how many samples per second @@ -54,3 +71,17 @@ func genCos(_ sample_rate: Int,_ freq: Float,_ ampl: Float,_ phase: Float,_ samp return out_signal } +func genCos(_ sample_rate: Int,_ freq: Float,_ ampl: Float,_ phase: Float,_ sample_num: Int) -> Array<Complex<Float32>> { + //let one_sec = sample_num/sample_rate + let sample_per_hz:Float32 = Float32(sample_rate)/Float32(freq) + let hz_step: Float32 = 2*Float32.pi/sample_per_hz + var out_signal:[Complex<Float32>] = Array(repeating: Complex<Float32>(Float32(0.0)), count: sample_num) + var start = phase + for i in 0...sample_num { + out_signal[i].real = ampl * cos(start) + out_signal[i].imaginary = 0.0 + start += hz_step + } + + return out_signal +} |