Multirate filter¶
Introduction¶
Multirate systems are discrete systems containing signals with different sampling rates (SR) are called multirate systems. In most cases, systems that vary the sampling rate of the input signal are considered. It can be increased and decreased by an integer number of times, as well as changed by a fractional number of times (m/n
, where m
and n
are integers). On the example of this model we will consider the classical problem of changing the PD by a fractional number of times, and also learn why we need a filter.

The model consists of the discrete sinusoidal signal source block DSP Sine Wave
, the block of increasing PD by an integer factor Upsample
, the block of decreasing PD by an integer factor Downsample
, and the filter block Discrete FIR Filter
, which is initially inactive (the signal passes through the block without changes). The original discrete sinusoid is a signal with a fundamental frequency of 5 Hz and a sampling frequency of 100 Hz.
Block Upsample
increases the PD by a factor of 5 in a very simple way - by adding four extra zeros between the samples of the incoming sinusoid.
The Downsample
block thins the samples of the incoming signal by removing (in our case) every second sample.
Thus we want to increase the PD of the sinusoid by 2.5 times.
On the Отладка
tab in the model we highlight the PD of blocks and signals with different colours.
When we run the model for simulation, we can observe in the window Графики
signals in the time domain.
Note that the original signal looks like a discrete (stepped) sinusoid, while the model output (a signal with a PD of 250 Hz) is an emission with zeros between them.
the output of the model (250 Hz PD signal) is an emission with zeros in between.

Blocks Upsample
and Downsample
- implement simple digital algorithms that change PD.
But they do not perform interpolation and decimation in the usual sense.
To understand how the block helps in such operations.
Discrete FIR Filter
let's first look at what happens
to the spectrum of the signal as the PD is raised and lowered.
Spectral copies and aliasing when changing the sampling rate¶
To do this, let's use the built-in interactive tool for
visualisation of the signal spectrum in the window Графики
, by selecting
in Меню сигналов
: Сигналы в частотной области
. Successively we will
display the signals (it is important to realise that for a correct display
signals must have the same sampling frequency on the same axes).
First, we will display the spectrum of the original discrete sinusoid. Let's make sure
that the peak of the spectrum is at 5 Hz, and the X-axis of the graph
lies between 0 and 50 Hz (i.e. up to half of the sampling frequency):

Now let us consider the signal spectrum after increasing the PD by a factor of 5:

The spectrum of a discrete signal is inherently periodic,
and as we expand the Nyquist zone of frequency observation
to a new value of half the PD, we start to see
spectral copies of our signal.
In our case, sinusoids are seen at frequencies of 5 Hz, 95 Hz,
105 Hz, 195 Hz, 205 Hz.
And when we further narrow the spectrum after surgery.
Downsample
these copies
are "wrapped" into a new Nyquist zone, which is now limited
to 125 Hz. This is the aliasing effect:

It's the presence of spectral copies in the output signal that
determines its shape - emissions with zeros. In essence, this is
a complex periodic signal formed by the sum of basic signals -
sinusoids.
We can't eliminate them completely, but we can suppress them
them with the right low-pass filter. This filter
is called an anti-imaging or anti-aliasing filter.
It is always placed after the operation Upsample
and before the
the operation Downsample
.
Designing a low-pass filter¶
Our task is to develop a suitable prototype (specification) of the
of the filter and put its coefficients
in the block Discrete FIR Filter
.
Taking into account that the original signal can lie in the range of
0 to 50 Hz, we choose a filter cutoff frequency of 50 Hz,
the Kaiser window function, the normalised width of the
of the transition band, as well as the required suppression
in the fence band. Also note that
the specification we choose is for a sampling rate of 500 Hz,
since this is the signal that enters the filter input:
We now calculate and display the amplitude-frequency response (AFR) of the
amplitude-frequency response (AFR) of the filter to verify its
ability to suppress spectral copies above 50 Hz:
A 50th order filter was synthesised using the chosen specification.
The shape of its frequency response, although it does not perfectly pass all frequencies of interest.
frequencies of interest, but for the current task - suppression of the interfering ones - it is suitable. The coefficients of the filter
coefficients are already included in the model block, so we don't have to transfer them unnecessarily.
Applying a low-pass filter¶
In the model, we right-click
on the filter block and select Включить блок
.
After that we run the model again for simulation,
and look at the spectrum of the two signals - at the input and output of the
of the filter:

As we can see, the spectral copies are suppressed relative to the
5 Hz sinusoid by more than 70 dB. It can also be seen that
the 5 Hz sine wave in the output signal has a higher
higher power. We purposely multiply the filter coefficients by 5,
because adding zeros with the Upsample
operation reduces
the energy of the signal by a factor of 5.
Now let's take a look
at the shape of the output signal in the time domain:

It corresponds in amplitude to the input signal, it also has a
a fundamental frequency of 5Hz, its sampling rate is 250Hz,
and its waveform is now a sine wave.
But we can also see that it's delayed relative to the input signal
by a quarter of a period. This is the effect of using a FIR filter that's 50 samples long.
50 samples - such filters are bound to introduce delay.
Conclusion¶
In this example, we have looked at the basic principles of changing the frequency of
sampling frequency in digital devices, the effects of imaging and aliasing,
the necessity of using low-pass filters.
{"id": "45efdf54-c19b-4cc5-9088-1b8c91e35a4c", "data": [{"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"y": 0.5086805555555556, "title": {"text": ""}, "len": 0.8657316272965879, "x": 0.9934383202099738}, "name": "y1", "yaxis": "y", "legendgroup": "y1", "line": {"color": "rgba(0, 154, 250, 1.000)", "shape": "linear", "dash": "solid", "width": 3}, "y": [3.085847892970513e-14, -0.00011210023287660044, -0.00043092244829811123, -0.0009064401614189235, -0.0014630177253497658, -0.0020100435135047964, -0.0024549583945451233, -0.0027170506232217445, -0.0027402317516797277, -0.0025030496734284946, -0.002024440123877383, -0.0013641506932753305, -0.0006173539565997627, 9.635713684051953e-05, 0.0006486953226935865, 0.0009215711831913667, 0.0008270470548014514, 0.0003258643303886475, -0.0005581224320988112, -0.0017302176490670569, -0.003026178516567129, -0.004224304761324765, -0.005069328988199746, -0.00530814781398967, -0.004736333325138025, -0.003253216585594843, -0.0009222599572737066, 0.0019674246913233707, 0.004843054085475994, 0.006798310389009561, 0.006555780597017497, 0.0024448090262391238, -0.00760355803357986, -0.026044492881874045, -0.055691737713378694, -0.09967730785349657, -0.16140240264477085, -0.24448381064501268, -0.3527000339602071, -0.4899408905428613, -0.6601636193198053, -0.8673576605355413, -1.1155194466278318, -1.408637817833299, -1.7506901327466804, -2.1456488027711895, -2.5974978400325046, -3.1102590553612646, -3.688027757066879, -4.335018168751491, -5.055619305141716, -5.854462739432301, -6.736504614097489, -7.707125482172809, -8.77225327453627, -9.938517130029505, -11.213443430020199, -12.605710876828592, -14.125490118146455, -15.784907542417523, -17.598696765172793, -19.58514347845662, -21.7675073618527, -24.176257616560296, -26.852779313279804, -29.855939223645077, -33.27475622938271, -37.255844218852104, -42.07358563411895, -48.364152678415415, -58.46185810091349, -69.90124856764837, -59.85383079122976, -58.75529846120951, -60.48238151576528, -64.97054891594684, -77.20322708961228, -72.27200719859866, -65.58036590520308, -63.2813441532728, -62.84311486875752, -63.75895153554512, -66.08821940360724, -70.59215119821387, -82.03054308243013, -78.17479515692894, -70.77762060949476, -67.90032725914898, -66.80647007776724, -66.90309804314592, -68.07847048729916, -70.53987796270928, -75.15922158022215, -87.35630561130691, -81.65472208874203, -74.47695720247778, -71.50272709881881, -70.22178683424713, -70.05909111028134, -70.87770718211199, -72.79582545909012, -76.3455397555556, -83.77990922784696, -92.50228224342894, -79.67832593822514, -75.50184702250546, -73.53603413647359, -72.8120246514407, -73.05368337221154, -74.24928970375113, -76.63880292081055, -81.0683357791438, -92.3744346134342, -88.16154870669459, -80.46779897052977, -77.21024045471941, -75.65679154837159, -75.1890391566119, -75.63254867754318, -77.03274942456594, -79.70655016557568, -84.75908578473857, -101.14111300265976, -88.23922082227392, -81.92521223281412, -79.04086188116383, -77.66696352498377, -77.31117847606815, -77.84126748086075, -79.3286384107798, -82.12807455903098, -87.48583047672744, -108.62597086348191, -89.49715959436865, -83.6252946505943, -80.86597630662438, -79.54435858460738, -79.21162970807677, -79.74947372832696, -81.23508583488763, -84.02588219893808, -89.36850499014878, -110.43957778111192, -91.3535287303663, -85.45401948079743, -82.66508821073138, -81.30924946594584, -80.93550984207664, -81.42163129694188, -82.83598809798463, -85.51076096496502, -90.57853419928692, -107.52603908948045, -93.6991876727914, -87.39662143038521, -84.45346465288708, -82.99328475961225, -82.52644579243565, -82.91274301990762, -84.2008406981976, -86.67889433385585, -91.3011732398534, -104.16257992310811, -96.64636489485832, -89.48722190071754, -86.26304017346108, -84.63174869084897, -84.0244289545474, -84.26923183995326, -85.38663621588694, -87.61029352721572, -91.69797504917936, -101.4553590663789, -100.6049064066176, -91.80323487011196, -88.13922606445706, -86.2628697444762, -85.46676683861257, -85.53090778682218, -86.44010989708589, -88.36914556681138, -91.89062246001646, -99.36586456892897, -106.97558394744516, -94.48884470741946, -90.14584868686471, -87.93027106728323, -86.89016416351095, -86.73311648914377, -87.39996393552772, -89.00568182139068, -91.9626161682211, -97.7329059149184, -139.40488588365653, -97.83532060815729, -92.37958752087481, -89.68828131401972, -88.33367118773072, -87.90896218338865, -88.29897463020046, -89.55876518776864, -91.96814777456483, -96.42818894902454, -108.26589901034255, -102.58072092548875, -95.00519016482545, -91.61213139770962, -89.84302121202296, -89.09178221732098, -89.1659851855993, -90.05854753233314, -91.94127774420477, -95.36203005881558, -102.50512643663453, -111.97671934626021, -98.35444386625483, -93.81930147115551, -91.47781128741642, -90.31828009648812, -90.02786437679887, -90.52885303143196, -91.90300782945583, -94.4721997726266, -99.28543905520436, -113.90334556019238, -103.30627191645142, -96.5216300530279, -93.32509083615902, -91.63312152408379, -90.91160096152282, -90.98918346603358, -91.86608564359884, -93.71454136464374, -97.07217787765728, -104.04655010601809, -114.4546815005092, -100.18590895020745, -95.529142194589, -93.0967103727076, -91.84684032564176, -91.4563793039025, -91.83805715905189, -93.05665946525832, -95.38997825802353, -99.70905920849582, -110.92985726351796, -106.29082738546863, -98.3700989905737, -94.80027427792751, -92.86943029513422, -91.94603454008933, -91.82311100182329, -92.47379121228411, -94.02711898581799, -96.89982692567476, -102.54053436489608, -377.5782501264819], "type": "scatter", "x": [0, 0.9765625, 1.953125, 2.9296875, 3.90625, 4.8828125, 5.859375, 6.8359375, 7.8125, 8.7890625, 9.765625, 10.7421875, 11.71875, 12.6953125, 13.671875, 14.6484375, 15.625, 16.6015625, 17.578125, 18.5546875, 19.53125, 20.5078125, 21.484375, 22.4609375, 23.4375, 24.4140625, 25.390625, 26.3671875, 27.34375, 28.3203125, 29.296875, 30.2734375, 31.25, 32.2265625, 33.203125, 34.1796875, 35.15625, 36.1328125, 37.109375, 38.0859375, 39.0625, 40.0390625, 41.015625, 41.9921875, 42.96875, 43.9453125, 44.921875, 45.8984375, 46.875, 47.8515625, 48.828125, 49.8046875, 50.78125, 51.7578125, 52.734375, 53.7109375, 54.6875, 55.6640625, 56.640625, 57.6171875, 58.59375, 59.5703125, 60.546875, 61.5234375, 62.5, 63.4765625, 64.453125, 65.4296875, 66.40625, 67.3828125, 68.359375, 69.3359375, 70.3125, 71.2890625, 72.265625, 73.2421875, 74.21875, 75.1953125, 76.171875, 77.1484375, 78.125, 79.1015625, 80.078125, 81.0546875, 82.03125, 83.0078125, 83.984375, 84.9609375, 85.9375, 86.9140625, 87.890625, 88.8671875, 89.84375, 90.8203125, 91.796875, 92.7734375, 93.75, 94.7265625, 95.703125, 96.6796875, 97.65625, 98.6328125, 99.609375, 100.5859375, 101.5625, 102.5390625, 103.515625, 104.4921875, 105.46875, 106.4453125, 107.421875, 108.3984375, 109.375, 110.3515625, 111.328125, 112.3046875, 113.28125, 114.2578125, 115.234375, 116.2109375, 117.1875, 118.1640625, 119.140625, 120.1171875, 121.09375, 122.0703125, 123.046875, 124.0234375, 125, 125.9765625, 126.953125, 127.9296875, 128.90625, 129.8828125, 130.859375, 131.8359375, 132.8125, 133.7890625, 134.765625, 135.7421875, 136.71875, 137.6953125, 138.671875, 139.6484375, 140.625, 141.6015625, 142.578125, 143.5546875, 144.53125, 145.5078125, 146.484375, 147.4609375, 148.4375, 149.4140625, 150.390625, 151.3671875, 152.34375, 153.3203125, 154.296875, 155.2734375, 156.25, 157.2265625, 158.203125, 159.1796875, 160.15625, 161.1328125, 162.109375, 163.0859375, 164.0625, 165.0390625, 166.015625, 166.9921875, 167.96875, 168.9453125, 169.921875, 170.8984375, 171.875, 172.8515625, 173.828125, 174.8046875, 175.78125, 176.7578125, 177.734375, 178.7109375, 179.6875, 180.6640625, 181.640625, 182.6171875, 183.59375, 184.5703125, 185.546875, 186.5234375, 187.5, 188.4765625, 189.453125, 190.4296875, 191.40625, 192.3828125, 193.359375, 194.3359375, 195.3125, 196.2890625, 197.265625, 198.2421875, 199.21875, 200.1953125, 201.171875, 202.1484375, 203.125, 204.1015625, 205.078125, 206.0546875, 207.03125, 208.0078125, 208.984375, 209.9609375, 210.9375, 211.9140625, 212.890625, 213.8671875, 214.84375, 215.8203125, 216.796875, 217.7734375, 218.75, 219.7265625, 220.703125, 221.6796875, 222.65625, 223.6328125, 224.609375, 225.5859375, 226.5625, 227.5390625, 228.515625, 229.4921875, 230.46875, 231.4453125, 232.421875, 233.3984375, 234.375, 235.3515625, 236.328125, 237.3046875, 238.28125, 239.2578125, 240.234375, 241.2109375, 242.1875, 243.1640625, 244.140625, 245.1171875, 246.09375, 247.0703125, 248.046875, 249.0234375, 250], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 257, "currentCount": 257}}}], "config": {"showlegend": true, "xaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [0, 50, 100, 150, 200, 250], "range": [-7.5, 257.5], "domain": [0.09128390201224845, 0.9934383202099738], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["0", "50", "100", "150", "200", "250"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "Частота, Гц", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [{"yanchor": "top", "xanchor": "center", "rotation": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 20}, "yref": "paper", "showarrow": false, "text": "АЧХ фильтра нижних частот", "xref": "paper", "x": 0.5423611111111111}], "height": 400, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "yaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [-100, -75, -50, -25, 0], "range": [-120, 10], "domain": [0.07581474190726165, 0.9415463692038496], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["-100", "-75", "-50", "-25", "0"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "Амплитуда, дБ", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "legend": {"yanchor": "auto", "xanchor": "auto", "bordercolor": "rgba(0, 0, 0, 1)", "bgcolor": "rgba(255, 255, 255, 1.000)", "borderwidth": 1, "tracegroupgap": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}, "text": ""}, "traceorder": "normal", "x": 1}, "width": 899.5}}