International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

Introduction to : sampled signals

E. Tikhonov and M. Sneps-Sneppe

Abstract — The article introduces the theoretical illustration figures to all parts) are collected in the foundations of the modern method of storing, transmitting and Appendix. processing signals: digital processing. It’s a way to use relatively small number of values instead of continuous real II. DIGITAL VOICE TRANSMISSION signal. For example, when transmitting information in telephony, The basic concept of telephone communication is the so- speech is concentrated in the bandwidth up to 4 kHz. But we called channel of tone frequency. Why? Formants of voice need doubled frequency 8 kHz sampling in digital form. This is that determining speech intelligibility are located mainly in a fundamental requirement. the frequency range from 300 to 3 400 Hz. So for the analog The reason is that the sampled signal is not just a set of voice telephony, the band frequency 4 kHz is usually quantities, but a set of short scaled pulses of large value. allocated for transmission of each channel [6]. Resulting spectrum has multiple copies of original one Currently, signal processing is usually done digitally - on infinitely duplicated on sampling frequency steps. If these digital computers (or specialized digital processors). They copies do not overlap significant (due to the limited original do spectral analysis, filtering, storage and transmission in useful spectrum) we could restore initial signal with filtering digital form [3]. That means only a certain set of signal just one of them. That’s why doubled sampling frequency is needed. values are selected from the real signal - samples. If the number of samples used is finite (as in the real cases), If we use the digital transmission, then according to the then we can use only an equal number of samples of the Kotelnikov theorem one should take the sampling rate of spectrum (or even a half of them). It’s enough for restoring. 8 000 counts per second (8 kHz) - twice as much. This is a As in the rest parts of the series, all theoretical ideas are deep and direct consequence of the discrete nature of the illustrated by mathematical rationales and Matlab programs signal obtained from the continuous. that demonstrate the work “in life”. The theorem was proposed and proved by Vladimir Keywords — Data rate, Dirac comb, Discrete Fourier Kotelnikov in 1933 in his work “On the capacity of ether Transform (DFT), discrete-time signal, Fast Fourier and wire in telecommunications”, in which the theorem was Transform (FFT), low pass filter, MatLab, Nyquist–Shannon– formulated as follows: Kotelnikov theorem, RC-circuit, Sampling, sampling theorem, “Any function ( ) consisting of frequencies from 0 to sinc-filter, telephone communication. can be continuously transmitted with any accuracy using 푓 푡 푓퐶 numbers following each other in ” [4]. I. INTRODUCTION 1 The theorem was discovered2푓퐶 by several authors The article continues the introduction to a signal independently. It is thus also known by the names Nyquist– processing tasks for radio astronomy measurements and Shannon–Kotelnikov, and cardinal theorem of interpolation, satellite data collection that could be used in the “Ventspils also sampling theorem, and Whittaker–Shannon International Radio Astronomy Center” of the Ventspils interpolation formula [5]. University of Applied Sciences. In previous papers complex signal representation [1] and spectral analysis principles [2] were discussed. Current article is dedicated to basics of discrete approximations of a signal for digital processing. The rest of the paper is the following. In Section 2 example of digital voice transmit is given (comparing with analogous). Section 3 suggests mathematical description of sampled signal and corresponding spectrum changes. In Section 4 restoring original continuous signal from these samples and in Section 5 restoring the samples from spectrum samples are discussed. All the Matlab codes (used as the examples and produced

Manuscript received May 31, 2019. Eugene Tikhonov is with Ventspils University of Applied Sciences, Fig 1. Pulse-code modulation (PCM) is a method used to 101a Inženieru Street, LV-3601, Ventspils, Latvia (e-mail: digitally represent sampled analog signals. Sampling and [email protected]). quantization of a signal (red) for 4-bit linear pulse-code Manfred Sneps-Sneppe is with Ventspils University of Applied modulation (LPCM). Sciences, 101a Inženieru Street, LV-3601, Ventspils, Latvia (e-mail: [email protected]). 13

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

In previous articles of the series [1] and [2], we used even the smallest continuous variable signal will be “more MatLab scripts that simulates continuous signals by a large powerful” than any number of fixed samples, no matter how number of points. In fact, we intuitively believe that if we many there are. take a lot of samples, we will get the same (or almost the Due to the fact that the samples are just a set of points (or same) result as for a real continuous signal. Is this true, and numbers), we cannot simply use them in the real world how many samples should we get? instead of continuous signals because of their finite value and zero duration. III. DISCRETE SIGNALS Therefore, a discrete signal means a special function that In digital signal processing (for example for digital depends on these number samples, used as the height of the computer processing with quantized time ticks) we have a corresponding delta functions, following each other after a deal with not continuous in time analog signal ( ), but with sampling time interval T: discrete signal (or discrete-time signal) – set or sequence of ( ) = ∞ ( ) signal value samples set in different times { 푠}[6]푡 . In most useful cases each value set at equal time intervals T 푠푎푚푝푙푒푑 푛 푛 푠 푡 � 푠 훿 푡 − 푛푇 (sampling time): 푠 a) Signal continuous s(t) 푛=−∞ b) Signal values s(nT) 1.5 1.5 = ( × ) Also data values of such signal could be not continuous 1 1 푛 but also discrete (they푠 can푠 only푇 푛take on one of a finite 0.5 0.5 Value Value number of values) – this type of signal is called discrete- 0 0 value signal. Discrete-time discrete-value signal is called -0.5 -0.5 digital signal, and it’s possible values called symbols. 0 1 2 3 0 1 2 3 For the important case, where signal has only 2 possible Time, t Time, t d) Sampled signal s (t) values 0 (“false”) and 1 (“true”) it is called bitstream. c) Sampling comb d(t) sampled Transmitted number in this case represented as a sequence 1.5 1.5 of sequential bits = [0, 1]: 1 1

0.5 0.5 푖 = × 2

푥 Value Value 푘 0 0 If signal takes 2N possible푥 � values푥푘 also say that it contains 푘 -0.5 -0.5 N bits for each symbol (because each symbol could be 0 1 2 3 0 1 2 3 represented as N bits). Bitstream obviously is a sequence of Time, t Time, t

1-bit symbols “0” and “1”. Fig. 2. Example of the sampled signal: the initial continuous Further we will not pay special attention to the signal (a), sampled values of the continuous signal (b), Dirac comb quantification of values, only the discretization of the signal of delta functions - marked with vertical lines with a height equal in time. to the area (c), sampled signal that is Dirac comb scaled with the Parameter of a discrete signal that shows how many samples (d). See Matlab code in Appendix B. values in second contained in a digital signal called signal data rate. Signal bitrate is a number of bits per second in This is an idealized representation, because the delta digital signal (for the case of bitstream is equals to data rate functions are mathematical abstraction. obviously). For example, if { } has K symbols per second Some approximations can also be sequences of pulses (for and each symbol contain M bits, then: data rate is K, bitrate example, short rectangular ones with a large voltage value), 푛 is × . 푠 and the shorter their duration, the less distortions due to their for the voice telephony example discussed earlier, the shape will be introduced. This clearly illustrates the numeric퐾 푀al value of each sample is represented as a 7 or 8-bit definition of the delta function as the limit of suitable pulses, binary code (that means each sample value if from 0 to 127 which we used earlier [2]. or to 255). So in the world of telecommunications there are Instead of infinite summation limits, finite ones can be two transmission systems - at a speed of 56 (8 kHz * 7 bits) used (if the original signal is time limited), for example, or 64 (8 kHz* 8 bits) kbit/s. from 0 to N. In this case, the signal can be considered This is not about the amount of useful information original, defined at infinity, multiplied by a function that contained in the signal in general. An overview of the takes values in the appropriate limits 1, and 0 is outside various encoding and compression methods is not included these limits. in this article devoted only to the transmission of the B. How the signal changes if only samples are used physical values of a given signal. from it A. What is a discrete signal At first sight, we lose an infinite amount of information, The discrete signal fundamentally differs from because there were continuous intervals with an uncountable continuous. It is shown in mathematics that rational numbers number of points, and only individual values remain. (that is, those that can be numbered in principle, even if However, under certain conditions, it is possible to restore there are an infinite number) are fundamentally smaller than the original continuous signal absolutely precisely from this the real numbers (which belong to the values of continuous limited number of points. In practice, even if these signals) that form the "continuum" (continuum) [7]. That is, conditions are not strictly fulfilled, a fairly close result can be obtained. 14

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

To demonstrate that we could use spectral analysis using frequency step and the scale ). [2]. The spectrum is one-to-one identifies 2휋 √2휋 the signal. So if the spectra of the two signals are the same, 푇 푇 then the signals are the same. Therefore, we consider what happens to the signal spectrum, if only samples have been selected from it. We can write the function of a discrete signal as a product of the original continuous signal by a special function:

( ) = ( ) × ∞ ( )

푠푎푚푝푙푒푑 푠 푡 푠 푡 � 훿 (푡)− 푛푇 ( ) 푛�=�−�∞�������� This function used for sampling푑 푡is called the Dirac comb: 푑 푡 ( ) = ∞ ( × ) ,

The spectrum푑 푡 of the� product훿 푡 − 푇 of푛 two푟 ∈signals푍 (Fourier 푛=−∞ transform) is the already known operation of of the original signals (with some scaling): Fig. 3. Dirac comb in time space временном (a) and frequency 1 space (b). See Matlab code in Appendix C. ( ) = ( ) ( ) ( ) = ∞ ( ) 2 −푗휔푡 Filtering property of the delta function means that 푠 푡 푓 푡 푔 푡 ↔ 푆 휔 � 푠 푡 푒 푑푡 convolution with it shifts the function to a given point. 1 √ 휋 −∞ = ∞ ( ) ( ) Therefore, the spectrum of the sampled signal is original 2 −푗휔푡 continuous signal spectrum scaled by and copied with a � 푓 푡 푔 푡 푒 푑푡 1 √ 휋 −∞ 1 1 step of equals to the sampling frequency푇√2휋 : = ∞ ( ) ∞ ( ) 2휋 1 2 ⎡ 2 ⎤ 푇 ( ) = × ( )( ) ⎢ +푗푢푡 ⎥ −푗휔푡 2 � 푓 푡 ⎢ � 퐺 푢 푒 푑푢⎥ 푒 푑푡 √ 휋 −∞ √ 휋 −∞ 푆푠푎푚푝푙푒푑 휔 1푆 ∗ 퐷 휔 ⎢���������������⎥ 휋= ∞ ( ) ( ) ⎣ 퐼퐹푇 ⎦ 2 1 ( ) = ∞ ( ) ∞ ( ) 2 ⎡ ⎤ 1 � 푆 푢 퐷 휔 − 푢 푑푢 ⎢ −푗 휔−푢 푡 ⎥ = 휋 −∞ � 퐺 푢 � 푓 푡 푒 푑푡 푑푢 2 휋 −∞ ⎢−∞ ⎥ ⎢�������������⎥ 2 1 퐹푇 1 = ∞ ( ) ⎣ ( ) = ×⎦( )( ) × 휋 ∞ ( ) ∞ ( 2 2 √ 휋 2 � 푆 푢 � 훿 휔 − 푢 Therefore,� if퐺 we푢 select퐹 휔 − samples푢 푑푢 from the퐺 signal∗ 퐹 휔(using the 푛=−∞ 휋 −∞ 휋 푇 )−∞ Dirac Comb), the total spectrum will be a convolution of the 휋 original spectrum with the Comb spectrum. − 1푛 푑푢 = 푇 ∞ ∞ ( ) ( What is the Dirac Comb spectrum: 2 1 2 � � 푆 푢 훿 휔 − 푢 ( ) = ∞ ( ) 푇 휋) 푛=−∞ −∞ 2 √ −푗휔푡 휋 퐷 휔 � 푑 푡 푒 푑푡 − 1푛 푑푢 2 √ 휋 −∞ 1 = 푇 ∞ = ∞ ∞ ( × ) 2 2 휋 −푗휔푡 � 푆 �휔 − 푛� 푑푢 � � 훿 푡 − 푇 푛 푒 푑푡 푇√ 휋 푛=−∞ 푇 √1휋 −∞ 푛=−∞ = ∞ ∞ ( × ) 2 −푗휔푡 � � 훿 푡 − 푇 푛 푒 푑푡 1휋 푛=−∞ −∞ = √ ∞ 2 −푗휔푛푇 � 푒 √��휋��푛=�−�∞����� 2푆푒푒 퐴푝푝푒푛푑푖푥 퐴 2 = ∞ ( ) √ 휋 휋 A detailed calculation of some� 훿 steps휔 − (marked푛 above in the 푇 푛=−∞ 푇 formula) is given in Appendix A. So, the Dirac comb in time (with the time step T and the scale 1) is a Dirac comb in frequencies space (with the

15

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

Fig. 4. Single rectangular pulse signal sampling: continuous signal, samples and sampled signal (a), spectrum of the original signal (b), spectrum of the sampled signal (c). See Matlab code in Appendix D.

IV. KOTELNIKOV THEOREM: CONTINUOUS SIGNAL RECOVERY FROM THE SAMPLES As we see the spectrum of sampled (discretized) signal is different from the original continuous. In the general case, the copies of a spectrum are superimposed on each other and distort so that it is impossible to obtain the original back (to restore the continuous signal). However, for example, if the step between copies of the spectra (equal to the sampling frequency) is large enough compared to the width of the spectrum itself, they can be divided (by filtering all but one copy). Since the copies are located at a distance of the sampling frequency from each other, the width of the spectrum of the continuous2휋 signal 푇 should be 2 times smaller than this step so that they do not overlap. This is the essence of Kotelnikov's theorem. A. Restoring with the ideal low pass filter To do this, we can apply an ideal low-pass filter (leaving only frequencies from 0 to ) or a band-pass filter (extracting the shifted spectrum from other copies), for example: Ω 16

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

( ) = ( ) × ( ) × 2 a) Signal s(t) and restored s*(t) 1.2 Where is the transfer ratio (the value at the 푆푟푒푠푡표푟푒푑 휔 푆푠푎푚푝푙푒푑 휔 퐻푙표푤푝푎푠푠 푤 푇√ 휋 s(t) 1 sinc(t-0) output of the푙표푤푝푎푠푠 filter divided by the value at the input): 퐻 1, | | < sinc(t-0.25) ( ) sinc(t-0.5) = 0.8 0, | | sinc(t-0.75) Impulse response푙표푤푝푎푠푠 (inversed Fourier transform)휔 훺 for it: sinc(t-1) 퐻 휔 � sinc(t-1.25) 휔 ≥ Ω 0.6 1 1 sinc(t-1.5) ( ) = Ω = sinc(t-1.75) 2 2 푗Ω푡 −푗Ω푡 0.4 sinc(t-2) 푗휔푡 푒 − 푒 Value sinc(t-2.25) sinc(t-2.5) ℎ 푡 � 푒 푑휔 sin 0.2 √ 휋 −Ω = ×√ 휋 푗푡 sinc(t-2.75) 2 sinc(t-3) 2Ω Ω푡 0 s (t) This filter is called “ideal low pass filter” or “sinc-filter” restored √ 휋 Ω푡 samples because of sinc-function ( ( ) = ). Unfortunately, it -0.2 sin 푥 couldn’t be realized in practice – because it is infinite in 푠푖푛푐 푥 푥 -0.4 time (in the future and in the past). -3 -2 -1 0 1 2 3 Spectra multiplication is equivalent to signal convolution: Time t, sec.

1 b) Spectrums ( ) = ( ) ( ) ( ) = ∞ ( ) 2 2 푗휔푡 푆 휔 퐹 휔 퐺 휔 ↔ 푠 푡 � 푆 휔 푒 푑휔 1 √ 휋 −∞ = ∞ ( ) ( ) 1.5 2 푗휔푡 � 퐹 휔 퐺 휔 푒 푑휔 S(f) S (f) √ 휋 −∞ 1 discrete 1 1 Sinc H(f) = ∞ ( ) ∞ ( ) 2 ⎡ 2 ⎤ ⎢ −푗휔휏 ⎥ 푗휔푡 � 퐹 휔 ⎢ � 푔 휏 푒 푑휏⎥ 푒 푑휔 0.5 √ 휋 −∞ ⎢√��휋��−�∞����������⎥ Spectrum value ⎣ 퐹푇 ⎦ 1 ( ) = ∞ ( ) ∞ ( ) 2 ⎡ ⎤ 0 ⎢ 푗휔 푡−휏 ⎥ � 푔 휏 � 퐹 휔 푒 푑휔 푑휏 휋 −∞ ⎢−∞ ⎥ ⎢�������������⎥ 1 퐼퐹푇 1 -0.5 = ∞ ( ) ⎣( ) = ( ⎦ )( ) -6 -4 -2 0 2 4 6 2 2 Frequency F, Hz Thus, the� signal푔 휏 푓restored푡 − 휏 푑휏by this frequency푔 ∗ 푓 푡 filtration: Fig. 5. The original continuous rectangular single pulse 휋 −∞ 휋 1 signal recovery from the samples: the original and ( ) = 2 × ∞ ( ) ( ) reconstructed signal (a), the spectra of the original signal, 2 the sampled signal and the filter (b). See Matlab code in 푠 푡 푇√ 휋 � 푠푠푎푚푝푙푒푑 휏 ℎ 푡 − 휏 푑휏 휋 −∞ Appendix E. = ∞ ∞ ( ) × 2 2 B. Restoring with not ideal low pass filter 푇 푛 2Ω sin (� �) 푠 훿 휏 − 푛푇 An ideal low-pass filter (sinc-filter) is not physically × √ 휋 −∞ 푛=−∞ √ 휋 ( ) realizable, since the sinc-function has non-zero values for all Ω 푡 − 휏 time points up to infinity, and the of an T 푑휏 = Ω 푡∞− 휏 ∞ ( ideal filter is not zero for times less than zero. It can only be used mathematically. Ω 푛 sin� 푠( � 훿) 휏 For example, consider the signal restoration using the 휋 )푛=−∞ −∞ ( ) simplest low-pass filter - RC circuit from the article [1] Ω 푡 − 휏 − 푛푇T sin푑휏( ( )) = ∞Ω 푡 −( 휏 ) ( ) Ω Ω 푡 − 푛푇 � 푠 푛푇 T In order to avoid the휋 푛imposition=−∞ of Ωspectra푡 − 푛푇 is necessary. This is the mathematical formulation of 휋the ≤ Ω Kotelnikov theorem.

Fig. 6. RC circuit and its time and vector diagrams

17

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

The amplification spectrum (dependence of the output signal (b). See Matlab code in Appendix F. voltage, that is, the capacitor on the input voltage for each individual frequency of the input signal) depends on the It can be seen that although RC-circuit is not very good impedances: low-pass filter. The level of power decreasing by a factor 1 of 2 (that is, the voltage amplitude 2 times lesser) is 1 ( ) = = = = achieved at a frequency = , this can be considered as + (1 + ) 1 + 1 √ 푈퐶 푍퐶 푗휔퐶 a conditional filtering boundary. Module퐻 휔 (absolute value without phases) of this transfer Ω 푅퐶 푈푖푛 푍푅 푍퐶 푅 푗휔푅퐶 푗휔푅퐶 For recovery, we can also directly simulate the physical characteristic: processes in the circuit over time. As discussed in the first 1 | ( )| == part of the article series the currents and voltages are 1 + ( )2 related:

a) RC-response H(w)=U /U 퐻 휔 c ( ) ( ) ( ) 1 ( ) ( ) � 휔푅퐶 = = = H(w) abs 퐶 퐶 0.5 퐸 푡 − 푈 푡 푑푈 푡 w So state푅 changing depends on the퐶 current state: cutoff

|H(w)| 푖 푡 푖 푡 퐶 0 푅 ( ) ( ) 푑푡 -40 -30 -20 -10 0 10 20 30 40 ( ) = Frequency w, rad/sec 퐶 We can assume퐶 the capacitor퐸 푡 − 푈is 푡initially discharged: 2 푑푈 푡 푑푡 (0) = 0 푅С H(w) angle . 0 w cutoff Of course, it is also necessary to replace the abstract delta 퐶 -2 functions,푈 for example, with a pulse of finite duration and angle, rad/sec -40 -30 -20 -10 0 10 20 30 40 Frequency w, rad/sec value (so that their product is single). Also, the simulation 1 time will not be continuous, but divided into many small H(w) real H(w) imag steps. 0 w cutoff a) Voltages in RC-circuit Re, Im w U -1 cutoff continuous Samples U -40 -30 -20 -10 0 10 20 30 40 sampled U restored 4 U Frequency w, rad/sec sinc

3 b) Spectrums 2

2 S(w)

S (w) Voltages u(t), V 1 restored

1 Re 0

0

-1

-1 -40 -30 -20 -10 0 10 20 30 40 0 0.5 1 1.5 2 2.5 3 Time t, sec. Frequency w, rad/sec 2 Fig. 8. Physical modeling of RC-circuit processing of a sampled

S (w) discrete signal sequence. See Matlab code in Appendix G. 1 H(w)

Re The principle of operation of the RC-circuit is clearly 0 seen: each pulse of the comb, due to its very large value, very quickly affects the charge of the capacitor (raising it to -1 -40 -30 -20 -10 0 10 20 30 40 a significant level). After that, the capacitor discharges more Frequency w, rad/sec slowly (because of its accumulated voltage is less than

prompting pulse) until the next correction pulse, which c) Restored signal charges it again, and so on. s(t) s (t) Although the signal differs from the original, but it still 5 restored reminds him.

4 In practice, much better low-pass filters are used, which give a result quite close to a sinc-filter.

3 V. DISCRETE FOURIER TRANSFORM - DISCRETE

Value 2 SPECTRUM FOR A FINITE NUMBER OF SAMPLES Summary, the spectrum of the sampled signal (peaks of 1 the sequence of delta functions scaled to the samples values)

0 is continuous, as is the original; and differs because of multiple copies at a distance corresponding to the

-1 time/sample rate. -5 -4 -3 -2 -1 0 1 2 3 4 5 From these samples, the original continuous signal can be Time t, sec accurately restored in some conditions. Fig. 7. The RC circuit can be used as a simple low pass filter: response spectrum (a) and a recovered sampled rectangular pulse But is it possible to discretize the spectrum so that it

18

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019 represents only a set of samples also? In this case, we again 1 , 1 will not have to deal with continuous functions and we will 푁−1 = 1 푁 be able to process them on digital devices. 푘 − 푎 , = 1 푘 ≠ The spectrum can be calculated from the readings � 푎 � − 푎 푘=0 1 ( )× directly: 푁 푘 2휋 = 푗 푚−푛 푁 , 1푁 1 − 푒 , = ( ) = ∞ ( ) � 푚 ≠ 푛 − 푎 2 −푗휔푡 푠푎푚푝푙푒푑 푠 0 푁 푚 푛 푆 휔 � 푠 푡 푒 푑푡 1 1 √ 휋 −∞ = ( ) = ∞ ( ) ∞ ( ) ⎧1������푖푛푡푒푔푒푟��� 2 ⎪ ����������� , = −푗휔푡 1푗2휋 푚−푛 � 푠 푡 � 훿 푡 − 푛푇 푒 푑푡 ⎨ − 푒 , = √1휋 −∞ 푛 −∞ 0, 푚 ≠ 푛 = ∞ ∞ ( ) ( ) = ⎪ − 푎 ⎩ , = 푁 푚 푛 2 −푗휔푡 = So: 푚 ≠ 푛 � � 푠 푡 훿 푡 − 푛푇 푒 푑푡 � 1휋 푛 −∞ −∞ 푁 푚 푛 = √ ∞ ( ) j 0, 푁−1 = 푁−1 × = × 2 2휋 , = = − ω푛푇 푗 푘푛 푠 푛푇 푒 푘 푁 푚 푚 ≠ 푛 푛 1 � � 푆 푒 � 푠 � 푁 푠 휋 푛 −∞ j 푘=0 푚=0 푁 푚 푛 = √ ∞ This pair of one-to-one transformations that bind a finite 2 = − ω푛푇 number of samples of a discretized signal and a discretized 푠푛푒 If the number of available� samples is finite (for example, spectrum is called the Discrete Fourier transform (DFT) or √ 휋 푛 −∞ from 0 to N – that we always have in real world), we Discrete in time Fourier transform. respectively change the limits of summation: 1 = 푁−1 j 2휋 ( ) = 푁 −푗� �푘푛 2 푘 푛 푁 =0 − ω푛푇 푆 � 푠 푒 푠푎푚푝푙푒푑 푛 푛1=0 Consider for푆 this case휔 the spectrum� 푠 samples푒 at some = 푁−1 푛 2휋 √ 휋 푗 푘푛 selected frequency points = : 푁 푆푘 That is, we can use푠푛 not �the 푆entire푘푒 continuous spectrum, 2휋푘 푁 푘=0 2 1 휔 푁푇 but only a small set of fixed points in it (number is equals to = = 푁−1 = 푁−1 2휋 2휋 number of time samples), applying transformations and 2 −푗 푘푛푇 −푗� �푘푛 푘 휋푘 푛 푁푇 푛 푁 filters only to them. 푆They푆 are� interesting� �because푠 푒 of all the� samples푠 푒 of the 푁푇 푛=0 푛=0 At the same time, for real-valued signals only one half of original sequence can√ 휋be calculated only from them, without the spectral samples is sufficient for restoring due to the using all the other points and intervals of the continuous conjugate symmetry (exact equality of the i-th and (N-1)-th spectrum: reference):

푁−1 = 푁−1 푁−1 ( ) 2휋 2휋 2휋 = 푁−1 = 푁−1 푗 푘푛 −푗� �푘푚 푗 푘푛 2휋 2휋 푘 푁 푚 푁 푁 −푗� � 푁−푛 푘 −푗2휋푘+푗� �푘푛 � 푆 푒 � � � 푠 푒 � 푒 푁−푘 푛 푁 푛 푁 푘=0 푘=0 푚=0 ( ) 푆 � 푠 푒 � 푠 푒 = 푁−1 푁−1 = 푛=0 푛=0 2휋 = 푁−1 = S 푗 푚−푛 푘 2휋 푚 푁 +푗� �푘푛 ∗ � 푠 � 푒 푛 푁 k 푚=0 푘=0 ( ) Briefly Discrete Fourier� transform푠 푒 also could be written = 푁−1 푁−1 푛=0 2휋 푘 푗 푚−푛 in vector/matrix form: 푚 푁 � 푠 � �푒 � = , where = ( )( ) 푚=0 푘=0 � ������ , 2휋 푎푘 k −푗 푁 푚−1 푛−1 Sum of N numbers (0..N-1) of geometrical������� progression���� a 푚 푛 푔푒표푚푒푡푟푖푐 푝푟표푔푟푒푠푠푖표푛 푠푢푚 푆 퐹�푠 퐹 푒 in last equation is: 푆1 = 푆2 ⎛ 3 ⎞ 푆… 푆 ⎜ 4 ⎟ ⎜푆 ⎟ 1 1 1 … 1 푁 ⎝푆 ⎠ × × ×( ) 1 … 1 2휋 2휋 2휋 푠 −푗 1 −푗 2 −푗 푁−1 = 1 푁 × 푁 × … 푁× ( ) 푠2 ⎛ 푒 2휋 푒 2휋 푒 2휋 ⎞ ⎛ 3 ⎞ … −푗…푁 2 −푗…푁 8 −푗 푁 2 푁−1 푠… ⎜ 푒 푒 푒 ⎟ ⎜ 4 ⎟ ⎜1 ×( ) × ( ) … ×( )( )⎟ ⎜푠 ⎟ 2휋 2휋 ⋱ 2휋 ⋮ −푗 푁−1 −푗 2 푁−1 −푗 푁−1 푁−1 푁 푁 푁 푁 ⎝ 푒 푒 푒 ⎠ ⎝푠 ⎠

19

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

a) Signal s(t) = rectangularPulse(0, 1, t) 1 APPENDIX

Signal s(t) Samples s n 0.8 A. Dirac Comb spectrum calculations Sampled s (t) sampled

1 ± 0.6 ( ) = ∞ = , = 2 −푗휔푛푇 푗휔푇

s(t) 1 2 0.4 퐷 휔 � 푒 �푞 푒 � √ 휋 푛=−∞

0.2 1 ⎡ ⎤ = ⎢ ∞ + ∞ 1 ⎥ 2 푛 −푛 0 ⎢ 1 2 ⎥ -0.5 0 0.5 1 1.5 2 � 푞 � 푞 − 퐶표푟푟푒푠푝표푛푑⏟ 푡표 ⎢ 푛=0 , 푛=0 , ⎥ Time, t (sec) √ 휋 푘=0 ⎢ 퐺푒표푚푒푡푟푖푐푎푙����� 퐺푒표푚푒푡푟푖푐푎푙����� ⎥ ⎢푝푟표푔푟푒푠푠푖표푛 1 푝푟표푔푟푒푠푠푖표푛 2 ⎥ 푃표푠푖푡푖푣푒 푘 푁푒푔푎푡푖푣푒 푘 b) Spectrum S(w) vs FFT ⎣ ⎦ 1 Geometrical progression partial sum: Re S(w) Im S(w) Re FFT = 푛−1 0.5 Im FFT FFT simmetry line 푘 푆푛 � 푞 , = 1 ± = 1 = 2 , 푘=0 0 = 1 푗휔푇 , 1 1 푛 푞 ↔ 푒 ↔ 휔푇 휋푟 푟 ∈ ℤ Re S(f), Im S(f) � − 푞 -0.5 This sum sequence푞 ≠ doesn’t convergent in the usual sense − 푞 because of infinite oscillating. In this cases under the limit

-1 could be understood Cesàro summation (as limit of average -1 0 1 2 3 4 5 6 7 8 9 10 Frequency, f (Hz) partial sum):

Fig. 9. Comparison of spectra: a continuous signal of a à 1 1 rectangular pulse and sampled spectrum frequencies of a sampled ∞ = = lim 푁 = lim 푁 푛 퐶푒푠 푟표 signal. Signal and its discretization shown at (a), and signal 푛 푛 푛 spectrum in comparison with DFT. One can see the symmetry � 푎 퐴 ����� 퐴 푁→∞ � 푆 푁→∞ � � 푎 푘=1 푁 푛=1 푁 푛=1 푘=1 ��� (redundancy) of the DFT and the deviation of the points of the For the case of discussed sequence: 푆푛 spectrum of the discretized signal from the line of the spectrum of ( + 1) 1 2 + 1 the continuous signal due to the imposition of copies. See Matlab 푁 == = , = 2 1 푁 2 code in Appendix H. 푁 = ⎧ 푁 푁 � 푛 ± 휔푇 휋푟 ⎪ 푛=1 1 1 푛 푁 푁 � 푆 푁 ±푗휔푇푛 , There are algorithms that allow to find these spectral 푁 푛=1 1 ⎨ − 푒 samples very quickly Fast Fourier Transform (FFT). The ⎪ � 푗휔푇 푒푙푠푒 Separately operating for case푁 푛= 1 − 푒 2 : number of operations in them can be proportional to log ⎩ for the number of samples N. They are implemented in 1 1 1 휔1푇 ≠ 휋푟 푁 푁 푁 = 푁 = 푁 various software products as standard functions [8]. 1 푛 (1 ) ⎛ 푛 ⎞ 푛 − 푞 � 푆 � ⎜푁 − � 푞 ⎟ VI. CONCLUSION 푁 푛=1 푁 푛=1 − 푞 푁 − 푞 ⎜ 푛=1 ⎟ 퐺푒표푚푒푡푟푖푐푎푙��� 푝푟표푔푟푒푠푠푖표푛 3 1 ⎝ 1 ⎠ Thus, a continuous signal (if it’s spectrum can be limited = (1 ) 1 푁−1 by acceptable bounds) can be turned into a set of samples, − 푞 �푁 − 푞 � from which it can then be restored (if necessary or after 푁 1 − 푞 1 ����−��푞� = 푃푎푟푡푖푎푙 푠푢푚 표푓 3 processing). The number of samples directly depends on the 1 (1 푁−)1 − 푞 selected boundaries of the used signal spectrum. The limit for each progression− is푞: 2 − 푞 푁 − 푞 Moreover, for practical purposes the number of samples 1 will be finite, which means that a finite number of samples lim 푁 of the sampled signal spectrum can be stored or processed. 푛 푁→∞ � 푆 + 1 푁 푛=1 lim = , = 2 Therefore, continuous signals of the real world can be 2 푁 turned into sets of numbers and processed by digital ⎧ 푁→∞ ∞ 휔푇 휋푟 = 1 1 1 <2 1 computing devices, as well as transmitted between them by ⎪ lim × = , (1 ) (1 푁)−1 (1 ± ) any convenient means, including those with suitable ��−��푞��� ⎨ − 푁→∞ 2 푗휔푇 푒푙푠푒 modulation and at suitable frequencies. − 푞 푁 ��−��푞� − 푒 ⎪ 퐶표푛푠푡 ≠0 That is the theme of the next part of article series. The limit of sum��� �of�� Geometrical→�0������ progressions 1 and 2: ⎩ lim ( + 1) = , = 2 1 lim 푁 ( + ) = 1 1 푁→∞ 푁 ∞ 휔푇 휋푟 1 2 + , 푛 푛 (1 ) (1 ) 푁→∞ � 푆 푆 � 푁 푛=1 푗휔푇 −푗휔푇 푒푙푠푒 − 푒 − 푒 Separately operating for case 2 :

휔푇 ≠ 휋푟

20

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

1 1 (1 ) + (1 ) + = (1 ) (1 ) (1 −푗휔푇 )(1 푗휔푇) Tmax = 3; % max plot time − 푒 − 푒 dt = 1/5; % samplting time 푗휔푇 −2푗휔푇 ( + 푗휔푇) −푗휔푇 accuracy = 500; % continuous time steps = − 푒 − 푒1 푗휔푇 − −푒푗휔푇+ − 푒 − 푒 푒 %% Processing −푗휔푇 푗휔푇 0 e = @(t) ones(size(t)); % ones-vector 2 − 푒( +− 푒 ) �푒 timeline = linspace(0, Tmax, 500); % timeline to = =1 1 2 ( 푗휔푇 + −푗휔푇) plot − 푒 푒 t_samples = 0:dt:Tmax; % sampling timeline So, 푗휔푇 −푗휔푇 1 − 푒 푒 %% Plotting ( ) = ∞ figure(); 2 −푗휔푛푇 % plot signal 퐷 휔 � 푒 subplot(2, 2, 1); hold on; grid on; 휋 푛=−∞ 1 1 √ = lim 푁 ( + ) 1 2 1 2 title('a) Signal continuous s(t)'); 푛 푛 xlabel('Time, t'); ylabel('Value'); , �푁→∞ =�2 푆 푆 − � = √ 휋 푁 푛=1 axis([0 Tmax -0.5 1.5]); 0, ∞ 휔푇 휋푟 Let explore integral in� some range around some point plot(timeline, s(timeline), 'DisplayName', 's(t) = 2 , : 푒푙푠푒 signal');

( ) ( ) % plot signal 2휋 2휋 휔푇 푟+휋푟1� 푟 ∈ 푍 1 푟+1� 푇 2 ( ) = 푇 2 ∞ subplot(2, 2, 2); hold on; grid on; 2 −푗휔푛푇 ( � ) 퐷 휔 푑휔 ( � ) � � 푒 � 푑휔 title('b) Signal values s(nT)'); 2휋 2휋 푛=−∞ 푟−1� √ 휋 푟−1� 푇 2 푇 (2 ) xlabel('Time, t'); ylabel('Value'); 2휋 axis([0 Tmax -0.5 1.5]); 1 푟+1� = 푇 2 ∞ + ∞ 2 푗휔푛푇 −푗휔푛푇 ( ) ⎛ scatter(t_samples, s(t_samples), '*', � � 푒 � 푒 'DisplayName', 's(t) signal'); 2휋 ⎜푛=1 푛=1 √ 휋 푟−1� 푇 2 �푃표푠푖푡푖푣푒������푛 �푁푒푔푎푡푖푣푒������푛 ⎝ % plot comb + 1 subplot(2, 2, 3); hold on; grid on; ⎞ 퐶표푟푟푒푠푝표푛푑⏟ 푡표⎟ 푑휔 title('c) Sampling comb d(t)'); 푛=0 ( ) xlabel('Time, t'); ylabel('Value'); 2휋 axis([0 Tmax -0.5 1.5]); 1 ⎠푟+1� = ∞ 푇 2 ( + ) 2 푗휔푛푇 −푗휔푛푇 stem(t_samples, e(t_samples), 'DisplayName', � ( � ) 푒 푒 푑휔 푛=1 2휋 'sampling'); √ 휋 ( 푟+)1� 푇 2 2휋 1 푟+1� + 푇 2 % plot samples 2 subplot(2, 2, 4); hold on; grid on; ( � ) 푑휔 2휋 √ 휋 푟+1�( ) title('d) Sampled signal s_{sampled}(t)'); 푇 2 2 2휋 1 푟+1� cos( ) xlabel('Time, t'); ylabel('Value'); = ∞ 푇 2 + 2 2 2휋 axis([0 Tmax -0.5 1.5]); 휔푛푇 � ( � ) 푑휔 푇 푛=1 2휋 stem(t_samples, s(t_samples), 'DisplayName', √2휋 푟−1� √ 휋 = 푇 2 's_sampled'); √ 휋 C. Matlab code: Dirac comb visualization (Figure 2) 1 1 2 1 + 푇 ∞ sin ( + ) 2 2 2 % Sampling comb visualization 휋

2� 1� � 푟 � 푛푇� √sin휋 푛=1( 푛푇 2) 푇 %% Settings 휋 Tmax = 5; % max plot time, sec − 2 � 푟 − � 푛푇�� = 푇 Fmax = 5; % max plot frequency, Hz dt = 1/2; % sampling time, sec √ 휋 1 1 + 푇 ∞ sin(2 + ) 2 2 %% Processing e = @(t) ones(size(t)); % ones-vector � �����휋푛푟��2���휋푛�� sin√ 휋(2푘=1 푛푇 ) = 0 Wmax = 2*pi*Fmax; % max plot freq., rad/s √ 휋 That is, the area− �(integral)���휋푛푟���−�� 휋푛��of� the function in a dw = 2*pi/dt; % sampling freq., rad/s 0 푇 neighborhood of points where it is nonzero is finite. N_t = floor(Tmax/dt); % number of t-samples So, this is a scaled delta function: N_w = floor(Wmax/dw); % number of w-samples

1 2 2 t_samples = dt*[-N_t:N_t]; % sampling timeline ( ) = ∞ = ∞ 2 w_samples = dw*[-N_w:N_w]; % sampling freq.line −푗휔푛푇 √ 휋 휋 D_scale = sqrt(2*pi)/dt; % frequency scaling 퐷 휔 � 푒 � 훿 �휔 − 푛� B. Matlab√ 휋 code:푛=−∞ Sampling example푇 푛=− (Figure∞ 1) 푇 %% Plotting figure(); % Sampling singnal examle

% plot signal %% Settings subplot(2, 1, 1); hold on; grid on; s = @(t) rectangularPulse(0, 2, t); % signal func

21

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

title('a) Time sampling d(t)'); % min frequency to plot xlabel('Time t, sec.'); ylabel('Value'); w_plot_min = -w_plot_max; axis([-Tmax Tmax -0.5 1.5]); % frequency line to plot w_plot_range = w_plot_min:(w_plot_max- stem(t_samples, e(t_samples), 'DisplayName', 'Time w_plot_min)/1000:w_plot_max; comb d(t)'); % zero-division fix w_plot_range(find(w_plot_range==0))=0.001; text(dt, 1+0.1, '1', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom'); % max frequency for IFT text(dt/2, -0.3, 'T', 'HorizontalAlignment', w_max = 2*pi/(2*t_step); 'center'); % min frequency for IFT line([0 0],[0 -0.3], 'Color', 'r', 'LineStyle','- w_min = -w_max; '); % sampling frequency line([dt dt],[0 -0.3], 'Color', 'r', w_step = 2*pi/t_max; 'LineStyle','-'); % sampled frequenct line line([-.1 dt+.1],[-.2 -.2], 'Color', 'r', w_dicrete = linspace(w_min, w_max, N_samples+3); 'LineStyle','-'); line([-.05 .05],[-.2-.05 -.2+.05], 'Color', 'r', % symbolic variables: time, frequency 'LineStyle','-'); syms t w; line([dt-.05 dt+.05],[-.2-.05 -.2+.05], 'Color', symbolic function of s(t) 'r', 'LineStyle','-'); s_function = rectangularPulse(pulse_start,pulse_duration,t);% % plot spectrum subplot(2, 1, 2); hold on; grid on; %% Processing title('b) Frequency sampling D($\omega$)'); o = @(t) zeros(size(t)); % zero-vector xlabel('Frequency $\omega$, rad/sec.'); e = @(t) ones(size(t)); % ones-vector ylabel('Value'); % signal stem(w_samples, D_scale*e(w_samples), s_continuous = eval(subs(s_function, t, 'DisplayName', 'Frequency comb d(t)'); t_plot_range)); % samples text(dw+0.4, D_scale-0.2, s_samples = eval(subs(s_function, t, t_dicrete)); '${\sqrt{2\pi}}\over{T}$'); % sampled signal text(dw/2, D_scale*-0.3, '${2\pi}\over{T}$', s_dicrete_function = sum((s_samples).*dirac(t- 'HorizontalAlignment', 'center'); t_dicrete)); line([0 0],[0 D_scale*-0.3], 'Color', 'r', 'LineStyle','-'); % Spectrum – symbolic line([dw dw],[0 D_scale*-0.3], 'Color', 'r', S_function = fourier(s_function); 'LineStyle','-'); % Spectrum - array for plot line([D_scale*-.1 dw+D_scale*.1],[D_scale*-.2 S_continuous = eval(subs(S_function, w, D_scale*-.2], 'Color', 'r', 'LineStyle','-'); w_plot_range)); line([D_scale*-.05 D_scale*.05],[D_scale*(-.2-.05) D_scale*(-.2+.05)], 'Color', 'r', 'LineStyle','- % Spectrum discrete - symbolic '); S_dicrete_function = fourier(s_dicrete_function); line([dw-D_scale*.05 dw+D_scale*.05],[D_scale*(- % Spectrum discrete - array for plot normalized .2-.05) D_scale*(-.2+.05)], 'Color', 'r', S_dicrete = eval(subs(S_dicrete_function, w, 'LineStyle','-'); w_plot_range))*t_step;

% Interpreter for special symbols s_restored_function = ifourier(S_disdis_function, set(groot,'defaulttextinterpreter','latex'); t); set(groot,'defaultAxesTickLabelInterpreter','latex s_restored = eval(subs(s_restored_function, t, '); t_plot_range)); set(groot,'defaultLegendInterpreter','latex'); set(findall(gcf,'- yscale=ceil(max(abs(S_dicrete))); property','FontSize'),'FontSize',10) %% a) Signal continuous D. Matlab code: sampled signal spectrum visualization figure(1); grid on; hold on; (Figure 3) axis([-1 t_plot_max -0.5 1.5]);

%% Parameters title(['a) Signal s(t) = ' char(s_function) ', and pulse_start = 0; sampling $s_n$']); pulse_duration = 1; xlabel('Time, t (sec)'); ylabel('s(t)'); N_samples = 10; % number of samples % Signal t_min=0; % min t of a signal plot(t_plot_range, s_continuous, 'LineWidth', 2, t_max=3; % max t of a signal 'DisplayName', 'Signal s(t)');

% Sampling % sampling time scatter(t_dicrete, s_samples, '*', 'k', t_step = t_max/N_samples; 'DisplayName', 'Samples $s_n$'); % sampled timeline quiver(t_dicrete, o(t_dicrete), o(t_dicrete), t_dicrete = linspace(t_min, t_max, N_samples); s_samples, 0, 'k', 'DisplayName', 'Sampled % max time to plot signal $s_{sampled}(t)$'); t_plot_max=5; % timeline to plot signal % Restored t_plot_range = linspace(t_min, t_plot_max, plot(t_plot_range, real(s_restored), 'Color', [.7 N_samples*100); .7 .7], 'DisplayName', 'Restored $s_{restored}(t)$'); % max frequency to plot w_plot_max = 2*(2*pi)/t_step; 22

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

legend('Location', 'best'); max(ylim)], 'Color', 'k', 'LineWidth', 2); line([-2*pi/(2*t_step) -2*pi/(2*t_step)], %% b) Signal spectrum - [min(ylim) max(ylim)], 'Color', 'k', 'LineWidth', % 3D 2); figure(2); grid on; hold on; xlim([w_plot_min w_plot_max]); % Abs view(55, 25); subplot(3, 1, 2); grid on; hold on; title(['b) Spectrum of a signal $S(\omega)$=' xlim([w_plot_min w_plot_max]); char(S_function)]); ylim([-yscale yscale]); xlabel('Frequency $\omega$, rad/s'); ylabel('Re $S(\omega)$'); xlabel('Frequency $\omega$, rad/s'); zlabel('Im $S(\omega)$'); ylabel('Abs S(w)'); plot3(w_plot_range, real(S_continuous), plot(w_plot_range, abs(S_dicrete), 'm'); % Abs imag(S_continuous), 'k'); % 3D curve plot3(w_plot_range, real(S_continuous), - line([2*pi/(2*t_step) 2*pi/(2*t_step)], [min(ylim) e(w_plot_range), 'r'); % Re max(ylim)], 'Color', 'k', 'LineWidth', 2); plot3(w_plot_range, 1.5*e(w_plot_range), line([-2*pi/(2*t_step) -2*pi/(2*t_step)], imag(S_continuous), 'b'); % Im [min(ylim) max(ylim)], 'Color', 'k', 'LineWidth', 2); % 2D figure(3); % Angle xlim([w_plot_min w_plot_max]); subplot(3, 1, 3); grid on; hold on; subplot(3, 1, 1); grid on; hold on; xlim([w_plot_min w_plot_max]); xlabel('Frequency $\omega$, rad/s'); xlabel('Frequency $\omega$, rad/s'); ylabel('Re / Im'); ylabel('Anlge S(w)'); plot(w_plot_range, real(S_continuous), 'r'); % Re plot(w_plot_range, angle(S_dicrete), 'g'); % Ang. plot(w_plot_range, imag(S_continuous), 'b'); % Im line([2*pi/(2*t_step) 2*pi/(2*t_step)], [min(ylim) legend('Re S(w)', 'Im S(w)'); max(ylim)], 'Color', 'k', 'LineWidth', 2); line([-2*pi/(2*t_step) -2*pi/(2*t_step)], subplot(3, 1, 2); grid on; hold on; [min(ylim) max(ylim)], 'Color', 'k', 'LineWidth', xlabel('Frequency $\omega$, rad/s'); 2); ylabel('Abs S(w)'); plot(w_plot_range, abs(S_continuous), 'm'); % Abs %% dicrete spectrum of disceted signal subplot(3, 1, 3); grid on; hold on; figure(6); xlabel('Frequency $\omega$, rad/s'); grid on;hold on; ylabel('Anlge S(w)'); xlim([w_min w_max]);%ylim([-yscale yscale]); plot(w_plot_range, angle(S_continuous), 'g');% Ang title('d) Sampled spectrum of sampled signal'); xlabel('Frequency, w (rad/s)'); %% Spectrum of signal dicrete ylabel('Re Sd(w), Im Sd(w)'); figure(4); grid on; hold on; % dicrete spectrum of dicrete function S_samples = eval(subs(S_dicrete_function, w, xlim([w_plot_min w_plot_max]); w_dicrete))*t_step; % samples normalized view(55, 25); S_disdis_function = sum((S_samples).*dirac(w- w_dicrete))*2; title('c) Spectrum $S_{sampled}(\omega)$ of sampled signal $s_n$'); % Re-Im xlabel('Frequency $\omega$, rad/s'); plot(w_plot_range, real(S_dicrete), 'Color', [1 ylabel('Re $S(\omega)$'); 0.7 0.7]); zlabel('Im $S(\omega)$'); plot(w_plot_range, imag(S_dicrete), 'Color', [0.7 0.7 1]); plot3(w_plot_range, real(S_dicrete), imag(S_dicrete), 'k'); % 3D curve quiver(w_dicrete, o(w_dicrete), o(w_dicrete), plot3(w_plot_range, real(S_dicrete), - real(S_samples), 0, 'r'); e(w_plot_range), 'r'); % Re quiver(w_dicrete, o(w_dicrete), o(w_dicrete), plot3(w_plot_range, 1.5*e(w_plot_range), imag(S_samples), 0, 'b'); imag(S_dicrete), 'b'); % Im %% Design: total figure(5); set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultAxesTickLabelInterpreter','latex % Re - Im '); subplot(3, 1, 1); set(groot,'defaultLegendInterpreter','latex'); grid on; hold on; set(findall(gcf,'- xlim([w_plot_min w_plot_max]); property','FontSize'),'FontSize',10) ylim([-yscale yscale]); xlabel('Frequency, $\omega$ (rad/s)'); E. Matlab code: signal restoring from the samples ylabel('Re / Im $S_{sampled}(\omega)$'); (Figure 4) plot(w_plot_range, real(S_dicrete), 'r'); %% Parameters plot(w_plot_range, imag(S_dicrete), 'b'); syms t w; line([2*pi/(2*t_step) 2*pi/(2*t_step)], [min(ylim)

23

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

s = rectangularPulse(0, 2, t); % signal sym func legend('Location', 'northwest');

Tmax = 3; % max plot time F. Matlab code: RC-response spectrum (Figure 5) Fc = 2; % sampling freq. % RC response spectrum

%% Processing %% Signal parameters o = @(t) zeros(size(t)); % zero-vector syms t;

Wc = 2*pi*Fc; % sampling angular freq. s = rectangularPulse(0, 2, t); % signal sym. Func. dt = 1/2/Fc; % sampling time step Tmax = 3; % max plot time dw = 1/dt; % sampling frequency step Fc = 2; % sampling freq. N = Tmax/dt; % number of samples %% Frequencies plot parameters Mmin = 0; % samples start f0 = -5; % show frequency from, Hz Mmax = Tmax/dt; % sampled finish f1 = 5; % show frequency to, Hz steps = 1000; % frequency accuracy step t_samples = dt*[Mmin:Mmax]; % sampling timeline %% RC-circuit parameters % plot timeline R = 100; % R = 100 Om t_plot = linspace(-Tmax, Tmax, 500); C = 5e-3; % C = 5 mF % plot frequency-line f_plot = linspace(-3*Fc, 3*Fc, 500); %% Processing response

% Spectrum - array for plot % frequency line Sw = eval(subs(fourier(s), w, 2*pi*f_plot)); w = 2*pi*linspace(f0, f1, steps); % % samples w0 = 1/R/C; s_samples = eval(subs(s, t, t_samples)); % sampled signal % response function s_dicrete_function = sum((s_samples).*dirac(t- H = @(w) 1./(1+j*w*R*C); t_samples)); % response vector H_C = H(w); % Spectrum discrete - symbolic S_dicrete_function = fourier(s_dicrete_function); e = @(t) ones(size(t)); % zero-vector % Spectrum discrete - array for plot normalized S_dicrete = eval(subs(S_dicrete_function, w, %% Processing signal spectrum 2*pi*f_plot))*dt; t_plot = linspace(-Tmax, Tmax, 500); % timeline

%% Spectrum dt = 1/2/Fc; % sampling time step figure(); t_samples = dt*[0:Tmax/dt]; % sampling timeline hold on; grid on; S_continuous = eval(fourier(s));% Spectrum array title('b) Spectrums'); xlabel('Frequency F, Hz'); s_samples = eval(subs(s, t, t_samples)); % samples ylabel('Spectrum value'); s_discrete_function = sum((s_samples).*dirac(t- t_samples)); % sampled signal plot3(f_plot, real(Sw), imag(Sw), 'k', 'DisplayName', 'S(f)'); % Spectrum discrete symbolic plot3(f_plot, real(S_dicrete), imag(S_dicrete), S_discrete_function = 'r', 'DisplayName', 'S_{discrete}(f)'); fourier(s_discrete_function); plot([-3*Fc -Fc -Fc Fc Fc 3*Fc], [0 0 % Spectrum discrete max(real(Sw)) max(real(Sw)) 0 0], 'b', S_discrete = eval(S_discrete_function)*dt; 'DisplayName', 'Sinc H(f)'); %% Spectrum legend('Location', 'best'); figure();

%% Signal subplot(2, 1, 1); figure(); hold on; grid on; hold on; grid on; title('b) Spectrums'); title('a) Signal s(t) and restored s*(t)'); xlabel('Frequency w, rad/sec'); xlabel('Time t, sec.'); ylabel('Re'); ylabel('Value'); zlabel('Im'); plot(t_plot, eval(subs(s, t, t_plot)), 'k', plot3(w, real(S_continuous), imag(S_continuous), 'LineWidth', 2, 'DisplayName', 's(t)'); % signal 'k', 'DisplayName', 'S(w)'); plot3(w, real(H(w).*S_discrete), x = o(t_plot); imag(H(w).*S_discrete), 'r', 'DisplayName', for i=Mmin:Mmax 'S_{restored}(w)'); f = eval(subs(s, t, dt*i))*sinc(Wc*(t_plot- dt*i)/pi); legend('Location', 'best'); x = x+f; plot(t_plot, f, ':', 'DisplayName', subplot(2, 1, 2); strcat('sinc(t-', num2str(dt*i),')')); hold on; grid on; end plot(t_plot, x, 'r', 'LineWidth', 2, xlabel('Frequency w, rad/sec'); 'DisplayName', 's_{restored}(t)'); ylabel('Re'); zlabel('Im'); scatter(t_samples, eval(subs(s, t, t_samples)), '*', 'DisplayName', 'samples'); plot3(w, real(S_discrete), imag(S_discrete), 'm', 'DisplayName', 'S_{discrete}(w)'); 24

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

plot3(w, real(H(w)), imag(H(w)), 'b', 'DisplayName', 'H(w)'); U_continuos = eval(subs(U_symbolic, t, t_continuous)); legend('Location', 'best'); U_samples = eval(subs(U_symbolic, t, t_samples));

%% Plotting 2D %% Real delta-output figure(); U_out = o(t_continuous); % Scaled delta grid % Abs for i=0:N_samples subplot(3, 1, 1); current_time = i*dt_sampling; hold on; grid on; U_sample = eval(subs(U_symbolic, t, current_time)); title('a) RC-response H(w)=U_c/U'); U_out = U_out + xlabel('Frequency w, rad/sec'); U_sample*delta_value*rectangularPulse(current_time ylabel('|H(w)|'); , current_time+delta_duration, t_continuous); end plot(w, abs(H_C), 'DisplayName', 'H(w) abs'); stem([-w0 w0], [power(2, -1/2) power(2, -1/2)], %% Processing CR-circuit: step-by-step modeling 'filled', 'DisplayName', 'w_{cutoff}'); U_C = (0); for i = 1:size(U_out, 2)-1 legend('Location', 'best'); dU_C = (U_out(i)-U_C(i))/R/C*dt_continuous; U_C(i+1) = U_C(i)+dU_C; % Abs end subplot(3, 1, 2); hold on; grid on; %% Processing sinc-filter % W_sampling = 2*pi*F_sampling; xlabel('Frequency w, rad/sec'); U_LPF = (0); ylabel('angle, rad/sec'); for i=1:size(U_out, 2) current_time = i/2/F_sampling; plot(w, angle(H_C), 'DisplayName', 'H(w) angle'); f = eval(subs(U_symbolic, t, current_time)) * stem([-w0 w0], [angle(H(-w0)) angle(H(w0))], sinc(2*F_sampling*(t_continuous-current_time)); 'filled', 'DisplayName', 'w_{cutoff}'); U_LPF = U_LPF + f; end legend('Location', 'best'); %% Plot a: RC modeling voltage % Re, Im figure(); subplot(3, 1, 3); hold on; grid on; axis([T_start T_end -1 max(U_C)+1]); % subplot(2, 1, 1); xlabel('Frequency w, rad/sec'); hold on; grid on; ylabel('Re, Im'); title('a) Voltages in RC-circuit'); xlabel('Time t, sec.'); ylabel('Voltages u(t), plot(w, real(H_C), 'DisplayName', 'H(w) real'); V'); plot(w, imag(H_C), 'DisplayName', 'H(w) imag'); stem([-w0 w0], [real(H(-w0)) real(H(w0))], plot(t_continuous, U_continuos, 'DisplayName', 'filled', 'DisplayName', 'w_{cutoff}'); 'U_{continuous}'); stem([-w0 w0], [imag(H(-w0)) imag(H(w0))], stem(t_samples, U_samples, 'DisplayName', 'filled', 'DisplayName', 'w_{cutoff}'); 'Samples'); plot(t_continuous, U_out, 'DisplayName', legend('Location', 'best'); 'U_{sampled}'); plot(t_continuous, U_C, 'DisplayName', G. Matlab code: RC-circuit signal restoring (Figure 6) 'U_{restored}'); % plot %% Time parameters voltage T_start = 0; % start time, sec plot(t_continuous, U_LPF, 'DisplayName', T_end = 3; % finish time, sec 'U_{sinc}'); % plot voltage % continuous time accuracy step dt_continuous = (T_end-T_start)/1000; legend('Location', 'best'); H. Matlab code: comparing continuous spectrum and F_sampling = 2; % sampling frequency, Hz DFT (Figure 7) %% RC parameters figure('units','normalized','outerposition',[0 0 R = 100; % 2 Om 0.5 1]); C = 5e-3; % 5 mF

%% Signal parameters %% Parameters syms t; U_symbolic = rectangularPulse(0, 2, t); % signal %Signal syms t; % t - symbolic variable delta_duration = dt_continuous*5; % delta-impulse % symbolic signal t delta_value = 1/delta_duration; s_function = rectangularPulse(0, 1, t);

%% Processing signal % Symbolic expression, Fourier function % timeline S_function = fourier(s_function); t_continuous = T_start:dt_continuous:T_end; % null time vector % Time parameters o = @(t) zeros(size(t)); N_counts = 20; % number of samples N_plot = 500; % plot accuracy dt_sampling = 1/2/F_sampling; t_samples = T_start:dt_sampling:T_end; N_samples = (T_end-T_start)/dt_sampling; 25

International Journal of Open Information Technologies ISSN: 2307-8162 vol. 7, no.7, 2019

Tmax=2; % plotting start time Tmin=0; % plotting end time % FFT plotting fft_S = fft(s_sampled)/N_counts*2; % Normalization %% Processing scatter(f_samples, real(fft_S), '*', 'r'); % Re % sampling time step scatter(f_samples, imag(fft_S), '*', 'b'); % Im dt = (Tmax-Tmin)/N_counts; % plot timeline % Symmetry line t_plot = linspace(Tmin, Tmax, N_plot); plot([1/2/dt 1/2/dt], [-1 1], 'k'); % sampling timeline t_samples = dt*(0:N_counts-1); legend('Re S(w)', 'Im S(w)', 'Re FFT', 'Im FFT', 'FFT simmetry line'); o = @(t) zeros(size(t)); % zero-vector REFERENCES %% Fourier processing [1] E. Tikhonov, M. Sneps-Sneppe. “Introduction to signal processing: sine wave and complex signals”, International Journal of Open % Plot frequency line Information Technologies, Vol. 7, No 3, March 2019, ISSN 2307- f_plot = linspace(-1/dt, 1/dt, N_plot); 8162. f_plot(f_plot==0)=0.0001; % zero-division fix [2] E. Tikhonov, M. Sneps-Sneppe. “Introduction to signal processing: spectral representation”, International Journal of Open Information % Sampling frequencies Technologies, Vol. 7, No 4, April 2019, ISSN 2307-8162. f_samples = linspace(0, 1/dt, N_counts); [3] Lyons, Richard G., “Understanding digital signal processing”, 3rd ed., Library of Congress Cataloging-in-Publication Data, 1948, ISBN 0- f_samples(f_samples==0)=0.0001;% zero-disivion fix 13-702741-9 [4] Kotelnikov VA, “On the transmission capacity of "ether" and wire in % Evaluate symbolics spectrums electrocommunications”, (English translation, PDF, url: http://ict.open.ac.uk/classics/1.pdf), Izd. Red. Upr. Svyazzi RKKA % Continuous (1933), Reprint in Modern Sampling Theory: Mathematics and w = 2*pi*f_plot; Applications, Editors: J. J. Benedetto und PJSG Ferreira, Birkhauser S_continuous = eval(S_function); (Boston) 2000, ISBN 0-8176-4023-1 [5] Robert J. Marks II, Introduction to Shannon Sampling and

Interpolation Theory, Springer-Verlag, New York, 1991. Available: % Spectrum samples https://marksmannet.com/RobertMarks/REPRINTS/1999_Introductio w = 2*pi*f_samples; nToShannonSamplingAndInterpolationTheory.pdf. Retrieved: May, S_samples = eval(S_function); 2019 [6] Kharkevich A.A., “Essays on the general theory of communication” % Signal sampled (Russian), State publishing house of technical and theoretical s_sampled = eval(subs(s_function, t, t_samples)); literature, Moscow, 1955 [7] Ilyin V.A., Sadovnichy V.A, Sendov Bl.H. "Real Numbers // Mathematical Analysis" (Russian), 3rd ed. pererab. and add. / Ed. %% Signal plot Tikhonov A. N., Prospect, Moscow 2006, ISBN 5-482-00445-7 [8] Emmanuel C. Ifeachor (2011) “Digital Signal Processing A practical subplot(2, 1, 1); approach download”. Prentice Hall; 2 edition (October 7, 2001), grid on; hold on; ISBN-10: 9780201596199 title(['a) Signal s(t) = ' char(s_function)]); xlabel('Time, t (sec)'); ylabel('s(t)');

% signal plot(t_plot, eval(subs(s_function, t, t_plot)), 'k'); % samples scatter(t_samples, s_sampled, '*', 'k'); % sampled signal quiver(t_samples, o(t_samples), o(t_samples), s_sampled, 0, 'm'); legend('Signal s(t)', 'Samples s_n', 'Sampled s_{sampled}(t)');

%% Plot spectrums subplot(2, 1, 2); grid on; hold on; xlim([-1 1/dt]); % limited axes title('b) Spectrum S(w) vs FFT'); xlabel('Frequency, f (Hz)'); ylabel('Re S(f), Im S(f)');

% Spectrum plot(f_plot, real(S_continuous), 'r'); plot(f_plot, imag(S_continuous), 'b'); 26