hi,

One of my freind is asking for bpsk modulator and demodulator. It's out of my domain knowledge and i'm not sure what is it about.

Can you refer to some C language example codes of the above.

will appreciate your quick reply
thx

Dani AI

Generated

Short, practical note that builds on the thread: is right that a production-grade BPSK modem (carrier recovery, timing recovery, channel equalization, framing, error control) gets complex. For learning or a lab demo there is a very small, workable C example that shows the core idea: map bits to +1/−1, multiply a carrier (phase 0 or π), and at the receiver multiply by the same carrier and integrate over the symbol interval (coherent demodulation). The snippet below is intentionally minimal — it assumes a perfectly synchronized local carrier and ideal channel so it’s suitable for experimentation and teaching, not RF hardware use.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    const double PI=3.141592653589793;
    const int Fs=8000, fc=1000, Ns=80, Nbits=32;
    double phase_inc=2.0*PI*fc/Fs, phase=0.0;
    double *sig = malloc(sizeof(double)*Ns*Nbits);
    int bits[Nbits], dec[Nbits];
    for(int i=0;i<Nbits;i++) bits[i]=rand()&1;
    for(int i=0;i<Nbits;i++){
        double sym = bits[i]?1.0:-1.0;
        for(int n=0;n<Ns;n++){
            sig[i*Ns+n]=sym*cos(phase);
            phase+=phase_inc; if(phase>2*PI) phase-=2*PI;
        }
    }
    double local=0.0;
    for(int i=0;i<Nbits;i++){
        double acc=0;
        for(int n=0;n<Ns;n++){ acc += sig[i*Ns+n]*cos(local); local+=phase_inc; if(local>2*PI)local-=2*PI; }
        dec[i] = acc>=0;
    }
    for(int i=0;i<8;i++) printf("%d -> %d\n", bits[i], dec[i]);
    free(sig);
    return 0;
}

Notes and quick troubleshooting:

  • This demo needs a coherent carrier reference. If the local carrier phase is unknown or can flip by π, use differential BPSK (DBPSK) or implement a Costas loop for carrier recovery.
  • Pick Fs and fc so Fs/fc is convenient (integer cycles/sample) to avoid slow phase drift in tests.
  • Improve performance with a matched filter (windowed carrier), low-pass filtering, and adding AWGN tests to measure BER.
  • For real I/O, write the signal to a WAV file or feed through ADC/DAC and add timing recovery and error-control layers before considering it a usable modem.

This provides a compact starting point for while acknowledging ’s point about real-system complexity.

Recommended Answers

All 3 Replies

did you try this?

Yes, but i couldn't find much as i really have no idea what this is about. I just need a simple c code; if there is any freely available for the above.

thx

hmm... you're serious aren't you?

okay, no: there is no "simple c code" for developing a binary phase shift key modem.

if there were, then people wouldn't get paid salary to develop solutions to relatively complex engineering projects.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.