用树莓派制作FM调频无线电发射器

news/2024/10/31 3:20:41/

最近发现一个好玩的项目,用树莓派制作FM调频无线电发射器

github地址 https://github.com/ChristopheJacquet/PiFmRds


FM-RDS transmitter using the Raspberry Pi

This program generates an FM modulation, with RDS (Radio Data System) data generated in real time. It can include monophonic or stereophonic audio.

It is based on the FM transmitter created by Oliver Mattos and Oskar Weigl, and later adapted to usingDMA by Richard Hirst. Christophe Jacquet adapted it and added the RDS data generator and modulator. The transmitter uses the Raspberry Pi's PWM generator to produce VHF signals.

NEW: now supports any sample rate for audio files, and generates FM-Stereo signals!

How to use it?

Pi-FM-RDS, depends on the sndfile library. To install this library on Debian-like distributions, for instance Raspbian, run sudo apt-get install libsndfile1-dev.

Then clone the source repository and run make in the src directory:

git clone https://github.com/ChristopheJacquet/PiFmRds.git
cd PiFmRds/src
make

Then you can just run:

sudo ./pi_fm_rds

This will generate an FM transmission on 107.9 MHz, with default station name (PS), radiotext (RT) and PI-code, without audio. The radiofrequency signal is emitted on GPIO 4 (pin 7 on header P1).

You can add monophonic or stereophonic audio by referencing an audio file as follows:

sudo ./pi_fm_rds -audio sound.wav

To test stereophonic audio, you can try the file stereo_44100.wav provided.

The more general syntax for running Pi-FM-RDS is as follows:

pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code] [-ps ps_text] [-rt rt_text]

All arguments are optional:

  • -freq specifies the carrier frequency (in MHz). Example: -freq 107.9.
  • -audio specifies an audio file to play as audio. The sample rate does not matter: Pi-FM-RDS will resample and filter it. If a stereo file is provided, Pi-FM-RDS will produce an FM-Stereo signal. Example: -audio sound.wav. The supported formats depend on libsndfile. This includes WAV and Ogg/Vorbis (among others) but not MP3. Specify - as the file name to read audio data on standard input (useful for piping audio into Pi-FM-RDS, see below).
  • -pi specifies the PI-code of the RDS broadcast. 4 hexadecimal digits. Example: -pi FFFF.
  • -ps specifies the station name (Program Service name, PS) of the RDS broadcast. Limit: 8 characters. Example: -ps RASP-PI.
  • -rt specifies the radiotext (RT) to be transmitted. Limit: 64 characters. Example: -rt 'Hello, world!'.
  • -ctl specifies a named pipe (FIFO) to use as a control channel to change PS and RT at run-time (see below).
  • -ppm specifies your Raspberry Pi's oscillator error in parts per million (ppm), see below.

By default the PS changes back and forth between Pi-FmRds and a sequence number, starting at00000000. The PS changes around one time per second.

Clock calibration (only if experiencing difficulties)

The RDS standards states that the error for the 57 kHz subcarrier must be less than ± 6 Hz, i.e. less than 105 ppm (parts per million). The Raspberry Pi's oscillator error may be above this figure. That is where the -ppm parameter comes into play: you specify your Pi's error and Pi-FM-RDS adjusts the clock dividers accordingly.

In practice, I found that Pi-FM-RDS works okay even without using the -ppm parameter. I suppose the receivers are more tolerant than stated in the RDS spec.

One way to measure the ppm error is to play the pulses.wav file: it will play a pulse for precisely 1 second, then play a 1-second silence, and so on. Record the audio output from a radio with a good audio card. Say you sample at 44.1 kHz. Measure 10 intervals. Using Audacity for example determine the number of samples of these 10 intervals: in the absence of clock error, it should be 441,000 samples. With my Pi, I found 441,132 samples. Therefore, my ppm error is (441132-441000)/441000 * 1e6 = 299 ppm, assuming that my sampling device (audio card) has no clock error...

Piping audio into Pi-FM-RDS

If you use the argument -audio -, Pi-FM-RDS reads audio data on standard input. This allows you to pipe the output of a program into Pi-FM-RDS. For instance, this can be used to read MP3 files using Sox:

sox -t mp3 http://www.linuxvoice.com/episodes/lv_s02e01.mp3 -t wav -  | sudo ./pi_fm_rds -audio -

Changing PS and RT at run-time

You can control PS and RT at run-time using a named pipe (FIFO). For this run Pi-FM-RDS with the -ctl argument.

Example:

mkfifo rds_ctl
sudo ./pi_fm_rds -ctl rds_ctl

Then you can send “commands” to change PS and RT:

cat >rds_ctl
PS MyText
RT A text to be sent as radiotext
PS OtherTxt
...

Every line must start with either PS or RT, followed by one space character, and the desired value. Any other line format is silently ignored.

Warning and Diclaimer

Never use this program to transmit VHF-FM data through an antenna, as it is illegal in most countries. This code is for experimental purposes only. Always connect a shielded transmission line from the RaspberryPi directly to a radio receiver, so as not to emit radio waves.

I could not be held liable for any misuse of your own Raspberry Pi. Any experiment is made under your own responsibility.

Tests

Pi-FM-RDS was successfully tested with all my RDS-able devices, namely:

  • a Sony ICF-C20RDS alarm clock from 1995,
  • a Sangean PR-D1 portable receiver from 1998,
  • a Samsung Galaxy S2 mobile phone from 2011,
  • a Philips MBD7020 hifi system from 2012,
  • a Silicon Labs USBFMRADIO-RD USB stick, employing an Si4701 chip, and using my RDS Surveyor program,
  • a “PCear Fm Radio”, a Chinese clone of the above, again using RDS Surveyor.

Reception works perfectly with all the devices above. RDS Surveyor reports no group errors.

CPU Usage

CPU usage is as follows:

  • without audio: 9%
  • with mono audio: 33%
  • with stereo audio: 40%

CPU usage increases dramatically when adding audio because the program has to upsample the (unspecified) sample rate of the input audio file to 228 kHz, its internal operating sample rate. Doing so, it has to apply an FIR filter, which is costly.

Design

The RDS data generator lies in the rds.c file.

The RDS data generator generates cyclically four 0A groups (for transmitting PS), and one 2A group (for transmitting RT). get_rds_group generates one group, and uses crc for computing the CRC.

To get samples of RDS data, call get_rds_samples. It calls get_rds_group, differentially encodes the signal and generates a shaped biphase symbol. Successive biphase symbols overlap: the samples are added so that the result is equivalent to applying the shaping filter (a root-raised-cosine (RRC) filter specified in the RDS standard) to a sequence of Manchester-encoded pulses.

The shaped biphase symbol is generated once and for all by a Python program calledgenerate_waveforms.py that uses Pydemod, one of my other software radio projects. This Python program generates an array called waveform_biphase that results from the application of the RRC filter to a positive-negative impulse pair. Note that the output of generate_waveforms.py, two files named waveforms.c and waveforms.h, are included in the Git repository, so you don't need to run the Python script yourself to compile Pi-FM-RDS.

Internally, the program samples all signals at 228 kHz, four times the RDS subcarrier's 57 kHz.

The FM multiplex signal (baseband signal) is generated by fm_mpx.c. This file handles the upsampling of the input audio file to 228 kHz, and the generation of the multiplex: unmodulated left+right signal (limited to 15 kHz), possibly the stereo pilot at 19 kHz, possibly the left-right signal, amplitude-modulated on 38 kHz (suppressed carrier) and RDS signal from rds.c. Upsampling is performed using a zero-order hold followed by an FIR low-pass filter of order 60. The filter is a sampled sinc windowed by a Hamming window. The filter coefficients are generated at startup so that the filter cuts frequencies above the minimum of:

  • the Nyquist frequency of the input audio file (half the sample rate) to avoid aliasing,
  • 15 kHz, the bandpass of the left+right and left-right channels, as per the FM broadcasting standards.

The samples are played by pi_fm_rds.c that is adapted from Richard Hirst's PiFmDma. The program was changed to support a sample rate of precisely 228 kHz.

References

  • EN 50067, Specification of the radio data system (RDS) for VHF/FM sound broadcasting in the frequency range 87.5 to 108.0 MHz


http://www.ppmy.cn/news/470718.html

相关文章

FAQ-按耳机hook键控制FM调频功能

耳机检测方式为ACCDET_SUPPORT TRUE,要实现按耳机hook键控制FM调频功能 [SOLUTION] 实现步骤: 1,在uem_msg_hdlr.c(ps\l4\uem\src)文件中先extern void mmi_fmrdo_main_goto_next_channel(void); 2,再定义static void…

收音机c语言程序,基于51单片机的数字FM调频收音机的设计(附接线图,主程序代码)...

基于51单片机的数字FM调频收音机的设计(附接线图,主程序代码)(任务书,开题报告,论文15000字) 摘要 在当今的社会时代中,信息的传输扮演着极其重要的地位。随着科学技术的不断发展与进步,人类的生活已早已不能离开通信。收音机从其诞生以来,一直是一种信息传递的重要工具。由…

【GNURadio RTL-SDR】双RTL-SDR信号源的FM调频广播接收机

文章目录 1. 前言2. 实验过程2.1 制作流图2.2 RTL-SDR的设备参数 1. 前言 两个RTL-SDR的dongle“电视棒”,芯片 RTL2832U R820T ,淘宝50左右那种能收FM和我国DTMB频段,想都接到同一台电脑去用软件无线电(GNURadio)的…

FM信号测试软件,手机中FM调频性能测试方法简介

原标题:手机中FM调频性能测试方法简介 手机已经成为人们非常重要的通讯工具,相应手机整合的功能也愈来愈多。目前市面上的手机基本上都支持FM收音机功能,而FM收音机性能则主要是通过 、接收频带宽度、解调输出信噪比、解调输出失真度、接收解调输出幅度等指标来给予衡量,摩…

隧道FM调频广播覆盖技术方案

隧道FM调频广播覆盖解决方案详细描述了隧道广播覆盖的技术原理,主要从隧道FM调频广播覆盖的设备组成、信号流程、关键技术等几方面进行描述。 隧道FM调频广播覆盖系统主要由信号选频单元、光纤传输单元、直放站(远端机)、泄/露电缆与天馈系统…

FIR 基础应用 - FM 调频波调制解调(FIR 低通滤波)

本文链接:https://blog.csdn.net/qq_46621272/article/details/125337119 FIR 基础应用 - FM 调频波调制解调(FIR 低通滤波) 文章目录 前言一、 调频波调制1. fm_modulation_dds 模块逻辑框图2. fm_modulation_dds.v verilog 代码 二、 调频波解调1. fm_demodulatio…

地下停车场FM调频广播覆盖方案

地下停车场FM调频广播覆盖方案 北京海特伟业科技有限公司 文/任洪卓 发布时间:2022-06-05 一、项目需求 我国的调频广播传输采用88-108MHz频段,只能在直视和无阻挡的情况下传播,因此地下停车场接收调频广播信号很差,有些甚至…

C++ 教程(16)——字符串

C 字符串 C 提供了以下两种类型的字符串表示形式: C 风格字符串C 引入的 string 类类型 C 风格字符串 C 风格的字符串起源于 C 语言,并在 C 中继续得到支持。字符串实际上是使用 null 字符 \0 终止的一维字符数组。因此,一个以 null 结尾…