#ulog (Tutorial @ 001) Unleashing the Capabilites of MATLAB #1

in #steemstem6 years ago (edited)

Never say "ENOUGH" but rather always say "I WANT TO LEARN MORE"


Good Day Steemians! How was your day? Have you learned new things today? Well, we must be productive everyday so here I am, sharing knowledge to you again amazing and beautiful people.


I assume that most of you are aware of what an Analog Signal is, right? And there are tons of programming platforms that can provide a representation of it. But how about a Discrete-Time Signal? What software can provide its mathematical representation?


20180517_195938-1-1-3.jpg

Let us first recall the necessary informations that we need in order to learn about a Discrete-Time Signal and to appreciate MATLAB.


What are Signals?

Signals are series of waveforms of informations and are represented mathematically. A signal can be classifies into two types; it can either be an Analog Signal or a Digital Signal.
It is easier to identify Digital from an Analog since it is precise and accurate. Whereas an Analog is harder to analyze since there are many variables that are present.


What is the Difference between an Analog-Time Signal and a Discrete-Time Signal?

Analog Signal is represented by physical quantities that change continuously -- Merriam

An Analog Signal is any continuous signal for which the time varying feature (variable) of the signal is a representation of some other time varying quantity, i.e., analogous to another time varying signal. -- Wikipedia

So as you can see from the definitions above, basically, Analog Signal is a signal that flactuates in accordance to time and is said to be called as Continuous-Time Signal. When we say "flactuates", this means that it is not constant, therefore it changes over time. But you cannot analyze it unless you take samples from it. For instance, a product owner wants to conduct a survey to know whether people like or dislike his product. Do you think he will ask each and every people in this planet just to know if his product is fine? Of course not! Because if he'll do so, then it'll take him years to pursue what he desire. So to make it easier, he needs to take opinions from some people.
The act of taking samples is called Sampling and the sampled signal is called Discrete-Time Signal. Its graph does not look like Analog Signal but it is not considered as a Digital Signal. Furthermore, Discrete-Time Signal is just the successive representation of samples taken from a Continuous-Time Signal.


To further understand the difference between them, let us acknowledge the application of MATLAB

What is MATLAB

MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment. A proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, C#, Java, Fortran and Python. ---Wikipedia

MATLAB is specifically designed for engineers and scientists. It possesses a matrix-based language that allows natural act or instance of representing a computational mathematics.

MATLAB combines a desktop environment tuned for iterative analysis and design processes with a programming language that expresses matrix and array mathematics directly.


Using MATLAB

  • Click here to avail the trial to download and install the software. If the trial ends, you are required to pay or buy and possess your license. But since I am an Engineering Student, our Department is licensed to open and use MATLAB.

  • After installation, click the MATLAB ICON.

IMG_20180511_193647.JPG

The picture below shows what it looks like after clicking the MATLAB ICON. You can see the tools, Directory, Command Window, Command History and even the Workplace Sheet.

IMG_20180510_132611.jpg

  • Then click Editor that is located at uppermost-left of the software.

IMG_20180511_193810.JPG

The picture below shows what a MATLAB editor looks like.

IMG_20180510_132614.jpg

  • Let us start encoding example codes for a Continuous-Time Signal.
Put two percent-signs (%%) to provide one section of the program. This will allow you to run the program separately from other sections.
%% Continuous
Always remember that MATLAB is a sequential type of programming platform. That means that in programming, there is a sequence that is in need to be followed. It is essential to first encode the values of every variables you are to represent. If you are curious about the value of t then let me explain it to you. t stands for time. We all know that time is independent and continuous so I decided to put a start and end of it interms of a matrix. The time starts at 0 and ends at .1. 0.001 is the interval of time. : is what you need to put when you make a matrix.
A = 10
f = 50
t = 0:0.001:.1
A Continuous-Time Signal is denoted as x(t) since it is a function witg repect to time but the only variables that can be represented are letters, numbers, and dollar sign that is why my vector is denoted with xt. In this example, I used sine for it is common and easier to understand.
xt = A*sin(2*pi*f*t)
Since the goal is to represent the function of "xt" so we need to also put the code below. Always remember that you need to enclose what you want to analyze with parenthesis.
plot(xt)
So the complete code for the first section is:
%% Continuous
A = 10
f = 50
t = 0:0.001:.1
xt = A*sin(2*pi*f*t)
plot(xt)
  • Then press the "Save and Run" button. This is to run the program.

IMG_20180511_194050.JPG

  • As you can see in the graph below, that is the representation of the Continuous-Time Signal we encoded.

IMG_20180510_132800-1.jpg

  • Moreover, a new section and new codes are to be made for Discrete-Time Signal.
Again, put two percent-signs (%%) to provide another section of another program. This will allow you to run the program separately from other sections.
%% Discrete
Since we are going to represent the samples taken from an Analog so let us recall the Nyguist Theorem. It states that sampling frequency is always greater or equal to 2 times the fundamental frequency. But do you know that using 2 is only essential when you want to get the frequency but if you want to also fully recover or get the exact figure of the signal then use 10 or more. So I used:

fs is 10 times greater than f

Considering that MATLAB is a sequential type of programming platform then it is essential to first encode the values of every variables you are to represent. There is no need to encode the values used from the first section even if you'll use it with this section. n is an integer value described by the use of a matrix; the larger it is, the more cycles you can see. ts is simply the sampling time, it is the interval of time and we all know that time is just equal to the inverse of frequency.
n = 0:20
fs = 10*f
ts = 1/fs
A Discrete-Time Signal is denoted as x(n) since it is a function with repect to an integer value but the only variables that can be represented are letters, numbers, and dollar sign that is why my vector is denoted with xn. I am still using the same sine function but the difference is that I implemented the Nyguist Theorem and when you convert Continuous-Time to Discrete-Time, t (time) is just equal to n multiplied with ts (number of samples multiplied with sampling time).
xn = A*sin(2*pi*f*ts*n)
Since the goal is to represent the function of "xn" so we need to also put the code below. Always remember that you need to enclose what you want to analyze with parenthesis but this time we are to ise "stem: since this time we are to represent the signal discretely.
stem(xn)
So the complete code for the second section is:
%% Discrete
n = 0:20
fs = 10*f
ts = 1/fs
xn = A*sin(2*pi*f*ts*n)
stem(xn)
You may be wondering why the values that are present in the first section are not inputted again in the second section yet in the variable that we are representing we are using those values, that is because once again the codes should be sequencial. As you can see that those values are present above the second section therefore any section below it can use the values.
  • Press F1 in your keyboard.

20180517_201841-1.jpg

As you can see in the graph below, that is the representation of the Discrete-Time Signal we encoded.

IMG_20180510_133203-1.jpg

Let us try to see how the graph looks like when our n = 0:100.

%% Discrete
n = 0:100
fs = 10*f
ts = 1/fs
xn = A*sin(2*pi*f*ts*n)
stem(xn)

IMG_20180510_133125-1.jpg

As you can see in the graphs, there really changes im hpw many cycles you are able to see so alter the value of n according to your desire.

  • Now this time, let us combine the codes from the two sections and let us see their difference. we are to ise subplotting to show their graphs in the same time. In SUBPLOTTING you need to consider how many figures are to be represented in x-axis, y-axis and the numbers to be represented.
So since we have two sections then in our y-axis we are to input 2; we are to represent one section above the other section then in our x-axis we are to input 1; and since we have two sections the first section will be denoted with 1 and the other one will be denoted with 2.
Also remember that subplots are to be put before your command.
%% Continuous
A = 10
f = 50
t = 0:0.001:.1
xt = A*sin(2*pi*f*t)
subplot(2,1,1)
plot(xt)

%% Discrete
n = 0:20
fs = 10*f
ts = 1/fs
xn = A*sin(2*pi*f*ts*n)
subplot(2,1,2)
stem(xn)

IMG_20180510_133249-1.jpg

That is how it looks like after we subplot the two sections

Click the video below to view how I did subplotting.


Be productive everyday! And I hope you learned something today.

this is @sissyjill at your service

Sort:  

Congratulations! This post has been upvoted by the communal account, @steemph.cebu by sissyjill being run at Teenvestors Cebu (Road to Financial Freedom Channel). This service is exclusive to Steemians following the Steemph.cebu trail at Steemauto. Thank you for following Steemph.cebu curation trail!

Don't forget to join Steem PH Discord Server, our Discord Server for Philippines.

Coin Marketplace

STEEM 0.36
TRX 0.12
JST 0.040
BTC 70846.59
ETH 3567.69
USDT 1.00
SBD 4.79