9 Star 72 Fork 27

ZZH-Finalize / 信号实验箱

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
readme_en.md 9.43 KB
一键复制 编辑 原始数据 按行查看 历史
ZZH-Finalize 提交于 2024-03-29 09:49 . fix typo issues for readme_en.md

Signal Test Box

This is a signal calculation/drawing software based on expression, the main function is to sample the signal given by an expression or a function, then execute the calculation of the sample sequences, and draw the results into the diagram. Using the shared library to extend functions is supported.

This software supports multiple platforms deployment, this feature mainly benefits from QT cross-platform API and CMake multiple platforms build ability, you could build applications of different platforms on one host. Currently, the Ubuntu 22.04(based on Win11 WSL2)、Win7/Win10/Win11、Android x86/Android armeabi-v7a(based on Win11 WSA and Realme X2 Pro) is tested passed

This software supports translations, powered by the QT linguist tool. Currently have Chinese simplified translate data(using English in software is default, then use translate data to translate, this is the solution recommended by the QT linguist module), if you want to add more language support, you could use the QT linguist tool to generate .ts file of this project, such as this file ui/zh_CN.ts, then translate the item in the .ts file manually, finally release this .ts file to .qm file.

The Software will get system locale information at launch time, therefore it can automatically match your system language setting. If your setting is an unsupported language, it will display in English.

If you have questions about using this software、reading the code or building this project, please leave an issue, I will handle it if I see it.

1. Simple demo

Right-click in signal list widget(long press for Android), select Add Signal in the popup, input a signal expression, set the Sample Rate and the Sample Points, click calculate button then you can see the wave.
signal0
signal1

Signal can nested use, to make it easy to use multiple signals to calculate, maximum nest level is 32.
signal2

Except sin and cos, some other functions could be used, such as the software random number function(rand) and the hardware random number function(hrand).
signal3
signal4

Fourier transforms, calling length function is because the fft function outputs complex number, the length function is to calculate the length of a complex number, therefore it could calculate the amplitude spectrum.
input signal
amplitude spectrum

The filters library has serval filter functions, lpf and hpf are IIR filters, they are low pass filters and high pass filters. Receive a sample sequence and a stop frequency as arguments, 'fir` is a FIR filter, receive a sample sequence、a filter order and a filter coefficient (can export by Matlab) as arguments.

There are 1 order IIR low pass filter、3 order IIR low pass filter and 32 order FIR low pass filter demo, For more information about the filter, please check out 10. Filter guide

OrigSig
IIR_filter1
IIR_filter2
FIR_filter

You can see, that the higher order of the filter has a better effect by analyzing the spectrum diagram of the signal after the filter.

2. Working Principle

  1. A signal could be defined by an expression f, at any moment t, signal amplitude is f(t)
  2. If given a moment t, the result of the expression f(t) is the sample value of signal f at the time t
  3. t could be calculated by software using Sample Rate, then repeat calculate N times, N is the Sample Points setting.
  4. The software will convert the expression into a grammar tree by using the built-in compiler.
  5. Before calculating the value of every node, it will calculate the value of the sub-node, therefore, the value of the root node is the value of the whole expression.
  6. If a signal references another signal, the inside signal will be calculated first
  7. Signals have a maximum nest limitation, to prevent signal reference itself or multiple signal cross reference causes the infinite recursion.

3. The definition of signal

In this software, all the signal is defined as an expression, such as sin(t) is the sin signal, and sin(100*t) + sin(200*t) is adding two different signals with different frequencies together.

A signal can reference another signal, such as sig0 = sin(100*t) sig1 = sin(200*t) sig2 = sig0+sig1

The signal reference itself or multiple signal cross-reference will trigger the maximum nest limit

4. Spectrum mode

After using fft function to calculate the Fourier transformation of a signal, if you only use length function to calculate the amplitude spectrum, the X axis of the diagram is the index of the data point, such as the following diagram.

iir_freq_index

You can see that the position of the crosshairs is X coordinate 10, this is the index of that data point in the sample sequence, if you want to know the frequency of this point, you need to calculate it by yourself, we know X=10, the sample rate is 5KHz, sample point is 256, so the frequency of this point is 5000/256*10=195.3Hz, it represents the 200Hz frequency in the original signal. Although doing that calculation is simple, it is also annoying, and all of the arguments we use to calculate are also in the software, so, you could check the spectrum mode checkbox in the lower right corner to make the software calculate instead of us.

After checking the spectrum mode checkbox, the X axis will be the actual frequency, such as in the following diagram. It is the signal we used in the diagram above, but the spectrum mode checkbox is checked, you can see that the position of the crosshairs is X coordinate 195.313, which is the same as our calculation result.

IIR_freq1

Something you need to know is, that the spectrum mode actually displays the first half of calculated data, it means if the sample points are 1024, the diagram will display the first 512 data points, this is because the spectrum is symmetrical, so only need the first half data is enough to analyze.

Another thing is, that the fft function only outputs half of the spectrum, this is also using the symmetrical spectrum. Such as we assume the sample point is 1024, the 1024 real number input to the fft function will get 512 complex numbers (still are 1024 float variables, but half of them is the real part, other half is the imaginary part), and after calling the length`` function, will get 512 real number, therefore, if you dont use the spectrum mode, you will find that all the last half of the diagram is zero, that is because of the diagram displays 1024 data points but we actually have only 512 data. If you use the spectrum mode, based on what I said above, the diagram will display 512 data points, this is a way to make full use of the display space to display valuable data.

5. Built-in compiler

This software has a built-in compiler, it supports common math expressions、double-slash single-line comments and if condition expressions.

Math expressions are the simplest math equations, such as (sin(t)+cos(t+3))*6

Double-slash single-line comments are the same as in C programming language, such as sin(t)//sin of t, chars after the double-slash is ignored by the compiler.

if condition expressions have the same logic as C programming language, but do not use ?:symbols and use **if** and **else** keywords, the grammar order is also different, actually, this is the same design as Python, the grammar rule ismath expression + if keyword + compare expression [+ else keyword + math expression]`, the content surrounded by the square bracket is optional, such as:

  1. 5 if index > 15 else 3//equals to index > 15 ? 5 : 3 in C
  2. 5 if index > 15//omit else sub expression, equals to index > 15 ? 5 : 0 in C

Combine if condition expression and index variable can generate step signal and impulse signal very easily, such as:

  1. 1 if index >= 0//unit step signal
  2. 1 if index == 0//unit impulse signal
  3. 1 if index >= 5//step signal with right shift 5
  4. 1 if index == 5//impulse signal with right shift 5
  5. 5 if index >= 0//step signal with amplitude is 5
  6. 5 if index == 0//step signal with amplitude is 5

The compiler supports these variables:

  1. t , represents the time, it is n divides fs, t = n/fs
  2. index , represents the index of samples, it is what we say n, such as the sample points is 1024, so index is the sequence of [0-1023].

The compiler supports a constant pi, representing the value of pi.

The compiler is case insensitive, pi equals PI Pi pI, and t is also equal to T.

6. Function library

7. Workspace

8. Release Versions

9. Build the source code

9.1. Recommended way

9.2. Manual way

10. Filter guide

11. Android build guide

C++
1
https://gitee.com/finalize/signal-test-box.git
git@gitee.com:finalize/signal-test-box.git
finalize
signal-test-box
信号实验箱
master

搜索帮助