apparantly this is better

This commit is contained in:
KubaPro010 2025-05-24 18:11:29 +02:00
parent f385d28ac1
commit f13e0bda40
1 changed files with 4 additions and 9 deletions

View File

@ -29,9 +29,9 @@ private:
public: public:
LoRaModulator(LoRaConfig cfg, int sr) : config(cfg), sample_rate(sr) { LoRaModulator(LoRaConfig cfg, int sr) : config(cfg), sample_rate(sr) {
symbols_per_second = config.bandwidth / (1 << config.spreading_factor); symbols_per_second = static_cast<float>(config.bandwidth) / (1 << config.spreading_factor);
symbol_time = (1 << config.spreading_factor) / config.bandwidth; symbol_time = 1.0f / symbols_per_second;
samples_per_symbol = sample_rate * symbol_time; samples_per_symbol = static_cast<int>(sample_rate * symbol_time);
} }
// Convert binary string to symbols // Convert binary string to symbols
@ -90,12 +90,7 @@ public:
freq_offset += (symbol_value * config.bandwidth) / (1 << config.spreading_factor); freq_offset += (symbol_value * config.bandwidth) / (1 << config.spreading_factor);
// Wrap frequency if it exceeds bandwidth // Wrap frequency if it exceeds bandwidth
while(freq_offset > bandwidth_half) { freq_offset = fmod(freq_offset + bandwidth_half, config.bandwidth) - bandwidth_half;
freq_offset -= config.bandwidth;
}
while(freq_offset < -bandwidth_half) {
freq_offset += config.bandwidth;
}
} else { } else {
// Downchirp: frequency decreases linearly // Downchirp: frequency decreases linearly
float progress = (float)i / num_samples; float progress = (float)i / num_samples;