Download presentation

Presentation is loading. Please wait.

Published byJames Harms Modified over 2 years ago

1
Lab5 (Signal & System) Instructor: Anan Osothsilp Date: 20 Feb 07 Due Date 09 March 07

2
Anan OsothsilpPage 1 Lab5 Date: 20 Feb 07 Objective: Learn how to use for loop operation for signal manipulation Learn how to write Matlab code to generate waveform for Fourier series Learn how to write Matlab code to generate signal spectrum

3
Anan OsothsilpPage 2 Lab Instruction: Follow the video tutorial and do Lab exercises Lab5 Date: 20 Feb 07

4
Anan OsothsilpPage 3 Lab5 Date: 20 Feb 07 For loop programming in Matlab Usage: - perform repeated task such as printing and calculation - iterate or loop through particular signal sample Looping - Display value y = [0 1 2 3 4 5 6]; for i = 1: 7 disp(y(i)); end Format for variable = start : stop //code end Iterating to find something -Find maximum y = [0 1 2 3 4 5 6]; temp = 0; for i = 1: 7 if (temp) < y(i) temp = y(i); end

5
Anan OsothsilpPage 4 Lab5 Date: 20 Feb 07 Linear combination using for loop Fourier series using for loop with plot on the same figure - If “ hold on;” command is called, then - subsequence call for plot command will create plot in the same figure x = [-1 0 1 2 3 4 5 6 7 8 ] y = 0; for n = 2:10 y = y+ x(n)^2; end figure(1); x = [1 2 3 4 5]; for i = 1:length(x) y = i*x; plot(x,y); hold on; pause(2); end

6
Anan OsothsilpPage 5 Lab5 Date: 20 Feb 07 Linear combination using for loop N = 10 Wo = 2*pi; for n = -N:1:N, Dn = 2/(j*n*Wo); % Fourier Series Coefficient y = y + real(Dn*exp(j*n*Wo*t)); end % Fourier Series computation end

7
Anan OsothsilpPage 6 Lab5 Date: 20 Feb 07 Fourier series of square wave Without for loop’s code t4=[-1.3:.001:2.3]; x4=round(mod(t4,1)); axis([-2 3 -0.3 1.3]); a0=0.5*ones(size(t4)); a1=-2/pi*sin(2*pi*t4); a3=-2/3/pi*sin(6*pi*t4); a5=-2/5/pi*sin(10*pi*t4); plot(t4,a0,'g',t4,a0+a1,'r',t4,a0+a1+a3,'m',t4,a0+a1+a3+a5,'k',t4,x4,'b','Linewidth',2) xlabel('Time (sec)') ylabel('Signal amplitude (units)') title('Periodic square wave signal') legend('one term','two terms','three terms','four terms')

8
Anan OsothsilpPage 7 Lab5 Date: 20 Feb 07 Fourier series of square wave With for loop’s code t=[-1.3:.001:2.3]; x=round(mod(t,1)); %this command generate square wave axis([-2 3 -0.3 1.3]); %this command set figure axis hold on; plot(t,x,'b','LineWidth',2); %blue color with linewidth =2 a0=0.5*ones(size(t4)); %DC component plot(t,a0,'k','LineWidth',2); %black color with linewidth =2 hold on; sum = a0; color = ['r','g','m']; i =1; for n = [1 3 5 ]; %alternative for n = 1:2:5 sum =sum+ (-2/(n*pi))*(sin(2*pi*n*t)); plot(t,sum,'LineWidth',2); %color according to color(i) hold on; pause(2); %delay to show our graph i = i+1; 'inc color indec'; end xlabel('Time (sec)') ylabel('Signal amplitude (units)') title('Periodic square wave signal') legend('x(t) with bias','n =1','n=2','n=3','n=4') grid on;

9
Anan OsothsilpPage 8 Lab5 Date: 20 Feb 07 Excerise1 -Using for loop technique, write Matlab code Fourier series of N = 100; -Plot Fourier summation For the following x(t) t=[-1.3:.001:2.3]; x=round(mod(t,1)); %this command generate square wave axis([-2 3 -0.3 1.3]); %this command set figure axis

10
Anan OsothsilpPage 9 Lab5 Date: 20 Feb 07 Frequency Spectrum of Fourier series Matlab code x = [1 2 3 4 5]; y = 2*x; stem(x,y); N = 10; Wo = pi; for n = -N:1:N, Dn = 2/(j*n*Wo); stem(n*Wo,abs(Dn)) hold on; pause(1); end Generate magnitude spectrum of signal

11
Anan OsothsilpPage 10 Lab5 Date: 20 Feb 07 N = 10; Wo = pi; for n = -N:1:N, Dn = 2/(j*n*Wo); stem(n*Wo,angle(Dn)*180/pi) hold on; end Generate phase spectrum of signal

12
Anan OsothsilpPage 11 Lab5 Date: 20 Feb 07 Exercise 2: Find Fourier series and plot its signal spectrum

Similar presentations

Presentation is loading. Please wait....

OK

Welcome to MATLAB DigComm LAB

Welcome to MATLAB DigComm LAB

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on population census 2011 data Free ppt on brain machine interface signal Ppt on seasons in hindi Ppt on 2nd world war countries Ppt on future generali insurance Download ppt on coordinate geometry for class 9th science Ppt on self management skills Ppt on swine flu prevention Ppt on 5g wireless system Ppt on share market basics