An square waveform signal is a signal that has two values that are -A and. The classic square wave signal which should be properly called square has the same half-periods. The signal can be created using sawtooth signal through thresholding. Positive amplitudes are converted into +A values and negative amplified values are converted to -A. For thresholding , we can use an logical condition that is y>0, return logical values True or False. It is possible to convert Boolean numbers can be converted into numerical values (numpy.astype) 1, 1 and 0 , respectively. To convert them to numbers +1 and -1 you need to multiply the two values by 2. Then subtract 1.

```
square = (saw >= 0).astype(np.int) * 2 - 1
plt.plot(n, square)
plt.xlabel('samlple no.')
plt.ylabel('amplitude')
plt.title('Square Signal)
plt.show()
```

Above square wave signal is characterized by the aspect ratio commonly called fill rate, which is 0.5, i.e., half of the signal is taken up by the positive side. It is possible that a square waveform can also have an additional form factor. It is possible to take it into consideration by correcting for any offset in the signal. Below is an example of the aspect ratio to be 0.8.

```
b = 0.8
phase = ((n * 2 * f / fs + 1) % 2) + (b - 1)
square08 = (phase >= 0).astype(np.int) * 2 - 1
plt.plot(n, square08)
plt.xlabel('sample no.')
plt.ylabel('amplitude')
plt.title('Square signal, form factor 0,8')
plt.show()
```

## Square wave FFT

Fast Fourier Transform (FFT) it is an algorithm which simplifies and reduces the amount of calculations required to determine the DFT. The algorithm is based on the use of matrix notes to describe DFT transform followed by an even distribution of points which approximate the waveform. The matrix used in calculation could then be divided into multiple sparse matrices (with an abundance of zeros) which greatly simplifies the process.

### Generating Periodic Signals Using FFT

The frequency of harmonics as well as other regular signals can be created by creating the desired spectrum by computing the reverse Fourier transform. The main drawback of this method is that it’s impossible to determine any signal frequency. The frequencies are determined by the dimensions of the transform as well as the sampling rate. To obtain any signal frequency is a matter of interpolation. The advantage of this method is that it is more efficient than for the additive method (especially when you must determine a large number of elements) in addition to the option of creating signals that have any spectrum.

For starters, let’s look at an a sinusoidal signal. We’re looking for to create N sample of this signal and therefore, we need N values from the spectrum. Because we are making an actual signal that is real, we only need to define one-half that of spectrum and utilize numpy.fft.irfft. numpy.fft.irfft function. In particular, we require N/2+1 values in the spectrum which are: the first value indicates what is known as the DC component, and the last value is what is known as the Nyquist value (for simplicity, we assume that N is equal) and the other values define the magnitude (and the phase) and phase of signal components. The spectrum value with the index K represents the signal component having a frequency kfs/N.

Create the buffer N/2+1 that is filled with zeros, ensuring that we will use complex numbers. The magnitude of the signal should be at least 1. Because it is true that sine components of the signal has to be visible twice within the spectrum so we must divide the amplitude into two. This component, called the sinusoidal one is portion of the complex spectrum pulse, consequently the the spectral component has to be at least -0.5j. Inserting this value into the subscript k=1 yields one phase of the signal and the subscript nk yields the frequency of n times. After having calculated IFFT and removing the imaginary portion that is residual it is still necessary to increase the signal magnitude using the an equation N (function irfft splits the result by the magnitude of the transform).

A regular square signal (with the aspect ratio being 0.5).

In order to calculate the square wave signal that has a shape factor B, it’s crucial to keep in mind that components in the Fourier series are depicted by cosines. Therefore, we must determine the actual amplitudes of the components of the spectral spectrum. Furthermore it is essential to change the results on the scale of amplitude, which is accomplished with changing an DC component to 2b-1.

## Square wave spectrum

To gain details about the various elements of a complex waveform it is necessary to perform a spectrum (frequency) study of the frequency signal taken from the measurement must be carried out. Analyzing signals may be carried out in a digital, analog or mixed ways. Analog signal processing is performed with spectrum analyzers. It could be a collection of filters having various pass frequencies as well as narrow band filters that are tunable. Digital processing is the use of Fast Fourier Transform (FFT) is the most frequently used. A periodic function is represented by the form of a Fourier series is the equivalent of breaking down it into constituent functions which include The constant part a0 as well as the harmonic components that have two pulsations: ω1, 2ω1, 3ω1, …, nω1, where ω1 is the fundamental pulsation and nω1 are the harmonic pulsations, n is a natural number. The fundamental pulsation is determined by the formula.

where: T – period of the function

The equation describing the periodic waveform x(t) by means of the Fourier series has the form.

Effectiveness of Fourier series a0, bn are determined by analyzing the equation of the waveform is established or based on the results of measurements made with the aid of a harmonic analyzer. For instance, a periodic signal that is in the form of a square waveform can be represented as an infinite trigonometric sequence that includes odd harmonics (1 3, 5, 7, …) with decreasing magnitudes. This is an illustration of the signal in the time domain.

Periodic signals may also be graphically represented within the frequency range. The abscissa axis has used the frequency f (or the pulsation of 2pf ). In the coordinate axis, the magnitudes or the ratios of magnitudes. The width of the bars is proportional to the magnitude of the amplitudes of related square wave harmonics that are present in the signal being studied. The graph is referred to as the spectrum of amplitude spectrum also known as the frequency spectrum. Spectrums that are periodic signal components have discrete however, spectra of non-periodic signal (e.g. stochastic or impulsive signal) are continuous.

## Square wave harmonics

A square wave is the superposition of several sine waves with odd harmonics of the fundamental frequency. The intensity of every harmonic ininversely proportional to the frequency. Similar to triangular and sawtooth waves are also composed of square wave harmonics which are different frequencies from frequencies that are fundamental. A pulse is a collection of all frequencies that are possible to represent in a size of sample as well as the quantity of samples. The frequencies of tapered signals are discrete that fall within a particular interval. The frequency of these signals is determined by the size of the sample for the beginning and ending frequencies as well as the amount of samples.

The most commonly used test signals apart from the sine wave are not able to provide the full control of their spectral properties. For instance the square wave harmonics are fixed in frequency, phase and amplitude with respect to fundamental. In contrast multi-tone signals may be produced with a set frequency and amplitude for each individual component’s frequency. Multi-tone signal is a combination of many sine waves or tones with distinct phase, amplitude and frequency. Multi-tone signal is normally created in a manner that the total amount of cycles in each tone is recorded into the signal. If the speedy Fourier transformation of the whole multi-tone signal is calculated, each tone is mapped precisely into a specific frequency band. This means there isn’t any spectral spread or leakage. Multi-tone signals are a part of numerous test specifications and enable systems to trigger rapidly and effectively over all frequencies. Multi-tone test signals can be used to measure what frequency range is appropriate for devices when it is properly selected. selection, can be used to determine things like cross-modulation interference.

References:

https://sound.eti.pg.gda.pl/~greg/dsp/06-GenerowanieSygnalow.html

https://home.agh.edu.pl/~mgi/instrukcje/LAB_1_Transformacja_FFT_Filtracja_Moc_sygna%B3u-student.pdf

http://www.kdm.p.lodz.pl/wyklady/lab/Cwiczenie8.pdf

http://www.prz.rzeszow.pl/kpe/materialy/astadler/DAQWWW/LabVIEW/Dataprocessing/Sygna%B3ytestowe/index.html