Shop OBEX P1 Docs P2 Docs Learn Events
simple IQ-Modulation with cordic(finished) — Parallax Forums

simple IQ-Modulation with cordic(finished)

ReinhardReinhard Posts: 489
edited 2020-01-05 11:11 in Propeller 2
Before I get the silicon (thanks to Connecticut)
I can think of a few more theoretical thought experiments.
How about an IQ modulator?
As you know, the equation is
f_sig_out = f_sig_in * cos (f_carrier) + f_sig_in * sin (f_carrier)
This means if an input signal is modulated without a DC component
a frequency spectrum is created with f_carrier + - f_sig_in.
With the DC component, f_carrier - f_sig_in, f_carrier, f_carrier + f_sig_in is created.
Only DC input, no AC, creates f_carrier.
I simulated exactly this case with the help of the Cordic solver.
One can do without the two multiplications if the
qrotate statement with which input is scaled.
dat
	org 0
	mov		angle,#0
	mov		sig_in,#100				'DC constant

loop
	mov		sig_out,#0				'clear output
	qrotate	sig_in,angle
	getqx	x						'x = sig_in * cos(angle)
	getqy	y						'y = sig_in * sin(angle)
	add		sig_out,x				
	add		sig_out,y				        'sig_out = x + y
	add		angle,##$800_0000		'increment 11,25°
	
	jmp		#loop
	
x		res	1
y		res	1
angle	res	1
sig_in	res	1
sig_out	res	1
	

Comments

  • cgraceycgracey Posts: 14,155
    It's funny how a lot of the math demanded by these algorithms just comes down to coordinate rotation, but because that doesn't normally exist in languages or hardware, everything is broken out into multiplying by sines and cosines (which usually resolve to table lookups for speed), then adding and subtracting. We can do it all in a single step with the CORDIC. I was delighted to find that a single SETQ+QROTATE made all the hard math go away in my FFT program.

    I actually got the 1024-point FFT running in under 1ms, but I want to spend more time later making it work by self-modifying code, so that it takes way less space.
  • I would like to contribute to make the P2 a rocket.
    But I have no experience in compiler construction.
    I am an electrical engineer, not a computer scientist.
    I have some experience in assembler programming in my professional life,
    (PIC's), lots of knowledge of C and math.
    I would also like the P2 to be given more attention in Germany.
    so if German speakers are present here, maybe we can do something
    to launch ?
    I can only say that I respect the 1024-FFT !
    Reinhard
  • cgracey wrote: »
    We can do it all in a single step with the CORDIC. I was delighted to find that a single SETQ+QROTATE made all the hard math go away in my FFT program.

    This is a big advantage over other DSPs.
  • There is another cordic in the color space converter. Can this be used for signal processing?

    I see a few limitations:
    8 bit output
    Q output only
    output to DAC or digital pins? only
    no way to reset phase (perhaps this could be worked around by running at a very low frequency and stopping it at a certain phase)

    None of this matters for an RF modulator. Except maybe the 8 bits.
  • cgraceycgracey Posts: 14,155
    There is another cordic in the color space converter. Can this be used for signal processing?

    I see a few limitations:
    8 bit output
    Q output only
    output to DAC or digital pins? only
    no way to reset phase (perhaps this could be worked around by running at a very low frequency and stopping it at a certain phase)

    None of this matters for an RF modulator. Except maybe the 8 bits.

    It only outputs to the DAC channels.

    The only way to reset its phase is to disable and reenable it.
  • Another example if the IQ modulator is fed with a cos.
    I logged the output of the simulation and entered a scilab script.
    The result corresponds to the theory.
    dat
    	org 0
    	mov		temp,#0
    loop
    	mov		angle,temp				'this is for f_sig_in
    	mov		angle2,angle			'this is for f_carrier
    	mul		angle2,#20				'f_carrier = 20 * f_sig_in
    	sal		angle,#16
    	sal		angle2,#16
    	qrotate	#100,angle				'make sig_in
    	mov		sig_out,#0				'clear output
    	getqx	sig_in					'sig_in = cos(angle)
    
    	qrotate	sig_in,angle2			'perform iq modulation
    	getqx	x						'x = sig_in * cos(angle2)
    	getqy	y						'y = sig_in * sin(angle2)
    	add		sig_out,x				
    	add		sig_out,y				'sig_out = x + y
    	add		temp,##$800		  		'increment (after sal 11,25°)
    	
    	jmp		#loop
    	
    x		res	1
    y		res	1
    angle	res	1
    angle2	res	1
    sig_in	res	1
    sig_out	res	1
    temp	res	1
    
    
  • Reinhard, it looks like your program does this:
    sig*sin(ct) + sig*cos(ct)
    sig*( sin(ct) + cos(ct) )
    sig*sqrt(2)*cos( ct - pi/4 )



    cgracey wrote: »
    There is another cordic in the color space converter. Can this be used for signal processing?

    I see a few limitations:
    8 bit output
    Q output only
    output to DAC or digital pins? only
    no way to reset phase (perhaps this could be worked around by running at a very low frequency and stopping it at a certain phase)

    None of this matters for an RF modulator. Except maybe the 8 bits.

    It only outputs to the DAC channels.

    The only way to reset its phase is to disable and reenable it.
    Thanks, Chip.

    That is still an improvement over the P1, which had no way to reset the chroma phase.
  • Does anyone have a short sequence for disable / enable?

  • ReinhardReinhard Posts: 489
    edited 2019-12-31 09:10
    Reinhard, it looks like your program does this:
    a) sig*sin(ct) + sig*cos(ct)
    b) sig*( sin(ct) + cos(ct) )
    c) sig*sqrt(2)*cos( ct - pi/4 )

    Yes, it show the principe of double sideband modulation with suppressing carrier.
    if we say sig = cos(phi) and ct = (20*phi)
    we get sig_out = cos(phi) * cos(20*phi) + cos(phi) * sin(20*phi)
    this is the a formula for double sideband modulation and corresponds with your equation a)
    b) and c) are alternative forms.
    Another alternative form is 0.5(sin(19*phi) + sin(21*phi) + cos(19*phi) + cos(21*phi))
    Here ws see the sum and diffs in frequency domain, the carrier is suppressed.
    If I get my ev board, I make a physical signal.
    Reinhard
    P.S. I am back in the forum after new year.
  • My motivation:
    At the beginning of the 90's I was working in a company in germany. The CEO was an American. In the 1960s he acquired the monopoly of transmitting background music to shops and hotels via telephone lines, (muzak) .In the 1990s he terminated the lines and rented a transponder on a semi-commercial satellite. (Kopernikus3).
    But the signal had to be encrypted. At that time, digital processing was not yet available cheaply. In the course of my thesis, I developed an analog scrambler. The band-limited audio signal was modulated up and down again.
    The upper sideband is cut and what is left is a frequency shifted and sideband inverted audio spectrum. This process was reversed in the receivers and the plain signal was audible. An entire European board was required for the analog components. Now I want to do a retro development with a chip for fun. I think this is easy for P2.
    Back to the thread:
    For the first one, I connected an external 8-bit R2R DAC because I just have it in my handicrafts. I don't want to be able to output it on a smartpin yet. I'm probably doing something wrong. I copied templates from the P2 Audio Out thread, but the pin remains silent. It would be great if someone could help me with a code snippet.
    const					'from forum thread P2 AUDIO OUT
      L_PIN = 0
      R_PIN = 1
      SYSTEM_CLOCK = 250000000
      SAMPLE_RATE = 250000
      INIT_8BIT_DAC_VALUE  = 128
      DAC_MODE             = %00011_0 ' DAC 16-bit dither, PWM
      DIR_MODE             = %01      ' Output enabled, overrides DIR
      ANALOG_OUT_MODE      = %10111 '  75 ohm, 2.0V DAC mode
      SMARTPIN_DAC_MODE    = (ANALOG_OUT_MODE << 16) | (INIT_8BIT_DAC_VALUE << 8) | (DIR_MODE << 6) | DAC_MODE
      SAMPLE_PERIOD        = SYSTEM_CLOCK  / SAMPLE_RATE  'CPU cycles between sample updates
    
    dat
    	org 0
    
        hubset  ##%1_000001_0000011000_1111_10_00       'config PLL, 20MHz/2*25*1 = 250MHz
        waitx   ##20_000_000 / 200                      'allow crystal+PLL 5ms to stabilize
        hubset  ##%1_000001_0000011000_1111_10_11       'switch to PLL
    	mov		dira,#255	
    	mov		temp,#0
    	
    'from forum thread P2 AUDIO OUT	
    	'wrpin   SMARTPIN_DAC_MODE, #L_PIN           ' Config smartpin DAC mode on "left" pin
        'wrpin   SMARTPIN_DAC_MODE, #R_PIN           ' Config smartpin DAC mode on "right" pin
        'wxpin   SAMPLE_PERIOD, #L_PIN                  ' Set sample period for left audio channel
        'wxpin   SAMPLE_PERIOD, #R_PIN                  ' Set sample period for right audio channel
        'dirh    #L_PIN                                ' Enable smartpin DAC mode on left pin
        'dirh    #R_PIN                                ' Enable smartpin DAC mode on right pin
        'setse1  #%001_000000 | L_PIN                  ' Event triggered every new sample period (when "left in pin rises")
    
    loop
    	mov		angle,temp				'this is for f_sig_in
    	mov		angle2,angle			'this is for f_carrier
    	mul		angle2,#20				'f_carrier = 20 * f_sig_in
    	sal		angle,#16
    	sal		angle2,#16
    	qrotate	#100,angle				'make sig_in
    	mov		sig_out,#0				'clear output
    	getqx	sig_in					'sig_in = cos(angle)
    
    	qrotate	sig_in,angle2			'perform iq modulation
    	getqx	x						'x = sig_in * cos(angle2)
    	getqy	y						'y = sig_in * sin(angle2)
    	add		sig_out,x				
    	add		sig_out,y				'sig_out = x + y
    	add		temp,##$800		  		'increment (after sal 11,25°)
    	
    '----------------------OUTPUT STAGE-------------------------------------
    										' ok with external dac
    	'mov		temp2,#128				'interims output stage
    	'sub		temp2,sig_out			'to 8 bit dac
    	'and		temp2,#255				'before I learned more
    	'mov		outa,temp2	 			'about audio smart pins	
    	drvnot	#2							'speed indicator : 781.2 kHz !
    	
    'from forum thread P2 AUDIO OUT	
         wypin    temp2, #L_PIN             ' Output sample on left channel
         wypin    temp2, #R_PIN             ' Output sample on right channel
         waitse1
    '-----------------------------------------------------------------------	
    	jmp		#loop
    	
    x		res	1
    y		res	1
    angle	res	1
    angle2	res	1
    sig_in	res	1
    sig_out	res	1
    temp	res	1
    temp2	res	1
    	
     
    
    
    something is comment out in the code, for debug reasons.
  • Ahle2Ahle2 Posts: 1,179
    I think the "waitse1", will wait forever! The smartpin must be activated and the event registered for it to work. But I honestly don't understand why you would use an external R2R dac?! Each pin om the P2 can do better than 8bit audio signals.
  • Ahle2 wrote: »
    I think the "waitse1", will wait forever! The smartpin must be activated and the event registered for it to work. But I honestly don't understand why you would use an external R2R dac?! Each pin om the P2 can do better than 8bit audio signals.

    The reason for use the old R2R dac is, because I haven't Experience with smartpin handling.
    Today I receive my EV Board and I wanted to see a quick success. Connect Osci to the pin and look at the signal.
    But I don't see anything with the output to smartpin. The pin is at 0Volt. Or do I still need a resistor on the pin?
  • wrpin   smartConfigAudioDAC, #L_PIN 
    

    smartConfigAudioDAC from the snippets of thread P2 Audio Out was not defined.


    I thought that's ok,but maybe not.
    wrpin   SMARTPIN_DAC_MODE, #L_PIN 
    
  • I think for the smartpin issue is it better I go to the P2 Audio Out thread.
  • now, with the many help from Audio OUT Thread, I can do my next step here.
    The DAC output is what I want for first and what I expected.

    pic_33_3.bmppic_33_4.bmp
  • ErNaErNa Posts: 1,752
    For those interested: https://de.wikipedia.org/wiki/Muzak_(Marke) or https://en.wikipedia.org/wiki/Muzak Also may be up-to-date: the chapter on "Stimulus progression". So we could create a channel to stimulate Px-usage with AI inspired melodies. And we will see what happens..

    A Happy And Succesfull New Year To All The Listeners!
  • ;-)
    Muzak, long long time ago.
    I was from 1991 to 1993 in the company.
    In Germany/Austria the was called funktionelle musik gmbh.
    It was an exciting and interesting time.

    Happy New Year.
  • Now I can finish this piece of code.
    I trimmed the sig_in frequency to 1kHz, the local oscillator frq. to 20kHz.
    The sig_out has 19 and 21 kHz frequncy components.pic_36_1.bmp
    the time domain looks:
    pic_36_2.bmp
  • Ahle2Ahle2 Posts: 1,179
    Good work Reinhard... I am glad you have got it working as intended. At 250 kHz you have got a lot more instructions to "waste" on processing. The P1 would have been choked already doing software multiplication and sine lookup.
  • A few radio hams including a friend of mine have designed single sideband HF transceivers based on DSPIC33 processors with the addition of a tayloe mixer and low noise 24 bit a/d. The propeller 2 probably has a lot more going for it as signal processor. I'm looking forward to trying vector math functions in pasm, glued together with TAQOZ. Great platform for experimental stuff. The eight COGS can pipeline the processes along and mic and speaker can probably be driven adequately by the internal converters.
Sign In or Register to comment.