Author Topic: Implement pre-emphasis filter in C  (Read 1056 times)

0 Members and 1 Guest are viewing this topic.

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Implement pre-emphasis filter in C
« on: January 11, 2023, 02:52:17 pm »
I'm working on an audio plugin for FM stereo multiplexing with RDS. I got the stereo multiplexing working but I'm running into problems with the RDS carrier.

The system runs at 192kHz sample rate. The RDS carrier is 57 kHz.

The problem is that when I switch the RDS carrier on and off, I get a lot of nasty harmonics. What would be the best approach to deal with these?

The code: https://gitlab.com/zipdox/fmgen.lv2/-/blob/rds/fmgen.c
« Last Edit: January 27, 2023, 04:05:33 am by Zipdox »
 

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #1 on: January 12, 2023, 12:49:41 am »
It appears I had no idea what I was doing and the Wikipedia page for RDS doesn't contain any information about the modulation type.

Anyway, now that I have figured out the manchester coding, I need to figure out the pulse shaping filter.
http://www.interactive-radio-system.com/docs/EN50067_RDS_Standard.pdf
The specification specifies "cosine rolloff". I have no idea how to implement this. This document specifies a raised-cosine filter, while this repo specifies a root-raised-cosine filter. I guess maybe I could steal some code from that repo.

And these
https://github.com/ChristopheJacquet/Pydemod/blob/master/src/pydemod/app/rds.py#L42
https://github.com/ChristopheJacquet/Pydemod/blob/master/src/pydemod/filters/shaping.py#L15
« Last Edit: January 12, 2023, 12:54:21 am by Zipdox »
 

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #2 on: January 12, 2023, 05:39:13 pm »
Looks like I figured it out.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #3 on: January 12, 2023, 07:28:52 pm »
Looks like I figured it out.

I have used RDS in the past but never implemented the modulation myself. Certainly interesting, although (as you noticed), there's probably a near-zero number of people on here that have ever done that.

Didn't really look at your source code, my quick guess is that you may have needed to switch the carrier on zero-crossings to avoid unwanted harmonics. Is it what you did?
 

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #4 on: January 12, 2023, 09:03:49 pm »
Didn't really look at your source code, my quick guess is that you may have needed to switch the carrier on zero-crossings to avoid unwanted harmonics. Is it what you did?
No, that's what I tried doing originally. The problem was that it's impossible to switch exactly at the zero-crossing with such a high frequency, and a sample rate that isn't a multiple of said frequency.

But that isn't the problem. That's not actually the proper way to even modulate the signal. The proper way is described in the specification PDF I linked. Basically you manchester encode the bitstream, turn the signal into short negative and positive pulses, run the signal though a pulse shaping filter (in this case a root-raised-cosine filter), and finally multiply the signal by the carrier sine wave (57 kHz). This multiplication results in a double-sideband surpressed-carrier signal (whatever that means) as shown below.
« Last Edit: January 13, 2023, 01:01:01 pm by Zipdox »
 
The following users thanked this post: SiliconWizard, DiTBho

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #5 on: January 13, 2023, 12:37:52 pm »
[...] finally multiply the signal by the carrier sine wave (57 kHz). This multiplication results in a double-sideband surpressed-carrier signal (whatever that means)
When you amplitude modulate a carrier, the bandwidth of the resulting signal is twice the modulating signal bandwidth, centered on the carrier.
With AM, the distribution of power between the carrier prequency and the side bands is determined by the modulation depth.
Part of the power will still be at the carrier frequency for regular AM (at least 50% for a 100% depth of modulation), OTOH, with a straight carrier × modulating signal multiplication (equivalent to a 200% modulation depth) no power remains at the carrier frequency, and the signal is concentrated on the sidebands.
In your picture, those are the two small domes around 57 kHz.

Just to clarify, the composite signal containing RDS, mono L+R, stereo etc. etc. is then used to frequency modulate the radio carrier - in this case the resulting spectrum is much wider, and the needed bandwidth on the air can be approximated by ΔF = 2×(Fmd+Fmax), with Fmd the depth of frequency modulation (75 kHz for FM broadcast, if memory serves) and Fmax the maximum frequency of the modulating signal.

EtA:
Quote
pulse shaping filter (in this case a root-raised-cosine filter)
This is done to limit the bandwidth of the pulse.
A straight edged pulse has an infinite bandwidth (sin(x)/x shaped) so to avoid the resulting modulated signal splattering all over the other parts, an edge smoothing filter (raised cosine) is used. The smoother and lower slew rate the signal, the narrower the bandwidth.
« Last Edit: January 13, 2023, 12:46:18 pm by newbrain »
Nandemo wa shiranai wa yo, shitteru koto dake.
 
The following users thanked this post: DiTBho

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Re: [DSP] Prevent harmonics when switching sine wave
« Reply #6 on: January 27, 2023, 03:57:27 am »
Holy shit I got it working.
 

Offline ZipdoxTopic starter

  • Regular Contributor
  • *
  • Posts: 170
  • Country: nl
Implement pre-emphasis filter in C
« Reply #7 on: January 27, 2023, 04:05:22 am »
I guess I'm changing the topic to something else. How do I implement a pre-emphasis filter in C? If you look in my repo you can see I tried borrowing some code from GNU Radio to calculate the IIR coefficients but I can't figure out how to apply them. The calculation of the coefficients is done in Python but the actually processing is C++, which I despise and am not competent in.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf