## Setting Carrier to Noise Ratio in Simulations

April 11, 2021

When simulating digital receivers, we often want to check performance with added Gaussian noise.  In this article, I’ll derive the simple equations for the rms noise level needed to produce a desired carrier to noise ratio (CNR or C/N).  I also provide a short Matlab function to generate a noise vector of the desired level for a given signal vector.

Definition of C/N

The Carrier to noise ratio is defined as the ratio of average signal power to noise power for a modulated...

## Update to a Narrow Bandpass Filter in Octave or Matlab

March 29, 2021

Following my earlier blog post (June 2020) featuring a Narrow Bandpass Filter, I’ve had some useful feedback and suggestions. This has inspired me to come up with an updated version, incorporating the following changes compared to the earlier one :

• Simpler code in Octave or Matlab
• Float32 precision replaces float64
• Faster processing by a factor of at least 4 times
• Easier setup of input parameters
• Normalized signal output level

A new experimental version in...

## Add a Power Marker to a Power Spectral Density (PSD) Plot

February 7, 2021

Perhaps we should call most Power Spectral Density (PSD) calculations relative PSD, because usually we don’t have to worry about absolute power levels.  However, for cases (e.g., measurements or simulations) where we are concerned with absolute power, it would be nice to be able to display it on a PSD plot.  Unfortunately, you can’t read the power directly from the plot.  For example, the plotted spectral peak of a narrowband signal, such as a sinewave, is lower than the...

## Compute Images/Aliases of CIC Interpolators/Decimators

November 1, 20202 comments

Cascade-Integrator-Comb (CIC) filters are efficient fixed-point interpolators or decimators.  For these filters, all coefficients are equal to 1, and there are no multipliers.  They are typically used when a large change in sample rate is needed.  This article provides two very simple Matlab functions that can be used to compute the spectral images of CIC interpolators and the aliases of CIC decimators.

1.  CIC Interpolators

Figure 1 shows three interpolate-by-M...

## Third-Order Distortion of a Digitally-Modulated Signal

June 9, 2020
Analog designers are always harping about amplifier third-order distortion.  Why?  In this article, we’ll look at why third-order distortion is important, and simulate a QAM signal with third-order distortion.

In the following analysis, we assume that signal phase at the amplifier output is not a function of amplitude.  With this assumption, the output y of a non-ideal amplifier can be written as a power series of the input signal x:

y=...

## A Narrow Bandpass Filter in Octave or Matlab

June 1, 20206 comments

The design of a very narrow bandpass FIR filter, coded in either Octave or Matlab, can prove challenging if a computationally-efficient  filter is required. This is especially true if the sampling rate is high relative to the filter's center frequency. The most obvious filter design methods, using either window-based or Remez ( Parks-McClellan ) functions, can easily result in filters with many thousands of taps.

The filter to be described reduces the computational effort (and thus...

## Second Order Discrete-Time System Demonstration

April 1, 2020

Discrete-time systems are remarkable:  the time response can be computed from mere difference equations, and the coefficients ai, bi of these equations are also the coefficients of H(z).  Here, I try to illustrate this remarkableness by converting a continuous-time second-order system to an approximately equivalent discrete-time system.  With a discrete-time model, we can then easily compute the time response to any input.  But note that the goal here is as much to...

## A Simplified Matlab Function for Power Spectral Density

March 3, 20204 comments

In an earlier post [1], I showed how to compute power spectral density (PSD) of a discrete-time signal using the Matlab function pwelch [2].  Pwelch is a useful function because it gives the correct output, and it has the option to average multiple Discrete Fourier Transforms (DFTs).  However, a typical function call has five arguments, and it can be hard to remember how to set them all and how they default.

In this post, I create a simplified PSD function by putting a...

## Fractional Delay FIR Filters

February 9, 202012 comments

Consider the following Finite Impulse Response (FIR) coefficients:

b = [b0 b1 b2 b1 b0]

These coefficients form a 5-tap symmetrical FIR filter having constant group delay [1,2] over 0 to fs/2 of:

D = (ntaps – 1)/2 = 2      samples

For a symmetrical filter with an odd number of taps, the group delay is always an integer number of samples, while for one with an even number of taps, the group delay is always an integer + 0.5 samples.  Can we design a filter...

## Model Signal Impairments at Complex Baseband

December 11, 20192 comments

In this article, we develop complex-baseband models for several signal impairments: interfering carrier, multipath, phase noise, and Gaussian noise.  To provide concrete examples, we’ll apply the impairments to a QAM system. The impairment models are Matlab functions that each use at most seven lines of code.  Although our example system is QAM, the models can be used for any complex-baseband signal.

I used a very simple complex-baseband model of a QAM system in my last

## Design IIR Butterworth Filters Using 12 Lines of Code

December 10, 201712 comments

While there are plenty of canned functions to design Butterworth IIR filters [1], it’s instructive and not that complicated to design them from scratch.  You can do it in 12 lines of Matlab code.  In this article, we’ll create a Matlab function butter_synth.m to design lowpass Butterworth filters of any order.  Here is an example function call for a 5th order filter:

N= 5 % Filter order fc= 10; % Hz cutoff freq fs= 100; % Hz sample freq [b,a]=...

## Delay estimation by FFT

September 22, 200750 comments
Given x=sig(t) and y=ref(t), returns [c, ref(t+delta), delta)] = fitSignal(y, x);:Estimates and corrects delay and scaling factor between two signals Code snippet

This article relates to the Matlab / Octave code snippet: Delay estimation with subsample resolution It explains the algorithm and the design decisions behind it.

Introduction

There are many DSP-related problems, where an unknown timing between two signals needs to be determined and corrected, for example, radar, sonar,...

## Use Matlab Function pwelch to Find Power Spectral Density – or Do It Yourself

January 13, 201933 comments

In my last post, we saw that finding the spectrum of a signal requires several steps beyond computing the discrete Fourier transform (DFT)[1].  These include windowing the signal, taking the magnitude-squared of the DFT, and computing the vector of frequencies.  The Matlab function pwelch [2] performs all these steps, and it also has the option to use DFT averaging to compute the so-called Welch power spectral density estimate [3,4].

## Design IIR Bandpass Filters

January 6, 201810 comments

In this post, I present a method to design Butterworth IIR bandpass filters.  My previous post [1] covered lowpass IIR filter design, and provided a Matlab function to design them.  Here, we’ll do the same thing for IIR bandpass filters, with a Matlab function bp_synth.m.  Here is an example function call for a bandpass filter based on a 3rd order lowpass prototype:

N= 3; % order of prototype LPF fcenter= 22.5; % Hz center frequency, Hz bw= 5; ...

## Design IIR Filters Using Cascaded Biquads

February 11, 201824 comments

This article shows how to implement a Butterworth IIR lowpass filter as a cascade of second-order IIR filters, or biquads.  We’ll derive how to calculate the coefficients of the biquads and do some examples using a Matlab function biquad_synth provided in the Appendix.  Although we’ll be designing Butterworth filters, the approach applies to any all-pole lowpass filter (Chebyshev, Bessel, etc).  As we’ll see, the cascaded-biquad design is less sensitive to coefficient...

## Digital PLL's -- Part 1

June 7, 201622 comments
1. Introduction

Figure 1.1 is a block diagram of a digital PLL (DPLL).  The purpose of the DPLL is to lock the phase of a numerically controlled oscillator (NCO) to a reference signal.  The loop includes a phase detector to compute phase error and a loop filter to set loop dynamic performance.  The output of the loop filter controls the frequency and phase of the NCO, driving the phase error to zero.

One application of the DPLL is to recover the timing in a digital...

## Time Machine, Anyone?

March 7, 20086 comments

Abstract: Dispersive linear systems with negative group delay have caused much confusion in the past. Some claim that they violate causality, others that they are the cause of superluminal tunneling. Can we really receive messages before they are sent? This article aims at pouring oil in the fire and causing yet more confusion :-).

Introduction

In this article we reproduce the results of a physical experiment...

## Plotting Discrete-Time Signals

September 15, 20195 comments

A discrete-time sinusoid can have frequency up to just shy of half the sample frequency.  But if you try to plot the sinusoid, the result is not always recognizable.  For example, if you plot a 9 Hz sinusoid sampled at 100 Hz, you get the result shown in the top of Figure 1, which looks like a sine.  But if you plot a 35 Hz sinusoid sampled at 100 Hz, you get the bottom graph, which does not look like a sine when you connect the dots.  We typically want the plot of a...

## TCP/IP interface (Matlab/Octave)

June 17, 201210 comments

Communicate with measurement instruments via Ethernet (no-toolbox-Matlab or Octave)

Purpose

Measurement automation is digital signal processing in a wider sense: Getting a digital signal from an analog world usually involves some measurement instruments, for example a spectrum analyzer. Modern instruments, and also many off-the-shelf prototyping boards such as FPGA cards [1] or microcontrollers [2] are able to communicate via Ethernet. Here, I provide some basic mex-functions (compiled C...

## A poor man's Simulink

January 24, 20153 comments

Glue between Octave and NGSPICE for discrete- and continuous time cosimulation (download) Keywords: Octave, SPICE, Simulink

Introduction

Many DSP problems have close ties with the analog world. For example, a switched-mode audio power amplifier uses a digital control loop to open and close power transistors driving an analog filter. There are commercial tools for digital-analog cosimulation: Simulink comes to mind, and mainstream EDA vendors support VHDL-AMS or Verilog-A in their...