-
Notifications
You must be signed in to change notification settings - Fork 0
Lab 1
##Exercise 1: Data Types
In this exercise we learnt the basics of LabView including setting up the diagram using modules by searching in the function palette and adding controls, constants and indicators. We also learnt how to set up the panel so we can run the program. We had no problems for this exercise.
###Screenshot 1 - Schematic diagram for the data types exercise.
The program works by converting the input string to an integer (ASCII form) and then treating the integers as a temperature in Farenheit, which is then converted to degrees Celsius by the following equation:
C = (F - 32) / 1.8
These values are then averaged to work out how 'hot' a string is. We tested both of our surnames and got the following results (first 3 characters shown):
###Screenshot 2 - "Nugent" entered into the 'hot' calculator.
###Screenshot 3 - "Yang" entered into the 'hot' calculator.
We realised that we would need a string that contained ASCII characters that were a large integer number, and tested our theory by looking up an ASCII table. A high value that we could easily type was "~".
###Screenshot 4 - "~" entered into the 'hot' calculator.
##Exercise 2: Implementation of the Central Limit Theorem
In this exercise we learnt how to implement the Central Limit Theorem which is stated below. We were introduced to some new modules such as loops, random numbers, comparisons and histograms. We encountered many difficulties with this task because the last part asked us to adjust the probability density function so that it had a mean of 0 and a variance of 1. Several GTAs gave us conflicting answers so we were running around in circles for a short while.
###Central Limit Theorem
When independent random variables are added, their sum tends towards a normal distribution
even if the variables themselves are not normally distributed.
For n random variables that are mutually independent and identically distributed, each with mean μ and variance σ², the new random variable will have mean and variance as follows:
As n→∞:
Wikipedia / Lecture Notes
To simulate a random variable, we used two for loops to create a 2D array that contained random numbers between 0 and 1. We then calculated the mean of this random variable and added this to an array. The loop is then run again (with some milliseconds of delay between iterations) with more i.i.d. RV means added to the array. This array is then plotted in a histogram. Using CLT, this graph converges to a normal distribution with the more loop iterations.
###Screenshot 5 - Schematic diagram for the CLT exercise.
###Screenshot 6 - Panel view from the CLT exercise.
Notice that the distribution is not very smooth. This is because the number of bins we have is large meaning the probability of being in any one bin is low. If we decrease the bins to ~10 then the graph is much smoother (this is done later).
In order to stop the program after 1000 iterations we just used a comparison block that is connected to the conditional terminal and a constant 999 (iteration starts at 0).
###Screenshot 7 - Schematic diagram that stops after 1000 iterations.
###Screenshot 8 - Panel view that stops after 1000 iterations.
Our last task was to adjust the random variable so that the normal distribution had 0 mean and unit variance. This would mean it would look something like below:
In order to do this, we decided to adjust the random number after it had came out of the generator. We could have also added the adjustments outside the for loops, the only difference would be a factor of 10.
We know that the random variable is uniformly distributed between 0 and 1. The mean of this is simply the middle which is 0.5, so we minus 0.5 to centre the distribution around 0. The variance of a uniform distribution is given by:
X ~ U(a,b)
Var(X) = 1/12 (b - a)^2
So for this example the variance is 1/12. If we recall the formula for scaling the variance of a variable:
Var(aX) = a^2 Var(X)
we want to multiply by √12 to get a variance of 1. We have to remember however that we also divide by 100 at the end, which does not affect the mean (since it is now 0), so we must also multiply by 10 (√100 = 10). The final multiplier is therefore given by:
√12 x 10 ~ 34.641
###Screenshot 9 - Diagram view for the standardised normal distribution.
###Screenshot 10 - Panel view for the standardised normal distribution.
##Exercise 3: Waveforms
In this exercise we learnt how to generate waveforms with given input and plot these in the time and frequency domain. We also explored the use of filters.
We first created 3 sine waveforms with frequencies 10Hz, 30Hz and 120Hz and added them together. Using the low-pass filter module with a cutoff frequency of 10Hz eliminated the higher frequency waveforms leaving us with the 10Hz sine wave on the output as shown below in screenshot 12.
###Screenshot 11 - Initial diagram view for ex3.
###Screenshot 12 - Initial panel view for ex3.
Next we needed to modify the filter parameters so that we only saw a 30Hz sine wave on the output. To do this we changed the filter block to be a band-pass filter and set the upper limit as 35Hz. The lower cut off frequency was then given by an indicator, set to be 25Hz. The diagram and panel are shown below.
###Screenshot 13 - Final diagram for ex3.
###Screenshot 14 - Final panel for ex3.