From 76869b1d3eac88cc6bdef2ef6f3a009b5c28c84d Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Fri, 23 May 2025 09:48:25 +0100 Subject: genearation of s8/u8/s16/u16/s16q11 works as expected --- Gen/GenAM.swift | 7 +++++++ Gen/GenCW.swift | 7 +++++++ Gen/GenFM.swift | 7 +++++++ Gen/GenMFSK.swift | 7 +++++++ Gen/GenTrig.swift | 31 +++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 Gen/GenAM.swift create mode 100644 Gen/GenCW.swift create mode 100644 Gen/GenFM.swift create mode 100644 Gen/GenMFSK.swift (limited to 'Gen') 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> { + + //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] = Array(repeating: Complex(Float(0.0)), count: sample_num) + var start = phase + for i in 0.. Array> { + //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] = Array(repeating: Complex(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 +} -- cgit v1.2.3