Shop OBEX P1 Docs P2 Docs Learn Events
Signalprocessing with fastspin (C) and P2 — Parallax Forums

Signalprocessing with fastspin (C) and P2


hello forum
I am currently working on a library for digital signal processing on the P2. I just implemented a Hilbert transformation. You always need it when you have a real signal (I) and use it to generate component (Q) to get a so-called IQ signal.
It is also possible with a filter, but the phase shift is exactly 90 degrees only at a certain frequency with little effort. That's why I use the Cordic unit, do a Fourier transform on the real signal, move in Hilbert space and do an inverse transformation of it.
The FT is easy, a real number must be multiplied by the rotation factors. At IFT you have to do a bit of trickery.
The existing structures of propeller2.h could have been used for the implementation. No big difference.
In the appendix the input signal x and the output y.
642 x 572 - 28K
642 x 572 - 28K
c
c
667B
h
h
409B

Comments

  • ReinhardReinhard Posts: 489
    edited 2020-06-23 18:10
    errata:
    LINE 93 in complex_test.c must change
    from
    y[k] += a * c + b * d; // this give x = cos y = sin
    to
    y[k] += a * c - b * d;// x = cos y = -sin this is math. correct

    I make the multiplication of 2 complex numbers on notice paper
    (a + ib) * (c + id) =
    ac + iad +ibc - bd =
    ac - bd + i(ad +bc)
    we use the real part ac - bd

    I do it right on paper and make a tipo in coding, what give sin instead -sin.
  • K2K2 Posts: 691
    What's needed here is the opportunity to upvote!

    DPSK demodulation is exactly what I want to do with the P2 when the present project is finis.
  • ReinhardReinhard Posts: 489
    edited 2020-06-23 19:58
    @K2
    the hilbert transformator in current state is more or less academical.
    I do it for demonstration some dsp - functions.
    hilbert is usefull if you have no knowledge about the signal.
    You can easier generate a IQ pair, if you know the parameters.
    Maybe for DPSK demod is this thread for interesst.
    https://forums.parallax.com/discussion/170987/simple-iq-modulation-with-cordic-finished#latest
    (But this was my first try with the processor and the programming language)
  • Cool, I'm interested in trying to make a BandPass filter . I have some C code for it in one of my books.
  • @"Bob Lawrence (VE1RLL)"
    the hilbert transformation was really just a test for my dsp - lib.
    For filter it is better to work in the time domain.
    Give me a little time and I will give you examples of filters in the time domain (lowpass, highpass, bandpass, notch, etc.)
  • @Reinhard
    Give me a little time and I will give you examples of filters in the time domain (lowpass, highpass, bandpass, notch, etc.)

    Sure, that sounds great!1. It would be fun to make a Graphics EQ with the P2.
  • ReinhardReinhard Posts: 489
    edited 2020-06-23 21:42
    @Bob Lawrence (VE1RLL)

    First you need a program, that calculate the filter coeffiecents for you.
    I have a program, that calculate a biquad filter.
    The name is BQ.c
    Under Linux it is compile with gcc -o BQ BQ.c -lm
    (under window or mac it must be similar)

    if you run BQ without parameters you get ;
    ./BQ
    usage:
    ./BQ filtertype Fc Q peakGaindB
    filtertype
    0 ... LowPass
    1 ... HighPass
    2 ... BandPass
    3 ... Notch
    4 ... Peak
    Fc = fcut/fsample
    Q = Quality of the filter
    The higher the quality, the steeper the filter
    peakGain = peakGain in dB
    example for LowPass: 0 0.25 1 0

    you want a bandpass:
    ./BQ 2 0.25 1 0
    you get ;
    #define a0 0.333333
    #define a1 0.000000
    #define a2 -0.333333
    #define b1 -0.000000
    #define b2 0.333333

    this are the filter coefficients, more to use it later.

    if you have gnuplot, you can visualize
    #! /bin/bash
    gnuplot -p -e 'plot "Amplitude.txt" with lines'
    gnuplot -p -e 'plot "Phase.txt" with lines'
    gnuplot -p -e 'plot "Nyquist.txt" with lines'
    gnuplot -p -e 'plot "Impulsresponse.txt" with lines'

    I'm looking for examples for P2, but calculate the filter coefficients is the basic.
    c
    c
    6K
    BQ.c 6.2K
Sign In or Register to comment.