Tuesday, August 11, 2026

Class D AM

Years ago I learned about a type of AM transmitter (more like RF stage) called Class D that is really efficient and flexible. The regular way of transmitting AM involves generating a carrier sine wave at the desired frequency and changing its amplitude with the audio, but that requires (1) a good/clean/stable sine wave source and (2) a device that can change the output voltage based on an audio signal. The simplest way to do part 2 is with an amplifier like a vacuum tube or transistor, but the problem is that those are linear devices so they're inefficient. What you actually want is a switching device.

As a kid, I always wondered why power supplies couldn't just be some series resistors. I also experimented with linear regulators (a chip-controlled variable resistor that maintains a constant voltage at the output) and wondered why they got so hot and assumed that I must be using them wrong. What I didn't realize was that they're the same thing and that that doesn't work because of Ohm's law.

The problem is that lowering a voltage with resistance wastes all the energy that the resistor is reducing by. For example, if you use a linear voltage regulator to convert 120 volts DC to 5 volts 1 amp to charge a phone, the input would also use 1 amp which would be 120 watts but since the output is only 5 watts, that's 115 watts of waste that is going to be released as heat which is incredibly wasteful. The way to fix that is with a switching power supply. Those work by switching the high voltage on and off really fast but (usually) leaving it on for way less time than off so the output only gets tiny slices of the higher voltage which gets averaged to a lower voltage. This is how good dimmers work and why some LED's flicker and look annoying.

This square-wave switching can also be used to generate AM radio. A square wave is a sine wave at the fundamental frequency plus all of the odd harmonics. You obviously wouldn't want to transmit that because it would pollute other frequencies like an arc transmitter, but if you add a low-pass filter (removes everything above its frequency), you get just the original sine wave at the desired frequency. This is your carrier. You can use whatever good square-wave source you want, such as an FPGA or a dedicated DDS (direct digital synthesis) chip. Some people even do it with microcontrollers like a Raspberry Pi or Arduino/ESP32. I prefer precise and exact timing so I've been using an FPGA. It sounds like the output would be unstable but dividing a higher square-wave clock from a crystal and using that either directly or in a DDS design can produce an extremely clean and stable carrier for an AM station.

Once you have a square wave at the frequency you want, you use it at the gate of a MOSFET or GAN FET to switch it perfectly on and off really fast like a power supply. This gets filtered and sent to the antenna. Because FET's are really efficient, they hardly get hot if you do it right even with several watts of output power but you have to use a gate driver because logic pins are fast (like megabits/second or faster) for other logic circuits but power circuits require something heavy-duty that can take a weak but fast information signal and turn it into amps of power in nanoseconds to charge and discharge a FET gate. If you use an audio signal or a logic signal that is slowed down by trying to drive something heavy-duty, the FET will spend a while between perfectly on and perfectly off and operate in its linear region and become a variable resistor like a linear regulator and get really hot and self-destruct in seconds. You can buy a gate driver like the TC4426A or build your own totem pole driver with regular transistors to drive a MOSFET fast enough but you need a different type if you use a GAN FET.

A solid carrier isn't really useful so how do you get the audio into it? Normally you would want to get as close as possible to a 50% duty cycle for the RF PWM but you could modulate the duty cycle with the audio. This works and makes recognizable audio but you would need a REALLY fast FET to switch fast enough for it to make sense because the PWM needs to be able to cover your audio waveform levels (the same as the bit depth on the computer). For example, if you have a 12 MHz FPGA board like mine and divide the clock to 600 kHz, you only get 20 total clock cycles for every RF PWM cycle (ideally 10 on and 10 off). If you lower the carrier frequency to 300 kHz (longwave) then you get 40 (ideally 20 on and 20 off). With 40 clock cycles per RF PWM output cycle, you could do 5-bit audio with a bit of overhead but that sounds horrible and you would need to be able to switch your FET at close to 12 MHz which is hard even with good recent devices because you have to watch out for parasitic stuff on the PCB traces.

A much better solution is to maintain a 50% RF PWM duty cycle on the RF stage and modulate the power going to it. To do that, you should convert your audio signal to PWM at a lower frequency and use that to drive a FET, filter the output to remove the switching frequency, and use the smooth amplified audio output as the input voltage for the RF stage. Here is a comparison.


There's a guy in the UK called John Stretch A.K.A. Stretchyman who builds custom transmitters like this for AM and lower shortwave frequencies. I bought one from him once (totally for a ham AM net ðŸ˜‰) and I can confirm his build quality and the clean output signal. With his transmitter, I was able to reach across much of the eastern US at only about 45 watts PEP with a longwire antenna in a tree and I didn't even need a fan for the transmitter. Here is a link to his YouTube channel. https://www.youtube.com/channel/UCnDdvpAi7FcSrETGwc6dT0Q. There are also a lot of similar options on eBay with more frequency coverage if you search for terms like "DDS".

I lost my "Stretchy" transmitter in an accident so I was wondering if I could build one that's good enough for now. To test that method before building one, I wrote a C++ program to modulate the square wave and generate a WAV file that I could play in HDSDR. I tried the modulated PWM duty cycle method first but it looked and sounded terrible so I asked Google's new search AI for advice and it told me about the modulated input voltage method. I updated the code to do that and then it looked and sounded amazing. Here are some things I noticed.

This is how the raw output looks in Audacity (that's as much as I could zoom in because the sample rate is 12 MHz).


This is how it looks in HDSDR. Notice all the harmonics and other dirty output even though all we want is the one signal at 600 kHz, and how there's a lot of energy right at DC. The reason it appears every 300 kHz is because I upsampled the audio to that rate to try and simulate PWM output at that frequency. If you leave it at 48 kHz then those will appear about every 50 kHz above and below the desired frequency


We can clean that up with "sox" and a bandpass filter. The high-pass filter at 550 kHz takes care of the lower interference and also the DC offset.

sox --ignore-length 12mhztest.wav 12mhztest_bpf_550k-650k.wav sinc -L 550k-650k

It's now a sine wave centered around 0


The harmonics and other mess are gone but it's still not completely clean. This is mostly because this is the only signal in the file and it's very strong so it's overpowering the virtual receiver. We can add some noise in Audacity so it's a bit weaker to make it more like a real-world signal. I mixed the signal with white noise with an amplitude of 0.03 for the next picture.

That looks a lot more like something you'd pick up over the air. Let's zoom in.

I included the audio waterfall so you could see the hard cutoff that I added at 15 kHz when I was doing the broadcast audio processing in Audacity. I think the remaining wider parts are from clipping.

You really don't want to just transmit stuff over the radio without processing it with something like an expander or Thimeo StereoTool. These make it sound better over the radio and help to maximize the modulation and amplify the higher frequencies so the signal is easier to hear when the band conditions are bad. As I currently understand it, a good audio processing toolchain should keep the sound close to clipping the whole time so the signal is rectangular like in the picture. Here is a quality example on Odysee just to make sure it doesn't get a copyright strike. For this file, I downmixed to mono, used Thimeo StereoTool's AM processor with pre-emphasis including the NRSC modified 75 µS one and 3 dB AM Brilliance, manually amplified the musical notes at the beginning, and used a 15 kHz low-pass filter.

https://odysee.com/softwarepwmamtransmittertest:dceb3749b76458e81ea61c6d0a7ca30721104556

Friday, November 6, 2020

7-zip optimization: sorting by file type

 Recently I was compressing the assets I scraped from a now-deleted Discord server and was able to save almost 600 MiB by having 7-zip sort by file type (the default behavior is to sort by filename) in addition to a few other options. This lets 7-zip take advantage of similarities between files of the same type.


The original data was 6,661,786,104 bytes, with the default compression it was 6,041,019,462 bytes (90.682%), and with "sort by file type" enabled, it was 5,427,406,392 bytes (81.471%). In this case, the optional parameters reduced the size of the output by 613,613,070 bytes (585.19 MiB).

This article was updated on February 11, 2021 because one of the parameters, "tr=on", doesn't exist and causes an error. I changed a few other parameters as well and updated the results in the previous paragraph because the new ones saved an extra 2.15 MiB.

Wednesday, July 15, 2020

Delivering GPS updates with TV datacasting

In 2011 my family got a Garmin GPS and a few years later I found it fascinating when I heard that it could get traffic data from FM radio. It occurred to me more recently that map updates could be sent over a broadcast with more capacity, such as a TV channel.

As you may know, my UTSC standard supports file transfers. Each packet is only 125,000 bytes, so you can't transfer much in each one, but it's possible to send large files as a split archive.

I set up an experiment to see how quickly I could transfer a full GPS map of South Carolina. Since I'm near the Georgia border I originally included a Georgia map but later decided to just do one state to make it faster.

I downloaded a copy of the OpenStreetMap data for South Carolina. I signed the map with my PGP key because I figured that automatic map updates should be signed and that unsigned ones, or those without a trusted signature, should require user intervention. I added a license file to the folder and then used my UTSC packet muxer to create packets that include a NoCopyrightSounds music compilation, an image that says this is a GPS map update and gives attribution for the map and music, and file transfers consisting of a split 7-Zip archive.

These are the 3 files I transmitted.


My packet muxer reads a JSON file with a list of content and an optional datacasting field. If datacasting is enabled, it finds the content with the highest bitrate and uses 7-Zip to compress the contents of a folder specified in the JSON. It instructs 7-Zip to split the archive into parts just small enough to fit in the least space (packets with the highest content bitrate).

The total content length was 23h23m00s and the file transfer was 104.9 MiB. The packet muxer reported that it had included the files 60 times. By coincidence, each full transfer took 1403 seconds or 23m23s. That means the map can be transmitted 61 times every 24 hours or about once every 23½ minutes.

After the muxer finished, I used my open-source UTSC transmitter (GitHub link) to transmit the output file. I used UTSC channel 2 (center freq 903.265625 MHz). Here's what it looks like in HDSDR.


Unfortunately, I don't know how to demodulate QPSK at the moment so I can't test the signal but I did some verification of the muxer output with a hex editor before I used it.

Wednesday, May 27, 2020

Multithreaded RRC for Raspberry Pi

In my last post I explained that I couldn't transmit continuous QPSK from my Raspberry Pi 3B because the single-threaded RRC function couldn't keep up with the transmitter. In other words the transmitter was transmitting and consuming the data buffer faster than the RRC function could supply it. This led to a situation in which there were short data bursts separated by slightly longer empty sections.

Tonight I resolved that. I carefully examined the RRC function until I understood how it worked and was sure that nothing depended on previous results, then split it into 4 equal parts, since the Pi has a quad-core CPU. The code uses pthreads in C to run a method that does 1/4 of the work. It populates the start and end indices for each thread, starts all 4, and waits for them to finish. The Pi can now transmit smooth QPSK with just a few sparse dropouts. I was using composite video for this test so it might be fast enough with HDMI which lets the system clocks run faster.


Sunday, May 24, 2020

May 2020 Hackerthon

Over the weekend, the owner of a Discord server called The Hive Mind ran a "hackerthon" during which members were supposed to build something and show pictures on Sunday. Since I was already working on a UTSC broadcast utility for LimeSDR's, I decided to finish it if possible and have something to enter if that was all I could do, and then see if I could transmit the same thing from a Raspberry Pi running on a power bank. If you're not familiar with UTSC, it's a TV standard I created in 2017 as a highly reliable and license-free alternative to ATSC.

Before I begin the description, here are the pictures I submitted when the event ended.







One of the first things I did during the hackerthon was to test the range of the LimeSDR Mini at its highest power. I used DATV Express to transmit QPSK at 625 kilosymbols/sec to make it as much like UTSC as possible and walked around outside with a laptop, SDRplay RSP1, and TV rabbit ears. The setup was on the second floor, about 25 feet above ground level, on a table near a window. The transmitting antenna was an adjustable TV dipole with ladder line oriented vertically. I walked until I was about 955 feet away (291 meters) and the signal was roughly 21 dB above the noise.

After I was done, I worked on a QPSK transmitter in Visual Studio. I copied the modulator from Charles Brain's (G4GUO) DATV Express code, which is public domain. I first tried this about a year ago and it worked but stuttered badly. I copied the code from an older version that had an issue with accessing the webcam when I compiled it so I assumed the modulator code was broken as well. It took a while for G4GUO to get back to me the second time I contacted him so I paused the project until a few days ago. That's when I tried again and succeeded. I think the issue was due to using a different buffer size the first time. I made sure to notify him via Twitter that I didn't need his help anymore.

Now that I could transmit QPSK, I wanted to see if I could use my LimeSDR Mini to do it from a Raspberry Pi. I have a Raspberry Pi 3B V1.2 and it was easy to set up the SDR and C++ environments. Since it uses Linux (specifically Raspbian), I didn't need any drivers. All I had to do was download the LimeSuite repo from GitHub and build and install it. When it was done, it left some include and library files in a folder that was easily accessible. I found them and used them with g++ to compile an example I found.

Once I checked that the API was accessible from C++ on the Pi, I copied my code from Visual Studio and removed everything specific to Windows. When I was done, it was able to transmit but had the stuttering issue. I spent hours trying different buffer sizes and noticed something odd: with a small buffer it stuttered rapidly, but with a large one it would transmit smoothly for a few seconds, nothing for slightly longer, and repeat. I tried transmitting pure noise and it didn't stutter so I decided to profile the code. What I found was that the RRC (root-raised cosine) method was too slow on the Pi's CPU. The large buffer size was letting it build up a large array of samples to transmit but the RRC method couldn't keep up, causing gaps longer than what was being transmitted. I decided to create a dummy signal generator instead. This would transmit QPSK with the same bandwidth as UTSC but with no real data. This was done by filling the data buffer with random bytes and using a bool variable called rrcRanOnce. I ran the RRC method once and set the variable to true, and then I had an "if" block that kept it from running again after that. This let me transmit the same RRC-filtered samples in a loop, producing a smooth QPSK signal on the Pi.

On Windows, my code originally had a GUI but I changed to a command-line project because I wanted to print debug information. I added methods to create UTSC packets and do the interleaving and de-interleaving. I wrote the output to a file and verified it in a hex editor. I also added command-line switches so I could use it outside of Visual Studio.

My transmitter is called UTSCTransmitterCli.exe and takes arguments such as an input file and the channel to use. UTSC is meant for the 902-928 MHz band. Each signal takes up about 850 kHz, so there's space for 30 channels. Here's the current UTSC air interface specification.

Intended band: 902-928 MHz
Bandwidth: 843.75 kHz
Modulation: QPSK (or Ï€/4 QPSK)
Symbol rate: 625 kilosymbols/sec
Rolloff: 0.35
Total data rate: 1.25 megabits/sec
FEC: LDPC, 4/5 (250 kilobits/sec)
Usable data rate: 1 megabit/sec

My transmitter uses π/4 QPSK. To achieve this, I duplicated the QPSK symbol array in my code and rotated each one by π/4 radians (45 degrees). Then, for each bit pair, the code checks if the index is odd or even and uses a ternary operator to choose the array that the symbol comes from.

As I said, my app takes an input file and transmits it without any processing. I have an option to create a file with UTSC packets but you can transmit anything you want. If the file is highly random, like if it's compressed, then the signal will be smooth but if not, then there will be patterns based on the content. Here are some examples.

A 7-zip file

A WAV file with music

A Visual Studio 2013 ISO image

Having visible patterns isn't desirable because they could violate power spectral density requirements. Here's what a basic UTSC signal without video would look like without any padding or interleaving.


The empty timeslots with spikes are the empty space for video that is zeroed out. Here's what it looks like when the empty space is filled with random bytes.


Notice the timeslots with peaks. That's from the WAV audio (8 bits, 44.1 kHz). With this method you can see how much of the packet is taken up by sound.

In this case the peaks aren't that bad but even if we were operating within the rules for PSD, there's another problem. If you live in the US then you probably have smart energy meters transmitting in this band. Those can briefly interfere with the signal. If we assume that a burst lasts 20 ms, then it could corrupt 25,000 bits (0.02 seconds * 1250000 bits/second) or 3125 bytes. This could mean the difference between a visible image or blocky colorful garbage, or it could cause bursts of noise in the audio.

To solve this, UTSC uses an interleaver. This is a scrambler that randomly and uniformly rearranges the data bit by bit at the transmitter and restores it at the receiver. If a burst of noise damages the scrambled data, the damage will be spread very evenly over the packet after it's unscrambled, which is not only easier to fix with error correction, but also produces audio that sounds better than bursts of noise if the error correction fails.

Here is the same broadcast from the last picture but with the interleaver enabled.


As I said earlier, the interleaver scrambles bit-by-bit. For example, bit 1633 in a plain packet would end up as bit 32 in an interleaved one, bit 952430 would become bit 33, and so on. Bits 0-31 inclusive are taken by the "UTSC" sync header. I generated a lookup table for this and it's defined in interleaver.h in my project.

Now that I've explained how this works, here's the full UTSC broadcast sequence.

(audio, video, EPG, files, etc.)->[packet muxer]->[FEC generator]->[interleaver]->[transmitter]

I don't have a FEC generator yet so I use random bytes as a placeholder.

Conclusion

I want it to be as easy as possible for people to get started with UTSC so I'm starting what I call the UTSC Ecosystem Project. It's a collection of guides and open-source programs for setting up a station. The goal is for anyone to be able to start with a PC or Raspberry Pi and a LimeSDR and be broadcasting in about 15 minutes instead of needing a week of free time and a PhD in Linux as is the case for too many open source projects.

Monday, December 16, 2019

MP3 player bug (RCA M6204-B)

Tonight I tried to put music on my RCA M6204-B MP3 player but when I tried to play it, it said the music section was empty.

TL;DR If your RCA MP3 player says the music section is empty even though you know it's not, make sure the MUSIC folder has at least 14 audio files. If that fails, split your music into at least 14 subfolders.

Full story:

This issue didn't make sense but I thought maybe I needed to use RCA easyRip. After installing that I had the same problem. I tried putting music directly in the MUSIC folder and a subfolder in MUSIC, making sure it was formatted as FAT32, formatting it in Windows and from its Settings menu, and trying MP3's from various sources. Nothing worked. I found other people online with this issue but most of the results were on fixya.com where they suggested calling a support number.

Fortunately, before clearing my player I had saved everything to a 7-zip file. I deleted everything and extracted the file onto the player and it worked. I thought there was some kind of database that the official RCA app populates when it transfers music, but the manual says you can copy music in Windows Explorer so that didn't make sense, but it was still worth trying. RCA easyRip was able to copy the music and list it when I restarted the program, so it should have worked but it still didn't.

Finally I copied everything from the 7-zip file onto the player again and decided to delete some of the music folders until the player said it was empty. I eventually discovered that the player requires the MUSIC folder to have at least 14 files, or folders with files, before it will recognize any music.

Tuesday, November 5, 2019

Purse.io review

Recently I became interested in growing grain so I decided to buy 3 types of grain seed on Amazon and try them out. Since I didn't have a credit or debit card at the time I placed the order, I used a platform called Purse.io to buy from Amazon using cryptocurrency. While most people think of Bitcoin when they hear "cryptocurrency", I actually used Bitcoin Cash (BCH) because it has lower fees.

I decided that I wanted wheat, barley, and rye seeds so I found them on Amazon and copy-pasted their URL's into Purse.io. The checkout process was quick and easy. I kept the discount slider at the lowest setting of 5% so it would be shipped immediately. Then I chose Bitcoin Cash from a drop-down menu and was given a QR code. I used the Electron Cash desktop wallet and scanned the QR code with a webcam. This populated the "address" and "amount" fields in the wallet, so all I had to do was quickly verify the info and click Send. Bitcoin Cash is designed to finalize payments in seconds and the website responded quickly once I sent the money.

It cost 98.2089 mBCH (milli-Bitcoin Cash) or 0.0982089 BCH if you don't like the mBCH unit. Bitcoin Cash was about $289 when I placed the order so the equivalent price in USD was $28.57.

I placed the order on Tuesday, October 29, 2019. Purse.io ordered the products from Amazon on Friday, November 1 and the package arrived on Tuesday, November 5.

Some people are concerned that Purse.io is a scam, so I decided to document my success.