apply all decimation in comples to simplify the chain

This commit is contained in:
Jakob Ketterl 2021-07-24 22:25:41 +02:00
parent ab99b8e476
commit c50da15bfd
4 changed files with 12 additions and 34 deletions

View File

@ -1,10 +1,9 @@
from csdr.chain import Chain from csdr.chain import Chain
from csdr.chain.demodulator import Demodulator
from pycsdr.modules import AmDemod, DcBlock, Agc, Convert from pycsdr.modules import AmDemod, DcBlock, Agc, Convert
from pycsdr.types import Format, AgcProfile from pycsdr.types import Format, AgcProfile
class Am(Demodulator): class Am(Chain):
def __init__(self): def __init__(self):
agc = Agc(Format.FLOAT) agc = Agc(Format.FLOAT)
agc.setProfile(AgcProfile.SLOW) agc.setProfile(AgcProfile.SLOW)
@ -12,13 +11,8 @@ class Am(Demodulator):
workers = [ workers = [
AmDemod(), AmDemod(),
DcBlock(), DcBlock(),
# empty chain as placeholder for the "last decimation"
Chain(),
agc, agc,
Convert(Format.FLOAT, Format.SHORT), Convert(Format.FLOAT, Format.SHORT),
] ]
super().__init__(*workers) super().__init__(*workers)
def setLastDecimation(self, decimation: Chain):
self.replace(2, decimation)

View File

@ -1,16 +1,10 @@
from csdr.chain import Chain from csdr.chain import Chain
from pycsdr.modules import Module, Shift, FirDecimate, Bandpass, Squelch, FractionalDecimator from pycsdr.modules import Shift, FirDecimate, Bandpass, Squelch, FractionalDecimator
from abc import ABCMeta, abstractmethod from pycsdr.types import Format
class Demodulator(Chain, metaclass=ABCMeta):
@abstractmethod
def setLastDecimation(self, decimation: Module):
pass
class DemodulatorChain(Chain): class DemodulatorChain(Chain):
def __init__(self, samp_rate: int, audioRate: int, shiftRate: float, demodulator: Demodulator): def __init__(self, samp_rate: int, audioRate: int, shiftRate: float, demodulator: Chain):
self.shift = Shift(shiftRate) self.shift = Shift(shiftRate)
decimation, fraction = self._getDecimation(samp_rate, audioRate) decimation, fraction = self._getDecimation(samp_rate, audioRate)
@ -23,16 +17,12 @@ class DemodulatorChain(Chain):
self.squelch = Squelch(5) self.squelch = Squelch(5)
if fraction != 1.0: workers = [self.shift, self.decimation]
demodulator.setLastDecimation(FractionalDecimator(fraction))
workers = [ if fraction != 1.0:
self.shift, workers += [FractionalDecimator(Format.COMPLEX_FLOAT, fraction)]
self.decimation,
self.bandpass, workers += [self.bandpass, self.squelch, demodulator]
self.squelch,
demodulator
]
super().__init__(*workers) super().__init__(*workers)

View File

@ -1,9 +1,9 @@
from csdr.chain.demodulator import Demodulator, Chain from csdr.chain import Chain
from pycsdr.modules import FmDemod, Limit, NfmDeemphasis, Agc, Convert from pycsdr.modules import FmDemod, Limit, NfmDeemphasis, Agc, Convert
from pycsdr.types import Format, AgcProfile from pycsdr.types import Format, AgcProfile
class Fm(Demodulator): class Fm(Chain):
def __init__(self, sampleRate: int): def __init__(self, sampleRate: int):
agc = Agc(Format.FLOAT) agc = Agc(Format.FLOAT)
agc.setProfile(AgcProfile.SLOW) agc.setProfile(AgcProfile.SLOW)
@ -11,13 +11,8 @@ class Fm(Demodulator):
workers = [ workers = [
FmDemod(), FmDemod(),
Limit(), Limit(),
# empty chain as placeholder for the "last decimation"
Chain(),
NfmDeemphasis(sampleRate), NfmDeemphasis(sampleRate),
agc, agc,
Convert(Format.FLOAT, Format.SHORT), Convert(Format.FLOAT, Format.SHORT),
] ]
super().__init__(*workers) super().__init__(*workers)
def setLastDecimation(self, decimation: Chain):
self.replace(2, decimation)

View File

@ -1,10 +1,9 @@
from csdr.chain import Chain from csdr.chain import Chain
from csdr.chain.demodulator import Demodulator
from pycsdr.modules import RealPart, Agc, Convert from pycsdr.modules import RealPart, Agc, Convert
from pycsdr.types import Format from pycsdr.types import Format
class Ssb(Demodulator): class Ssb(Chain):
def __init__(self): def __init__(self):
workers = [ workers = [
RealPart(), RealPart(),