Implement pre-emphasis filter in C - Page 1
Forum section: electronics / general

author: Zipdox
author_rank: Regular Contributor
timestamp: January 11, 2023, 02:52:17 pm
content: 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

author: Zipdox
author_rank: Regular Contributor
timestamp: January 12, 2023, 12:49:41 am
content: 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.pdfThe specification specifies "cosine rolloff". I have no idea how to implement this.This documentspecifies a raised-cosine filter, whilethis repospecifies a root-raised-cosine filter. I guess maybe I could steal some code from that repo.And thesehttps://github.com/ChristopheJacquet/Pydemod/blob/master/src/pydemod/app/rds.py#L42https://github.com/ChristopheJacquet/Pydemod/blob/master/src/pydemod/filters/shaping.py#L15

author: Zipdox
author_rank: Regular Contributor
timestamp: January 12, 2023, 05:39:13 pm
content: Looks like I figured it out.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 12, 2023, 07:28:52 pm
content: Quote from: Zipdox on January 12, 2023, 05:39:13 pmI 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?

author: Zipdox
author_rank: Regular Contributor
timestamp: January 12, 2023, 09:03:49 pm
content: Quote from: SiliconWizard on January 12, 2023, 07:28:52 pmNo, 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.

author: newbrain
author_rank: Super Contributor
timestamp: January 13, 2023, 12:37:52 pm
content: Quote from: Zipdox on January 12, 2023, 09:03:49 pmWhen you amplitude modulate a carrier, the bandwidth of the resulting signal is twice the modulating signal bandwidth, centered on the carrier.WithAM, 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:QuoteThis 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.

author: Zipdox
author_rank: Regular Contributor
timestamp: January 27, 2023, 03:57:27 am
content: Holy shit I got it working.

author: Zipdox
author_rank: Regular Contributor
timestamp: January 27, 2023, 04:05:22 am
content: 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.