Lab. 1 Matlab Functions, Filtering and Aliasing PART-1: Familiarization With MATLAB
Lab. 1 Matlab Functions, Filtering and Aliasing PART-1: Familiarization With MATLAB
x=99 + 4 i % j can be used too. Complex numbers are natural for MATLAB variables
myString=‘hello world’
myArray = [ 1 2; 3 4]
Variable Names:
o First character must be a LETTER.
o After that, any combination of letters, numbers and _ could be given.
o CASE SENSITIVE! (var1 is different from Var1).
Built-in variables:
1. i and j can be used to indicate complex numbers.
2. pi has the value 3.1415926…
3. Ans stores the last unassigned value (like on a calculator).
2. Indexing or going into and bringing back elements for use, thus use first bracket:
c = a (2,1)
d = sin (a(2,1))
% Remember RC convention or Row-Column convention signifying row to be
represented first, then column.
5. Structure Array: A structure is a data type that groups related data using data
containers called fields. Each field can contain data of any type or size.
Example:
patient(1).name = 'John Doe';
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
patient
5. Creating functions:
function y = discrete_sin (n, Fs, Fo)
y = sin (2*pi*Fo/Fs*n);
% t = n * Ts = n / Fs
stem( n,y)
end
6. MATLAB Sound
Check out the MATLAB demo by typing on command prompt: xpsound
Make your own sound !
t = 1 : 0.01:5 ;
Fo=3;
Fs= 100;
A=400;
y = A* cos (2*pi*Fo*t);
sound (y)
Assignment:
1) Use audioread and audiorecorder functions (get help from MATLAB help),
and try to find digital versions of “Hello !” and “Olleh !” in your OWN voice
by next class!. No need to write it in report!
PART-2: Aliasing(Basics)
Aliasing occurs when a system is measured at an insufficient sampling rate. It is
perhaps best explained through example.
Let's say I have a ball that has three positions: 0 (middle), +1 (up), and -1 (down).
Let's say that ball starts at 0 at time=0, goes to +1, then to 0, then to -1, then back
to 0, and each of these 4 movements takes 1 second. Since it takes 4 seconds to
complete this cycle, the frequency of this motion would be (1 cycle)/(4 seconds) =
.25 Hz.
Now let's say you want to measure this frequency, but you only look at the ball
once every 5 seconds. At t=0, you see it at 0, at t=5 you see it at 1, at t=10 you see
it at 0, at t=15 you see it at -1, and finally at t=20 you see it at zero after what
appears to be a complete cycle. You will then say that the frequency appears to be
(1 cycle)/(20 seconds) = .05 Hz. But this is wrong!!! Why? Because you weren't
looking often enough, and you missed a bunch of the movement, resulting in you
'measuring' a totally different frequency. That's aliasing.
for i = 1:3
if ((Fs < 2 * Fo) && i~=3)
disp('you cannot make me do this! ' )
elseif ((Fs < 2 * Fo) && i==3)
disp('Fine, I give you aliasing ' ) % broadly discussed in later part
plot ( n/Fs, y)
else
plot ( n/Fs, y)
end
end
LAB TASK
Create a 5 by 5 random matrix(use rand function). Multiply the whole matrix by 10. Do
the mean of the first 2 columns and median for the next 3 columns, and save it in a 1 by
5 matrix . Try to use all the things you learned in this lab and finish the code in ONE
LINE ONLY