Net 222: Communications and networks fundamentals (Practical Part) Networks and Communication Department Lab 3: Matlab – Sinusoidal&Exercises
Lab Contents Basic exercises Arrays & Matrices Plotting Sinusoidal signal Networks and Communication Department
Basic exercises Let vector x = [5 2 1 6]: Add 16 to each element Let y = [4 1 3 5], multiply x*y Networks and Communication Department
Solution A. B. Adding 16 to vector x in matlab Multiplying two vectors x and y Networks and Communication Department
Basic exercises Evaluate the following MATLAB expressions by your hand and use MATLAB for checking your ans.: 2 / 2 * 3 (6 - 2 ) / 5 + 7 ^ 2 – 1 A. B. Hands calculation: 2/2=1 1*3 = 3 In Matlab:
How to evaluate an expression ? (6 - 2 ) / 5 + 7 ^ 2 – 1 Networks and Communication Department
Basic exercises Let vector t= 2, 4, 6, 8…20: Compute cos^2(t) %Notice that vector t is a starting form 2 and incremented by 2 till 20 Networks and Communication Department
Solution % cos^2(t) is written as cos(t).^2 Networks and Communication Department
Basic exercises Let vector t= 2, 4, 6, 8…20: Exp^t(1+ cos(3t)) %Notice that vector t is a starting form 2 and incremented by 2 till 20 exp Exponential. exp(X) is the exponential of the elements of X, e to the X.
How to write an expression in matlab % exp^t is written as exp(t). Networks and Communication Department
Arrays & Matrices Given an array A = [ 2 4 1 6 7 2 3 5 9] provide the commands needed to: assign the first row of A to a vector called x1 Networks and Communication Department
Solution %Array in matlab written as each rows separated by ; %assign the first row till end Networks and Communication Department
Arrays & Matrices Given an array A = [ 2 4 1 6 7 2 3 5 9] provide the commands needed to: assign the last 2 rows of A to an array called y % end-1 is row before the last row % end is the last row Networks and Communication Department
Arrays & Matrices Given an array A = [ 2 4 1 6 7 2 3 5 9] provide the commands needed to: compute the square-root of each element of A sqrt(X) is the square root of the elements of X. Networks and Communication Department
Group work ! Given an array A = [ 2 4 1 6 7 2 3 5 9] provide the commands needed to: compute the square-root of the first row of A Networks and Communication Department
Arrays & Matrices Transpose the following matrices: B=[3 2 6 8] A. B. Networks and Communication Department
Plotting Plot sin(x2) on the interval [-5,5] step 0.01 Networks and Communication Department
Solution Networks and Communication Department
Plotting The curve equations: 2. Create three curve on the interval [0,2π] step π/100 add legends to the plot The curve equations: y1 = sin(x) y2 = sin(x-0.25) y3 = sin(x-0.5)
Solution Networks and Communication Department
Sinusoidal Time & Frequency domain continuous or discrete signals Sinusoid Sampling Networks and Communication Department
continuous or discrete signals Continuous-Time Signals: A signal is continuous-time signal if the independent variable t is continuous. Discrete-Time Signals: A signal is defined at discrete times, a discrete-time signal is often identified as a sequence of numbers, denoted by A very important class of discrete-time signals is obtained by sampling a continuous-time signal IN MATLAB: command plot used to sketch the continuous time signals IN MATLAB: command stem used to sketch the discrete time signals Networks and Communication Department
Plotting Time domain using Matlab concept A general sine wave in time domain can be represented by three parameters : Peak amplitude (A) Frequency (f) Phase (φ) s(t) = A sin(2π f t +Φ) Networks and Communication Department
Plotting Time domain using Matlab Example: Plot and stem the time domain signal 7*sin(2*pi*2000*t+pi), t=0:0.05:3 To open the editor click on New -> Script
Matlab code Networks and Communication Department f=2000; t=0:0.05:3; x=7*sin(2*3.14*f*t+3.14); subplot(2,1,1); plot(t,x); xlabel('t'); ylabel('x(t)'); title('time domine continuous'); subplot(2,1,2); stem(t,x); xlabel('n'); ylabel('x[n]'); title('time domine discrete'); Networks and Communication Department
Run and save After writing the code click on Run button to save the code and run it .
Figure 1 Networks and Communication Department
Plotting Frequency domain using Matlab concept Using discipline Known as Fourier analysis (any signal is made up of components at various frequencies, in which each component is a sinusoid ). Eg. s(t) = [(4/π) x (sin(2πft) + (1/3) sin(2π(3f)t)] Networks and Communication Department
Plotting Frequency domain using Matlab example Plot each signals alone the show the frequency domain( Fourier) signal s(t)=[6*sin(2pi*t+pi)+4*sin(2*pi*3t+pi)+ 2*sin(2*pi*5t+3*pi)] Networks and Communication Department
Matlab code f1=1; f2=3; f3=5; t=0:0.01:5; pi=3.14; %############################# 1 s1=6*sin(2*pi*f1*t+pi); s2=4*sin(2*pi*f2*t+pi); s3=2*sin(2*pi*f3*t+3*pi); subplot(4,1,1); plot(t,s1,'linewidth',2); title('first signal '); grid on ; %############################## 2 subplot(4,1,2); plot(t,s2,'linewidth',2); title('second signal '); f1=1; f2=3; f3=5; t=0:0.01:5; pi=3.14; %############################# 1 s1=6*sin(2*pi*f1*t+pi); s2=4*sin(2*pi*f2*t+pi); s3=2*sin(2*pi*f3*t+3*pi); subplot(4,1,1); plot(t,s1,'linewidth',2); title('first signal '); grid on ; %############################## 2 subplot(4,1,2); plot(t,s2,'linewidth',2); title('second signal ');
Con. Matlab code %############################## 3 subplot(4,1,3); plot(t,s3,'linewidth',2); title('third signal '); grid on ; %############################## Fourier fd=(s1+s2+s3); subplot(4,1,4); plot(t,fd,'linewidth',2); title('Freqency Domaine '); grid on; Networks and Communication Department
Figure 2 Networks and Communication Department
Sampling In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A sample is a value or set of values at a point in time and/or space. Networks and Communication Department
Con. Sampling The sampling frequency or sampling rate, fs, is the average number of samples obtained in one second For functions that vary with time, let s(t) be a continuous function (or "signal") to be sampled, and let sampling be performed by measuring the value of the continuous function every T seconds, which is called the sampling interval dt= 1/fs Networks and Communication Department
Sampling rate Networks and Communication Department
Con. Sampling rate Networks and Communication Department
Sinusoid Sampling Sample the sinusoid x = sin(2 pi f t), where f = 2 kHz. And t=0:5T Let x1 be the signal sampled at rate of 10 kHz. f=2000; T=1/f; dt1= 1/10000; t1=0:dt1:5*T; x1=sin(2*3.14*f*t1); stem(t1,x1);
Matlab code Networks and Communication Department Discrete-Time Signals Networks and Communication Department
Figure Networks and Communication Department f=2000; T=1/f; dt1= 1/10000; t1=0:dt1:5*T; x1=sin(2*3.14*f*t1); plot(t1,x1); Networks and Communication Department
Sinusoid Sampling Sample the sinusoid x = sin(2 pi f t), where f = 2 kHz. And t=0:5T Let x2 be the signal sampled at 3 kHz f=2000; T=1/f; dt2= 1/3000; t2=0:dt2:5*T; x2=sin(2*3.14*f*t2); stem(t2,x2); Networks and Communication Department
Sinusoid Sampling Plot frequency domain sinusoid x = sin(2 pi f t), where sampling frequency Fs = 8000 Hz. At different frequency tones start from 0 till 3, then multiplying the tones with 2 Note : The sampling frequency is sample rate In the form of an FT it’s easy to filter sound. For example, when you adjust the equalizer on your sound system, like when changing the bass or treble, what you’re really doing is telling the device to multiply the different frequencies by different amounts before sending the signal to the speakers.
Matlab code f=8000; % sampling frequency t1=0:1/f:3; % time axis %############################ 1 s1=sin(2*3.14*f*t1); s2=sin(2*3.14*f*2*t1); subplot(3,1,1); plot(t1,s1,'linewidth',2); title('first f tone'); grid on ; Networks and Communication Department
Con. Matlab code %########################## 2 subplot(3,1,2); plot(2*t1,s1,'linewidth',2); title('second f tone'); grid on ; fd = (s1+s2); subplot(3,1,3); plot(t1,fd,'linewidth',2); title(' frequncey domain ' ) ; Networks and Communication Department
Figure Networks and Communication Department
The End Any Questions ? Networks and Communication Department