Docsity

DSP LAB manual , notes, Lab Reports of Digital Signal Processing

Toggle sidebar
bg1
Bangladesh University of Business and
Technology (BUBT)
Department of Electrical & Electronic Engineering (EEE)
EEE 314: Digital Signal Processing Lab
Experiment No. 02:
Generation and Visualization of continuous-time
and discrete-time signals.
Theory:
Continuous-time and Discrete-time signals:
Digital Signal Processing must necessarily begin with a signal, and many signals, such as
sound, images, etc., originate as continuous signals, and must be converted into a sequence
of samples to be processed using digital techniques. Sinusoids are one of the most common
and important signals. Fig. 1 depicts a continuous-time sine wave with a frequency of 2 .
The general equation for continuous-time sine waves is:
()= sin(Ω + )=  sin (2 + )
Here,
() is the continuous-time signal (which is a function of time, ), is the amplitude,
Ω is the continuous-time angular frequency (unit is /), is the continuous-time
frequency (unit is ), is time and is the phase (unit is ).
The number of cycles or oscillations per second is called the continuous-time frequency ().
In fig. 1 there are 2 cycles in 1 , so the frequency is 2 . The inverse of the frequency is
the continuous-time time period (
), whose unit is . So,
= 1
⁄. Time period is the time
required for one complete cycle. Here in fig. 1 we can see that one cycle takes 0.5  to
complete. So, here, the time period (
) is 0.5 . Alternatively, as the frequency is 2 ,
time period (
) = 1
⁄ = 1 2
⁄= 0.5 .
Fig. 1: Continuous-time sinusoid with = 2 .
pf3
pf4
pf5
pf8

Partial preview of the text

Download DSP LAB manual , notes and more Lab Reports Digital Signal Processing in PDF only on Docsity!

Bangladesh University of Business and

Technology (BUBT)

Department of Electrical & Electronic Engineering (EEE)

EEE 314: Digital Signal Processing Lab

Experiment No. 02: Generation and Visualization of continuous-time

and discrete-time signals.

Theory:

Continuous-time and Discrete-time signals: Digital Signal Processing must necessarily begin with a signal, and many signals, such as sound, images, etc., originate as continuous signals, and must be converted into a sequence of samples to be processed using digital techniques. Sinusoids are one of the most common and important signals. Fig. 1 depicts a continuous-time sine wave with a frequency of 2 . The general equation for continuous-time sine waves is:

() = sin(Ω + ) = sin (2 + )

Here, ()^ is the continuous-time signal (which is a function of time, ), is the amplitude, Ω is the continuous-time angular frequency (unit is /), is the continuous-time frequency (unit is ), is time and is the phase (unit is ).

The number of cycles or oscillations per second is called the continuous-time frequency (). In fig. 1 there are 2 cycles in 1 , so the frequency is 2 . The inverse of the frequency is the continuous-time time period ( ), whose unit is . So, = 1 ⁄^. Time period is the time required for one complete cycle. Here in fig. 1 we can see that one cycle takes 0.5 to complete. So, here, the time period ( ) is 0.5 . Alternatively, as the frequency is 2 , time period ( ) = 1 ⁄ = 1 2⁄ = 0.5 .

Fig. 1: Continuous-time sinusoid with = 2 .

In continuous-time signals time() can take any value from −∞ to +∞. In other words, there

will be a () for every value of . You will get a value for (), (0.30874), √2, etc.

Discrete-time signals have values only at fixed intervals of time. For example, fig. 2 depicts a discrete-time signal which has values on 0 , 0.125 , 0.25 , 0.375 , 0.5 , 0. , 0.75 , 0.875 , 1 , etc. In this particular example the values are coming at a fixed interval of 0.125 . It is called the sampling interval (). Note that the signal in fig. 2 is actually created by taking values or samples every from the signal in fig. 1. Alternatively, we can say that we took 8 per or took samples at the rate of 8 from the continuous-time signal in fig. 1 to create the discrete-time signal in fig. 2. It is called the sampling rate or sampling frequency ( ). Sampling rate or frequency is the inverse of sampling interval.

Fig. 2: Discrete-time sinusoid with = 1/4 and time () as the independent variable.

For a better understanding of the sampling process, fig. 3 below depicts the continuous-time signal (in fig. 1) and the discrete-time signal (in fig. 2) on the same graph:

Fig. 3: Continuous-time and Discrete-time signals on the same figure.

for (), (0.30874), √2, etc.

Generation and Visualization of continuous-time sinusoid signals: We cannot actually generate continuous-time signals in computers because computer is a digital device which can only process and store digital data. But we can create a discrete- time signal with a very high sampling frequency to emulate a continuous-time signal. How high? There is no rule but let’s say it should be about 100 times greater than the maximum frequency contained in the continuous signal. An example should be able to clarify this.

Example 01: Generate and plot a continuous-time sinusoid over the duration − ≤ ≤ given that the amplitude is 5, the frequency is 2 Hz and the phase is 0 radian.

The equation for the given sinusoid is:

() = 5 sin(2(2) + 0)

As the frequency is 2 Hz, we can use a sampling frequency of 200 Hz. So, the sampling interval is 1 200 = 0.005 ⁄^. To compute and plot the sample values of a 2 Hz sine wave sampled every 0.005 second on the time interval -1 to 1 second, write the following MATLAB code in the command window and observe the generated figure.

A = 5; F = 2; theta = 0;

Fs = F*100; T = 1/Fs;

t = -1:T:1; xa = Asin(2piFt + theta);

plot(t, xa) title("Continuous-time sinusoid" ); xlabel("Time (t)" ); ylabel("Amplitude" );

Practice Problem 01: Generate and plot the continuous-time signal provided below over the duration − ≤ ≤ .

() = 3 cos(2) − 5 sin(6) + 10cos (12)

[Hint: As the signal above has multiple sinusoids contained within, use the maximum frequency among those to determine the suitable sampling frequency.]

Generation and Visualization of discrete-time sinusoid signals: The process of generating a discrete-time signal is mostly similar but has a few differences.

  1. The sampling frequency ( ) should be provided in the problem statement. If it is not given, then one suitable sampling frequency can be chosen using the sampling theorem.
  2. If not provided, discrete-time frequency () can be calculated from continuous-time frequency () and sampling frequency ( ) using the equation = ⁄ (^) .
  1. In case of discrete-time signals, index () should be used as the independent variable instead of time (). Index () can be calculated from time () by using the relationship = ⁄ if it is not provided in the problem statement. One should be careful when a continuous-time and a discrete-time signal have to be plotted on top of each other. Multiple graphs cannot be plotted together if they have different independent variables. As continuous-time signals have time () and discrete-time signals have index () as the independent variables they cannot be plotted together. A workaround for this is to use time () as independent variable while plotting discrete-time signals as well. So, generate the discrete-time signal using index () but plot it using time ().

Normally, MATLAB function plot is used to plot a continuous-time signal. On the other hand, MATLAB function stem is used to plot a discrete-time signal.

Example 02: Write a MATLAB script to generate and plot a discrete-time sinusoid over the duration − ≤ ≤ given that the amplitude is 5, the continuous-time frequency is 2 Hz, the phase is 0 radian and the sampling frequency is 8 Hz.

The discrete-time frequency should be calculated as it is not provided. The range of index is given in the problem statement. If the time were provided rather than the index, it had to be calculated using the equation mentioned earlier. Write the following MATLAB code in the command window and observe the generated figure.

A = 5; F = 2; theta = 0;

Fs = 8; T = 1/Fs;

n = -10:10; f = F/Fs; x = Asin(2pifn + theta);

stem(n, x) title("Discrete-time sinusoid" ); xlabel("Index (n)" ); ylabel("Amplitude" );

Practice Problem 02: Repeat Example 02 but this time do it over the duration − ≤ ≤ . [Hint: Convert time (t) to index (n). The rest of the code is same as Example 02.]

Example 03: Generate and plot the signals below to justify that, ( + °) = ().

() = sin (2(1/6) + /2) () = cos (2(1/6))

Different methods can be used to plot multiple signals at the same time.

  1. Signals can be plotted on separate figures or windows.
  2. Signals can be plotted on the same figure but on separate sections or locations.
  3. Lastly, signals can be plotted on the same figure on top of each other.

Method 3: If hold on is written before a plotting function it will be plotted on top of the previous plot. As there is only one plot, titles, axis labels, etc. will have to be added only once. Legend can be used to distinguish between signals.

n = -16:16; x1 = sin(2pi(1/6)n + pi/2); x2 = cos(2pi(1/6)n);

stem(n, x1) hold on stem(n, x2) title("Sine and Cosine wave" ); xlabel("Index (n)" ); ylabel("Amplitude" ); legend("Sine wave" ,"Cosine wave" );

Note that, the generated figure seemingly has only one plot in case of method 3. In actuality, as both plots are same, one plot is obscuring the other one.

Practice Problem 03: Write a MATLAB script to plot the signal () = ( (^) ) for (^) = , ⁄ , ,⁄ ,⁄ ⁄ and on the same figure using subplot. [Hint: There are 6 signals in total. Arrange them by choosing suitable number of rows and columns for the subplot. Also be careful about the position argument.]

Example 04: Write a MATLAB code to generate a continuous-time sinusoid with amplitude 1, frequency 1 Hz and phase 0 over the duration ≤ ≤ . Then generate a discrete-time sinusoid achieved by sampling the signal above at the rate of 16 Hz. Lastly, plot both signals on the same figure on top of each other.

As the signals have to be plotted on top of each other, we cannot use different independent variables for the signals. So, we generate the continuous signal using time (t) and the discrete signal using index (n) but while plotting we use time (t) for both signals. Also note that, the sampling frequency is different for continuous and discrete signals.

A = 1; F = 1; theta = 0;

Fs = F100; T = 1/Fs; t = 0:T:2; xa = Acos(2piF*t + theta);

plot(t, xa)

Fs = 16; T = 1/Fs; t = 0:T:2; n = t/T; f = F/Fs;

x = Acos(2pifn + theta);

hold on stem(t, x)

title("Continuous and Discrete wave"); xlabel("Time (t)"); ylabel("Amplitude"); legend("Continuous signal","Discrete signal");

Practice Problem 04: Write a MATLAB script to generate the continuous-time signal provided below over the duration ≤ ≤ . Then generate a discrete-time sinusoid achieved by sampling the signal below at the rate of 16 Hz. Then plot both signals on top of each other. Repeat the procedure with sampling frequency 5 Hz. Make comment on the two cases.

() = 3 cos(2) − 5 sin(6) + 10cos (12)

[Hint: Plotting the signals is similar to Example 04. Observe the discrete signals generated using the two different sampling frequencies. Which one is better? Are they following the sampling theorem?]

Lab Report:

Solve the practice problems and submit the solutions as the lab report. You do not have to write down the theory section. The codes should be handwritten. Print the figures. If you face difficulties, mention it in the discussion section.