Code Monkey home page Code Monkey logo

qpsk-mod-demod-libs's Introduction

QPSK-mod-demod-libs

C-libraries for QPSK modulation and demodulation

  include
 butterworth_filter.hButterworth Filter implementation for filtering continues signal Original code from: https://github.com/filoe/cscore
 bytes_symbols_converter.hMethods to convert array of bytes to symbols and back
 pll.hNumerically-controlled Phase locked loop
 qpsk_demodulator.hQPSK demodulator (decoder)
 qpsk_modulator.hQPSK modulator (encoder)
 rrc_filter.hRoot raised cosine (RRC) filter implementation by Fern Lane for filtering continues signal
  src
 butterworth_filter.cButterworth Filter implementation for filtering continues signal Original code from: https://github.com/filoe/cscore
 bytes_symbols_converter.cMethods to convert array of bytes to symbols and back
 pll.cNumerically-controlled Phase locked loop
 qpsk_demodulator.cQPSK demodulator (decoder)
 qpsk_modulator.cQPSK modulator (encoder)
 rrc_filter.cRoot raised cosine (RRC) filter implementation by Fern Lane for filtering continues signal

Generated by doxygen 1.9.8

qpsk_modulator.c File Reference

Functions

qpsk_modulator_sqpsk_modulator_init (float sample_rate, float carrier_frequency, float bandwidth, uint16_t halfcycles_per_symbol, float amplitude_peak)
 Initializes QPSK demodulator.
 
uint32_t qpsk_modulator_calculate_samples_chunk_length (qpsk_modulator_s *qpsk_modulator, uint32_t symbols_chunk_length)
 Calculates the size of the array of sample after modulation.
 
void qpsk_modulator_modulate_chunk (qpsk_modulator_s *qpsk_modulator, uint8_t *symbols_chunk, uint32_t symbols_chunk_length, float *samples_chunk, uint8_t debug_messages)
 Modulates chunk of symbols.
 
void qpsk_modulator_reset (qpsk_modulator_s *qpsk_modulator)
 Resets QPSK modulator to the initial state.
 
void qpsk_modulator_destroy (qpsk_modulator_s *qpsk_modulator)
 Frees all memory allocated by QPSK modulator.
 

Detailed Description

QPSK modulator (encoder)

Author
Fern Lane
Version
1.0.0
Date
2023-09-26
Copyright
Copyright (c) 2023

Copyright (C) 2023 Fern Lane, QPSK modulator / demodulator libraries Licensed under the GNU Affero General Public License, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.en.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file qpsk_modulator.c.

Function Documentation

◆ qpsk_modulator_calculate_samples_chunk_length()

uint32_t qpsk_modulator_calculate_samples_chunk_length ( qpsk_modulator_s qpsk_modulator,
uint32_t  symbols_chunk_length 
)

Calculates the size of the array of sample after modulation.

Parameters
qpsk_modulatorQPSK modulator's struct
symbols_chunk_lengthnumber of symbols
Returns
uint32_t number of samples

Definition at line 104 of file qpsk_modulator.c.

◆ qpsk_modulator_destroy()

void qpsk_modulator_destroy ( qpsk_modulator_s qpsk_modulator)

Frees all memory allocated by QPSK modulator.

Parameters
qpsk_modulatorQPSK modulator's struct

Definition at line 252 of file qpsk_modulator.c.

◆ qpsk_modulator_init()

qpsk_modulator_s * qpsk_modulator_init ( float  sample_rate,
float  carrier_frequency,
float  bandwidth,
uint16_t  halfcycles_per_symbol,
float  amplitude_peak 
)

Initializes QPSK demodulator.

Parameters
sample_rateSampling rate (in Hz)
carrier_frequencyCarrier frequency (in Hz)
bandwidthOutput signal required bandwidth (in Hz)
halfcycles_per_symbolRate of symbols in carrier halfcycles (2 halfcycles = 1 full carrier wave cycle)
amplitude_peakAmplitude of modulated signal (peak value)
Returns
qpsk_modulator_s* QPSK modulator's struct

Definition at line 44 of file qpsk_modulator.c.

◆ qpsk_modulator_modulate_chunk()

void qpsk_modulator_modulate_chunk ( qpsk_modulator_s qpsk_modulator,
uint8_t *  symbols_chunk,
uint32_t  symbols_chunk_length,
float *  samples_chunk,
uint8_t  debug_messages 
)

Modulates chunk of symbols.

Parameters
qpsk_modulatorQPSK modulator's struct
symbols_chunkArray of symbols
symbols_chunk_lengthLength of array of symbols
samples_chunkAllocated array of samples (size must be qpsk_modulator_calculate_samples_chunk_length * sizeof(float))
debug_messagesEnable printf() debug messages (greatly affects performance)

Definition at line 120 of file qpsk_modulator.c.

◆ qpsk_modulator_reset()

void qpsk_modulator_reset ( qpsk_modulator_s qpsk_modulator)

Resets QPSK modulator to the initial state.

Parameters
qpsk_modulator

Definition at line 232 of file qpsk_modulator.c.


Generated by doxygen 1.9.8

qpsk_demodulator.c File Reference

Functions

float clampf (float value, float min, float max)
 Clamps float value to a range.
 
qpsk_demodulator_sqpsk_demodulator_init (float sample_rate, float lo_frequency, float bandwidth, uint16_t halfcycles_per_symbol, float carrier_start_threshold, float carrier_lost_threshold, float pll_lock_threshold, float pll_lock_time)
 Initializes QPSK demodulator.
 
void qpsk_demodulator_demodulate_chunk (qpsk_demodulator_s *qpsk_demodulator, float *samples_chunk, uint32_t samples_chunk_size, uint8_t *symbols_chunk, uint8_t debug_messages)
 Demodulates one chunk of samples into symbols.
 
void qpsk_demodulator_reset (qpsk_demodulator_s *qpsk_demodulator)
 Resets QPSK demodulator to the initial state.
 
void qpsk_demodulator_destroy (qpsk_demodulator_s *qpsk_demodulator)
 Frees all memory allocated by QPSK demodulator.
 

Detailed Description

QPSK demodulator (decoder)

Author
Fern Lane
Version
1.0.0
Date
2023-09-26
Copyright
Copyright (c) 2023

Copyright (C) 2023 Fern Lane, QPSK modulator / demodulator libraries Licensed under the GNU Affero General Public License, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.en.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file qpsk_demodulator.c.

Function Documentation

◆ clampf()

float clampf ( float  value,
float  min,
float  max 
)

Clamps float value to a range.

Parameters
valueValue to clamp
minRange minimum value
maxRange maximum value
Returns
float Clamped value

Definition at line 42 of file qpsk_demodulator.c.

◆ qpsk_demodulator_demodulate_chunk()

void qpsk_demodulator_demodulate_chunk ( qpsk_demodulator_s qpsk_demodulator,
float *  samples_chunk,
uint32_t  samples_chunk_size,
uint8_t *  symbols_chunk,
uint8_t  debug_messages 
)

Demodulates one chunk of samples into symbols.

Parameters
qpsk_demodulatorQPSK demodulator's struct
samples_chunkAarray of samples
samples_chunk_sizeLength of array of symbols
symbols_chunkAllocated array of symbols (size equal to samples_chunk_size) 0xFF - no symbol decoded at current sample, 0b00, 0b01, 0b10, 0b11 - decoded symbols at specific samples
debug_messagesEnable printf() debug messages (greatly affects performance)

Definition at line 153 of file qpsk_demodulator.c.

◆ qpsk_demodulator_destroy()

void qpsk_demodulator_destroy ( qpsk_demodulator_s qpsk_demodulator)

Frees all memory allocated by QPSK demodulator.

Parameters
qpsk_demodulatorQPSK demodulator's struct

Definition at line 481 of file qpsk_demodulator.c.

◆ qpsk_demodulator_init()

qpsk_demodulator_s * qpsk_demodulator_init ( float  sample_rate,
float  lo_frequency,
float  bandwidth,
uint16_t  halfcycles_per_symbol,
float  carrier_start_threshold,
float  carrier_lost_threshold,
float  pll_lock_threshold,
float  pll_lock_time 
)

Initializes QPSK demodulator.

Parameters
sample_rateSampling rate (in Hz)
lo_frequencyCarrier frequency (local oscillator) (in Hz)
bandwidthInput signal bandwidth (in Hz)
halfcycles_per_symbolRate of symbols in carrier halfcycles (2 halfcycles = 1 full carrier wave cycle)
carrier_start_thresholdSignal must be above this threshold to start PLL locking and demodulating (in dBFS RMS)
carrier_lost_thresholdSignal must be below this threshold to stop PLL locking and demodulating (in dBFS RMS)
pll_lock_thresholdPLL's input (IQ error) should't change during pll_lock_time more than this value
pll_lock_timePLL's input (IQ error) should't change during this time (in seconds) more than pll_lock_threshold
Returns
qpsk_demodulator_s* QPSK demodulator's struct

Definition at line 61 of file qpsk_demodulator.c.

◆ qpsk_demodulator_reset()

void qpsk_demodulator_reset ( qpsk_demodulator_s qpsk_demodulator)

Resets QPSK demodulator to the initial state.

Parameters
qpsk_demodulatorQPSK demodulator's struct

Definition at line 449 of file qpsk_demodulator.c.


Generated by doxygen 1.9.8

qpsk-mod-demod-libs's People

Contributors

f33rni avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

qpsk-mod-demod-libs's Issues

A failed attempt to build a case of QPSK modulation and demodulation case

I tried to use these functions to build a QPSK modulation and demodulation case, but the demodulation results and the input data are very different, the main program is as follows, I think it is the function parameter setting problem, hope the author can point out the error or provide a correct QPSK modulation and demodulation case, thank you very much!

`#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include "butterworth_filter.h"
#include "rrc_filter.h"
#include "qpsk_modulator.h"
#include "bytes_symbols_converter.h"
#include "file_reader.h"
#include "qpsk_demodulator.h"
#include "pll.h"
#include "butterworth_filter.h"

int main() {

read_file();
uint32_t bytes_length = file_len;
uint32_t start_silence_length = 10;
uint32_t preamble_length = 10;
uint8_t add_iq_sync_byte = 1;
uint32_t end_silence_length = 10;

uint8_t* symbols = bytes_to_symbols(file_buf, bytes_length, start_silence_length, preamble_length, add_iq_sync_byte, end_silence_length);

uint32_t symbols_length = bytes_to_symbols_calculate_length(bytes_length, start_silence_length, preamble_length, add_iq_sync_byte, end_silence_length);

//初始化QPSK调制器
qpsk_modulator_s* qpsk_modulator = qpsk_modulator_init(10000,5000,2000,2,100.0);

// 计算所需的样本数
uint32_t samples_length = qpsk_modulator_calculate_samples_chunk_length(qpsk_modulator, symbols_length);

// 为 IQ 样本序列分配内存
float* samples_chunk = malloc(samples_length * sizeof(float));

// 调制符号
qpsk_modulator_modulate_chunk(qpsk_modulator, symbols, symbols_length, samples_chunk, 1);

// 初始化 QPSK 解调器
uint8_t* symbols_demodulate = malloc(samples_length * sizeof(uint8_t));

qpsk_demodulator_s* qpsk_demodulator = qpsk_demodulator_init(10000, 5000, 2000, 2, -1, 1, 1e4, 1e-6);

qpsk_demodulator_demodulate_chunk(qpsk_demodulator, samples_chunk, samples_length, symbols_demodulate, 1);

uint8_t* symbols_demodulate2 = malloc(symbols_length * sizeof(uint8_t));

symbols_demodulate2 = symbols_remove_empty(symbols_demodulate2, symbols_length);

symbols_demodulate2 = symbols_to_bytes(symbols_demodulate, symbols_length);

return 0;

}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.