Discrete Sinusoid

Discrete-time Signals and Systems

Luis Chaparro , in Signals and Systems Using MATLAB (Second Edition), 2015

9.4 What Have We Accomplished? Where Do We Go From Here?

As you saw in this chapter, the theory of discrete-time signals and systems is very similar to the theory of continuous-time signals and systems. Many of the results in the continuous-time theory are changed by replacing integrals by sums, derivatives by differences, and ordinary differential equations by difference equations. However, there are significant differences imposed by the way the discrete-time signals and systems are generated. For instance, the discrete frequency is finite but circular, and it depends on the sampling time. Discrete sinusoids, as another example, are not necessarily periodic. Thus, despite the similarities there are also significant differences between the continuous-time and the discrete-time signals and systems.

Now that we have a basic structure for discrete-time signals and systems, we will start developing the theory of linear time-invariant discrete-time systems. Again you will find a great deal of similarity with the linear time-invariant continuous-time systems but also some very significant differences. Also, notice the relation that exists between the Z-transform and the Fourier representations of discrete-time signals and systems, not only with each other but with the Laplace and Fourier transforms. There is a great deal of connection among all of these transforms, and a clear understanding of this would help you with the analysis and synthesis of discrete-time signals and systems.

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780123948120000097

Sampling Theory

Luis F. Chaparro , in Signals and Systems using MATLAB, 2011

7.4.3 Sampling, Quantizing, and Coding with MATLAB

The conversion of an analog signal into a digital signal consists of three steps: sampling, quantization, and coding. These are the three operations an ADC does. To illustrate them consider a sinusoid x(t) = 4 cos(2πt). Its sampling period, according to the Nyquist sampling rate condition, is

T s π Ω max = 0 . 5 sec/sample

as the maximum frequency of x(t) is Ωmax = 2π. We let T s = 0.01 (sec/sample) to obtain a sampled signal x s (nT s ) = 4 cos(2πnT s ) = 4 cos(2πn /100), a discrete sinusoid of period 100. The following script is used to get the sampled x[n] and the quantized x q [n] signals and the quantization error ε[n] (see Figure 7.13).

Figure 7.13. (a) Sinusoid, (b) sampled sinusoid using T s = 0.01, (c) quantized sinusoid using four levels, and (d) quantization error.

%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Sampling, quantization and coding

%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all; clf

% analog signal

t = 0:0.01:1; x = 4 ∗ sin(2 ∗ pi ∗ t);

% sampled signal

Ts = 0.01; N = length(t); n = 0:N − 1;

xs = 4 ∗ sin(2 ∗ pi ∗ n ∗ Ts);

% quantized signal

Q = 2;   % quantization levels is 2Q

[d,y,e] = quantizer(x,Q);

% binary signal

z = coder(y,d)

The quantization of the sampled signal is implemented with the function quantizer which compares each of the samples x s (nT s ) with four levels and assigns to each the corresponding level. Notice the appproximation of the values given by the quantized signal samples to the actual values of the signal. The difference between the original and the quantized signal, or the quantization error, ε(nT s ), is also computed and shown in Figure 7.13.

function [d,y,e] = quantizer(x,Q)

% Input: x, signal to be quantized at 2Q levels

% Outputs: y quantized signal

%   e, quantization error

%   d quantum

% USE [d,y,e] = quantizer(x,Q)

%

N = length(x);

d = max(abs(x))/Q;

for k = 1:N,

  if x(k)>= 0,

  y(k) = floor(x(k)/d)*d;

  else

  if x(k) == min(x),

  y(k) = (x(k)/abs(x(k))) ∗(floor(abs(x(k))/d) ∗ d);

  else

  y(k) = (x(k)/abs(x(k))) ∗ (floor(abs(x(k))/d) ∗ d + d);

  end

  end

  if y(k) == 2 ∗ d,

  y(k) = d;

  end

end

The binary signal corresponding to the quantized signal is computed using the function coder which assigns the binary codes '10','11','00', and '01' to the four possible levels of the quantizer. The result is a sequence of 0s and 1s, each pair of digits sequentially corresponding to each of the samples of the quantized signal. The following is the function used to effect this coding.

function z1 = coder(y,delta)

% Coder for 4-level quantizer

% input: y quantized signal

% output: z1 binary sequence

% USE z1 = coder(y)

%

z1 = '00'; % starting code

N = length(y);

for n = 1:N,

  y(n)

  if y(n) == delta

  z = '01';

  elseif y(n) == 0

  z = '00';

  elseif y(n) == -delta

  z = '11';

  else

  z = '10';

  end

  z1 = [z1 z];

end

M = length(z1);

z1 = z1(3:M) % get rid of starting code

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780123747167000119

Discrete-Time Signals and Systems

Luis F. Chaparro , Aydin Akan , in Signals and Systems Using MATLAB (Third Edition), 2019

9.2.1 Periodic and Aperiodic Discrete-Time Signals

A discrete-time signal x [ n ] is periodic if

it is defined for all possible values of n, < n < , and

there is a positive integer N such that

(9.2) x [ n + k N ] = x [ n ]

for any integer k. The smallest value of N is called the fundamental period of x [ n ] .

An aperiodic signal does not satisfy one or both of the above conditions.

Periodic discrete-time sinusoids, of fundamental period N, are of the form

(9.3) x [ n ] = A cos ( 2 π m N n + θ ) < n <

where the discrete frequency is ω 0 = 2 π m / N (rad), for positive integers m and N which are not divisible by each other, and θ is the phase angle.

The definition of a discrete-time periodic signal is similar to that of continuous-time periodic signals, except for the fundamental period being an integer. That periodic discrete-time sinusoids are of the given form can easily be shown: shifting the sinusoid in (9.3) by a multiple k of the fundamental period N, we have

x [ n + k N ] = A cos ( 2 π m N ( n + k N ) + θ ) = A cos ( 2 π m N n + 2 π m k + θ ) = x [ n ] ,

since we add to the original angle a multiple mk (an integer) of 2π, which does not change the angle. If the discrete frequency is not in the form 2 π m / N , the sinusoid is not periodic.

Remark

The unit of the discrete frequency ω is radians. Moreover, discrete frequencies repeat every 2π, i.e., ω = ω + 2 π k for any integer k, and as such we only need to consider the range π ω < π . This is in contrast with the analog frequency Ω which has rad/s as unit, and its range is from −∞ to ∞.

Example 9.3

Consider the sinusoids

x 1 [ n ] = 2 cos ( π n π / 3 ) , x 2 [ n ] = 3 sin ( 3 π n + π / 2 ) < n < .

From their frequencies determine if these signals are periodic, and if periodic their corresponding fundamental periods.

Solution: The frequency of x 1 [ n ] can be written

ω 1 = π = 2 π 2

for integers m = 1 and N = 2 , so that x 1 [ n ] is periodic of fundamental period N 1 = 2 . Likewise the frequency of x 2 [ n ] can be written

ω 2 = 3 π = 2 π 2 3

for integers m = 3 and N = 2 , so that x 2 [ n ] is also periodic of fundamental period N 2 = 2 , which can be verified as follows:

x 2 [ n + 2 ] = 3 sin ( 3 π ( n + 2 ) + π / 2 ) = 3 sin ( 3 π n + 6 π + π / 2 ) = x 2 [ n ] .  □

Example 9.4

What is true for analog sinusoids—that they are always periodic—is not true for discrete sinusoids. Discrete sinusoids can be non-periodic even if they result from uniformly sampling a periodic continuous-time sinusoid. Consider the discrete-time signal x [ n ] = cos ( n + π / 4 ) , < n < , which is obtained by sampling the analog sinusoid x ( t ) = cos ( t + π / 4 ) , < t < , with a sampling period T s = 1 s/sample. Is x [ n ] periodic? If so, indicate its fundamental period. Otherwise, determine values of the sampling period satisfying the Nyquist sampling rate condition that when used in sampling x ( t ) result in periodic signals.

Solution: The sampled signal x [ n ] = x ( t ) | t = n T s = cos ( n + π / 4 ) has a discrete frequency ω = 1 (rad) which cannot be expressed as 2 π m / N for any integers m and N because π is an irrational number. So x [ n ] is not periodic.

Since the frequency of the continuous-time signal x ( t ) = cos ( t + π / 4 ) is Ω 0 = 1 , the sampling period, according to the Nyquist sampling rate condition, should be

T s π Ω 0 = π

and for the sampled signal x ( t ) | t = n T s = cos ( n T s + π / 4 ) to be periodic of fundamental period N or

cos ( ( n + N ) T s + π / 4 ) = cos ( n T s + π / 4 )  it is necessary that N T s = 2 k π

for an integer k, i.e., a multiple of 2π. Thus T s = 2 k π / N π satisfies the Nyquist sampling condition at the same time that ensures the periodicity of the sampled signal. For instance, if we wish to have a discrete sinusoid with fundamental period N = 10 , then T s = k π / 5 , for k chosen so that the Nyquist sampling rate condition is satisfied, i.e.,

0 < T s = k π / 5 π  so that 0 < k 5 .

From these possible values for k we choose k = 1 and 3 so that N and k are not divisible by each other and we get the desired fundamental period N = 10 (the values k = 2 and 4 would give 5 as the period, and k = 5 would give a period of 2 instead of 10). Indeed, if we let k = 1 then T s = 0.2 π satisfies the Nyquist sampling rate condition, and we obtain the sampled signal

x [ n ] = x ( t ) | t = 0.2 π n = cos ( 0.2 π n + π / 4 ) = cos ( 2 π 10 n + π 4 ) ,

which according to its frequency is periodic of fundamental period 10. For k = 3 , we have T s = 0.6 π < π and

x [ n ] = x ( t ) | t = 0.6 π n = cos ( 0.6 π n + π / 4 ) = cos ( 2 π × 3 10 n + π 4 )

also of fundamental period N = 10 . □

When sampling an analog sinusoid

(9.4) x ( t ) = A cos ( Ω 0 t + θ ) < t <

of fundamental period T 0 = 2 π / Ω 0 , Ω 0 > 0 , we obtain a periodic discrete sinusoid

(9.5) x [ n ] = A cos ( Ω 0 T s n + θ ) = A cos ( 2 π T s T 0 n + θ )

provided that

(9.6) T s T 0 = m N

for positive integers N and m which are not divisible by each other. To avoid frequency aliasing the sampling period should also satisfy the Nyquist sampling condition,

(9.7) T s π Ω 0 = T 0 2 .

Indeed, sampling a continuous-time signal x ( t ) using as sampling period T s we obtain

x [ n ] = A cos ( Ω 0 T s n + θ ) = A cos ( 2 π T s T 0 n + θ )

where the discrete frequency is ω 0 = 2 π T s / T 0 . For this signal to be periodic we should be able to express this frequency as 2 π m / N for non-divisible positive integers m and N. This requires that

T s T 0 = m N

be rational with integers m and N not divisible by each other, or that

(9.8) m T 0 = N T s ,

which says that a period ( m = 1 ) or several periods ( m > 1 ) should be divided into N > 0 segments of duration T s s. If this condition is not satisfied, then the discretized sinusoid is not periodic. To avoid frequency aliasing, the sampling period should be chosen so that

T s π Ω 0 = T 0 2

as determined by the Nyquist sampling condition.

The sum z [ n ] = x [ n ] + y [ n ] of periodic signals x [ n ] with fundamental period N 1 , and y [ n ] with fundamental period N 2 is periodic if the ratio of periods of the summands is rational, i.e.,

N 2 N 1 = p q

and p and q are integers not divisible by each other. If so, the fundamental period of z [ n ] is q N 2 = p N 1 .

If q N 2 = p N 1 , since p N 1 and q N 2 are multiples of the periods of x [ n ] and y [ n ] , we have

z [ n + p N 1 ] = x [ n + p N 1 ] + y [ n + p N 1 ] = x [ n ] + y [ n + q N 2 ] = x [ n ] + y [ n ] = z [ n ]

or z [ n ] is periodic of fundamental period q N 2 = p N 1 .

Example 9.5

The signal z [ n ] = v [ n ] + w [ n ] + y [ n ] is the sum of three periodic signals v [ n ] , w [ n ] and y [ n ] of fundamental periods N 1 = 2 , N 2 = 3 and N 3 = 4 , respectively. Determine if z [ n ] is periodic, and if so give its fundamental period.

Solution: Let x [ n ] = v [ n ] + w [ n ] , so that z [ n ] = x [ n ] + y [ n ] . The signal x [ n ] is periodic since N 2 / N 1 = 3 / 2 is a rational number with non-divisible factors, and its fundamental period is N 4 = 3 N 1 = 2 N 2 = 6 . The signal z [ n ] is also periodic since

N 4 N 3 = 6 4 = 3 2

is rational with non-divisible factors. The fundamental period of z [ n ] is N = 2 N 4 = 3 N 3 = 12 . Thus z [ n ] is periodic of fundamental period 12, indeed

z [ n + 12 ] = v [ n + 6 N 1 ] + w [ n + 4 N 2 ] + y [ n + 3 N 3 ] = v [ n ] + w [ n ] + y [ n ] = z [ n ] .  □

Example 9.6

Determine if the signal

x [ n ] = m = 0 X m cos ( m ω 0 n ) , ω 0 = 2 π N 0

is periodic, and if so determine its fundamental period.

Solution: The signal x [ n ] consists of the sum of a constant X 0 and cosines of frequency

m ω 0 = 2 π m N 0 m = 1 , 2 , .

The periodicity of x [ n ] depends on the periodicity of the cosines. According to the frequency of the cosines, they are periodic of fundamental period N 0 . Thus x [ n ] is periodic of fundamental period N 0 , indeed

x [ n + N 0 ] = m = 0 X m cos ( m ω 0 ( n + N 0 ) ) = m = 0 X m cos ( m ω 0 n + 2 π m ) = x [ n ] .  □

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B978012814204200020X

Sampling Theory

Luis Chaparro , in Signals and Systems Using MATLAB (Second Edition), 2015

8.3.3 Sampling, Quantizing, and Coding with MATLAB

The conversion of a continuous-time signal into a digital signal consists of three steps: sampling, quantizing, and coding. These are the three operations an A/D converter does. To illustrate them consider a sinusoid x ( t ) = 4 cos ( 2 π t ) . Its sampling period, according to the Nyquist sampling rate condition, is

T s π / Ω max = 0.5 sec / sample

as the maximum frequency of x(t) is Ω max = 2 π . We let T s   =   0.01 (sec/sample) to obtain a sampled signal x s ( nT s ) = 4 cos ( 2 π nT s ) = 4 cos ( 2 π n / 100 ) , a discrete sinusoid of period 100. The following script is used to get the sampled x[n] and the quantized x q [n] signals and the quantization error ε[n] (see Figure 8.13).

Figure 8.13. A period of sinusoid x ( t ) = 4 cos ( 2 π t ) (left-top), sampled sinusoid using T s   =   0.01 (right-top), quantized sinusoid using 4 levels (left-bottom), quantization error (right-bottom) 0 ε Δ = 2 .

%%

% Sampling, quantization and coding

%%

clear all; clf

% continuous--time signal

t=0:0.01:1; x=4*sin(2*pi*t);

% sampled signal

Ts=0.01; N=length(t); n=0:N−1;

xs=4*sin(2*pi*n*Ts);

% quantized signal

Q=2;    % quantization levels is 2Q

[d,y,e]=quantizer(x,Q);

% binary signal

z=coder(y,d)

The quantization of the sampled signal is implemented with our function quantizer which compares each of the samples x s (nT s ) with four levels and assigns to each the corresponding level. Notice the approximation of the values given by the quantized signal to the actual values of the signal. The difference between the original and the quantized signal, or the quantization error, ε(nT s ), is also computed and shown in Figure 8.13.

function [d,y,e]=quantizer(x,Q)

%Input: x, signal to be quantized at 2Q levels

%Outputs: y, quantized signal

%  e, quantization error

%USE [y,e]=midriser(x,Q)

%

N=length(x); d=max(abs(x))/Q;

for k=1:N,

if x(k)>=0,

  y(k)=floor(x(k)/d)*d;

else

    if x(k)==min(x),

    y(k)=(x(k)/abs(x(k)))*(floor(abs(x(k))/d)*d);

    else

    y(k)=(x(k)/abs(x(k)))*(floor(abs(x(k))/d)*d+d);

    end

end

if y(k)==2*d,

    y(k)=d;

end

end

e=x−y

The binary signal corresponding to the quantized signal is computed using our function coder which assigns the binary codes '10','11','00', and '01' to the 4 possible levels of the quantizer. The result is a sequence of 0s and 1s, each pair of digits sequentially corresponding to each of the samples of the quantized signal. The following is the function used to effect this coding.

function z1=coder(y,delta)

% Coder for 4-level quantizer

% input: y quantized signal

% output: z1 binary sequence

% USE z1=coder(y)

%

z1='00'; % starting code

N=length(y);

for n=1:N,

y(n)

if y(n)== delta

  z='01';

elseif y(n)==0

  z='00';

elseif y(n)== −delta

  z='11';

else

    z='10';

end

z1=[z1 z];

end

M=length(z1);

z1=z1(3:M) % get rid of starting code

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780123948120000085

Analog-to-Digital Signal Conversion

Nasser Kehtarnavaz , in Digital Signal Processing System Design (Second Edition), 2008

L3.1 Aliasing

In this example, a discrete signal is generated by sampling a sinusoidal signal. When the normalized frequency f/fs of the discrete signal becomes greater than 0.5, or the Nyquist frequency, the aliasing effect becomes evident.

A sampling process is done by setting the sampling frequency fs to 1 kHz, and the number of samples N to 10. This results in a 10 ms sampled signal. The signal frequency is arranged to vary between 0 and 1000 Hz using an FP control. Figure L3-1 shows a sinusoidal signal having a frequency of 300 Hz which is sampled at 1 kHz for 10 ms producing 10 samples, which are displayed in a waveform graph. In this graph, an analog signal representation is also made by oversampling the sinusoidal signal 100 times faster. In other words, an analog signal representation is obtained by considering a sampling frequency of 100 kHz generating 1000 samples.

Figure L3-1. Aliasing effect.

The FP of the VI includes a Horizontal Pointer Slide control for the signal frequency and two Numeric Indicators for the normalized frequency and aliased frequency. A Stop Button associated with a While Loop on the BD is located on the FP. This button is used to stop the execution of the VI.

Figure L3-2 shows the BD for this sampling system. To generate the analog and discrete sinusoids, one uses a MathScript node. The input to the script node consists of frequency f and sampling frequency fs. The output of the script node consists of three arrays corresponding to the sinusoidal samples (discrete, analog, and aliased) and normalized aliased frequency fa. The Build Waveform function (Functions » Programming » Waveform » Build Waveform) is used to build a waveform by combining the samples into the Y terminal, and the time duration between samples, Ts =1/1000, into the dt terminal. As discussed earlier, the number of samples for the analog representation of the signal is considered to be 100 times that of the discrete signal. Thus, the time interval of the analog signal is set to one hundredth of that of the discrete signal.

Figure L3-2. BD of aliasing example using MathScript.

In the MathScript node, the discrete signal and the analog signal are generated by sampling a cosine wave at 1 kHz and 100 kHz, respectively, and the aliased signal is generated when the signal frequency gets higher than the Nyquist frequency.

An If-else Statement is used to handle the sampling cases with and without aliasing. If the normalized frequency fn is greater than 0.5, the aliased frequency is calculated and used for generating the aliased signal. If fn is less than or equal to 0.5, the aliased signal is the same as the analog signal, and the aliased frequency is set to 0.

When using a MathScript node, one needs to set the input/output data type manually corresponding to the variables in the script. The default data type is set to Scalar Double, which needs to be changed to 1-D Array Double to get the output as a signal. This can be done by right-clicking on any of the output nodes and selecting Choose Data Type (see Figure L3-3).

Figure L3-3. Changing script node data type.

Alternatively, instead of using MathScript, one can use Sine Wave VIs (Functions » Signal Processing » Signal Generation » Sine Wave) to generate the analog and discrete signals. These VIs are arranged vertically in the middle of the BD shown in Figure L3-4. The inputs to these VIs comprise number of samples, amplitude, frequency, and phase offset. Amplitude is set to 1 by default in the absence of any wiring to the amplitude terminal. The f terminal requires frequency to be specified in cycles per sample, which is the reciprocal of number of samples per period.

Figure L3-4. BD of aliasing example—True case.

For the analog signal generation, the value wired to the f terminal is divided by 100 because it is sampled 100 times faster than the discrete signal. For phase, the numeric constant 90 is wired to the phase in terminal.

Among the three Sine Wave VIs shown in Figure L3-4, the top VI generates the discrete signal, the middle VI generates the analog signal, and the bottom VI generates the aliased signal when the signal frequency gets higher than the Nyquist frequency.

A Case Structure is used to handle the sampling cases with aliasing and without aliasing. If the normalized frequency is greater than 0.5, corresponding to the True case, the third Sine Wave VI generates an aliased signal. All the inputs except for the aliased signal frequency are the same.

Note that an Expression Node (Functions » Programming » Numeric » Expression Node) is used to obtain the aliased frequency. An Expression Node is usually used to calculate an expression of a single variable. Many built-in functions, e.g., abs (absolute), can be used in an Expression Node to evaluate an equation. More details on the use of Expression Node can be found in [1].

For the False case, i.e., sampling without aliasing, there is no need to generate an aliased signal. Thus, the analog signal is connected to the output of the Case Structure so that the same signal is drawn on the waveform graph and the frequency of the aliased signal is set to 0. This is illustrated in Figure L3-5. It should be remembered that, when using a Case Structure, one needs to wire all the outputs for each case.

Figure L3-5. False case.

An aliasing outcome is illustrated in Figure L3-6, where samples of a 700 Hz sinusoid are shown. Note that these samples could have also been obtained from a 300 Hz sinusoid, shown by the dotted line in Figure L3-6, where samples of a 700 Hz sinusoid are shown. Note that these samples could have also been obtained from a 300 Hz sinusoid, shown by the dotted line in Figure L3-6.

Figure L3-6. A 700 Hz sinusoid aliased with a 300 Hz sinusoid.

Next, all the three waveforms are bundled together by using the Build Array function and displayed in the same graph. The properties of the waveform graph should be configured as shown in Figure L3-7. This is done by expanding the plot legend vertically to display the three entries and renaming the labels appropriately. Right-click on the waveform graph and choose Properties from the shortcut menu.

Figure L3-7. Waveform Graph Properties dialog box.

A Waveform Graph Properties dialog box will be brought up. Select the Plots tab to modify the plot style. Choose Sampled Signal in the Plot drop-down menu, as shown in Figure L3-7. Also, choose the options for Point Style, Plot Interpolation, and Fill to as indicated in this figure. Adjust the line style of the aliased signal to dotted line.

Rename all the controls and indicators, and modify the maximum scale of the Horizontal Pointer Slide control to 1000 to complete the VI.

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780123744906000039