c.s.s class work

Post on 29-Jun-2015

510 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

AMIR BAGHDADI Student Number 2802166Second Year

CIRCUITS, SIGNALS AND SYSTEMS WORKSHOPMATLAB and Simulink Exercises during a Computer Workshop – 1 hour per week forthe first 10 weeks. You will carry out the following nine exercises:Exercise 1: Simulink Model to display a sinusoidal signal on an oscilloscope. Investigatethe effect of changing its amplitude, frequency, dc bias, and phase. Also displays the RMSvalue of the signal.Exercise 2: Progressive synthesis of a bipolar square wave from sinusoidal signals in theTrigonometric Fourier Series of this waveform. Shows plots of the fundamental frequencyalone, progressively adds the third, fifth, seventh harmonics weighted with coefficients upuntil the 19th

harmonic. Finishes with a 3-D surface representing the gradualtransformation of a sine wave into a square wave.Exercise 3: Progressive synthesis of a unipolar triangular wave from sinusoidal signals inthe Trigonometric Fourier Series of this waveform. Shows a plot of the DC offset followedby the fundamental frequency added to it, progressively adds the third, fifth, seventhharmonics weighted with coefficients up until the 19th

harmonic. Finishes with a 3-Dsurface representing the gradual transformation of a sine wave into a triangular wave.Exercise 4: Progressive synthesis of a half-wave rectified sine waveform from sinusoidalsignals in the Trigonometric Fourier Series of this waveform. Shows a plot of the DCoffset followed by the fundamental frequency added to it, progressively adds the second,fourth, sixth harmonics weighted with coefficients up until the 8th

harmonic.Exercise 5: Find the Trigonometric Fourier series of a sawtooth waveform and synthesizeit by writing a MATLAB program to verify the solution.

1

AMIR BAGHDADI Student Number 2802166Second Year

Exercise 6: Find the Discrete Fourier Transform (DFT) of a signal f(t) by using the FastFourier Transform (FFT) algorithm in MATLAB. With exercises 6.1: Find the frequenciesin a noiseless (deterministic) signal y(t); and 6.2 Find the frequencies in a noisy signal y(t)Exercise 7: Find the power frequency spectrum of three signals with exercises 7.1, 7.2 and7.3.Exercise 8: Simulink prediction of the unit step response of some first and second ordercircuits. Model the circuit with a transfer function and analytically predict its timeresponse. Verify with a MATLAB/SIMULINK simulation.Exercise 9: MATLAB prediction of the frequency response of filter circuits. Sketch Bodeplots of given circuit transfer functions. Compare you sketch with a MATLAB Bode plot.Predict the frequency response of Low pass, High pass, Band pass, Band stop, PhaseAdvance and Phase Lag circuits.

EXERCISE 2: FOURIER SERIES OF SQUARE WAVEAim: To show that the Fourier series expansion for a square-wave is made up of asum of odd harmonics.You will show this graphically using MATLAB. Type in step one only to see what it does(there is no need for the pause at his stage. A sine wave will be displayed.)1. Start by forming a time vector running from 0 to 10 in steps of 0.1, and take thesine of all the points. Let's plot this fundamental frequency.t = 0:.1:10; (%creates a vector of values from zero to ten in steps of 0.1%)y = sin(t); (%creates a vector y with values that are the sine of the values in thevector t%)plot(t,y); (% plots the vector t against the vector y%)pause; (% the pause is overcome by pressing any button%)

2

AMIR BAGHDADI Student Number 2802166Second Year

3

AMIR BAGHDADI Student Number 2802166Second Year

2. Now add the third harmonic weighted by a third to the fundamental, and plot it.y = sin(t) + sin(3*t)/3; (%creates a vector y%)plot(t,y); (% plot the time vector t against the vector y %)pause;

4

AMIR BAGHDADI Student Number 2802166Second Year

5

AMIR BAGHDADI Student Number 2802166Second Year

3. Now add the first, third, fifth, seventh, and ninth harmonics each weightedrespectively by a third, a fifth, a seventh, and a ninth)y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9;plot(t,y);pause;

6

AMIR BAGHDADI Student Number 2802166Second Year

7

AMIR BAGHDADI Student Number 2802166Second Year

4. For a finale, we will go from the fundamental to the 19th harmonic, creatingvectors of successively more harmonics, and saving all intermediate steps as therows of a matrix. These vectors are plotted on the same figure to show theevolution of the square wave.t = 0:.02:3.14; (% create a vector with values from zero Pi %)y = zeros(10, length(t));x = zeros(size(t));for k=1:2:19x = x + sin(k*t)/k;y((k+1)/2,:) = x;endplot(y(1:2:9,:)')title('The building of a square wave')pause;

8

AMIR BAGHDADI Student Number 2802166Second Year

5. Here is a 3-D surface representing the gradual transformation of a sine wave into asquare wave.surf(y);shading interpaxis off ij

9

AMIR BAGHDADI Student Number 2802166Second Year

EXERCISE 3: FOURIER SERIES OF TRIANGULAR WAVEAim: To show that the Fourier series expansion for a triangular-wave shown infigure 2 is made up of a sum of odd harmonics and a constant term.You will show this graphically using MATLAB.

Then start by forming a time vector running from 0 to 10 in steps of 0.1.1. t = [0:0.1:10];2. Lets plot the DC term V/2

t =[0:0.1:10];y =5;figure;

10

AMIR BAGHDADI Student Number 2802166Second Year

plot(t,y);title('The constant term = 5 V')

11

AMIR BAGHDADI Student Number 2802166Second Year

12

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 104

4.2

4.4

4.6

4.8

5

5.2

5.4

5.6

5.8

6The constant term=5V

3. Next plot the DC term plus the fundamental

y = 5 + (40/(pi*pi))*cos(t);figure;plot(t,y);title('The constant term of 5 V plus fundamental frequency')

13

AMIR BAGHDADI Student Number 2802166Second Year

14

AMIR BAGHDADI Student Number 2802166Second Year

15

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 100

1

2

3

4

5

6

7

8

9

10The constant term of 5V plus fundamental frequency

4. Now add the constant 5, the fundamental and third harmonic, and plot it.

y = 5+ (40/(pi*pi))*cos(t) + (40/((3*pi)*(3*pi)))*cos(3*t);figure;plot(t,y);title('The constant term plus fundamental frequency plus thirdharmonic')

16

AMIR BAGHDADI Student Number 2802166Second Year

17

AMIR BAGHDADI Student Number 2802166Second Year

18

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 100

1

2

3

4

5

6

7

8

9

10The constant term fundamental frequency plus third harmonic

5. Plot the sum of constant , fundamental, 3rd

and 5th

harmonics

y = 5+ (40/(pi*pi))*cos(t) + (40/((3*pi)*(3*pi)))*cos(3*t) + (40/((5*pi)*(5*pi)))*cos(5*t);figure;plot(t,y);title('Constant term, fundamental, 3rd and 5th harmonics')

19

AMIR BAGHDADI Student Number 2802166Second Year

20

AMIR BAGHDADI Student Number 2802166Second Year

21

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 100

1

2

3

4

5

6

7

8

9

10Constant term, fundamental, 3rd and 5th harmonics

6. Finally, plot individual terms in the series on the same graph up to the 19th

harmonic

x = 5;for k = 1:2:19x = x + (40/((k*pi)*(k*pi)))*cos(k*t);y((k+1)/2,:) = x;endfigure;plot(y(1:2:9,:)');title('Constant term, fundamental, 3rd, 5th, 7th upto 19th harmonics');

22

AMIR BAGHDADI Student Number 2802166Second Year

23

AMIR BAGHDADI Student Number 2802166Second Year

24

AMIR BAGHDADI Student Number 2802166Second Year

0 20 40 60 80 100 1200

1

2

3

4

5

6

7

8

9

10Constant term, fundamental, 3rd, 5th, 7th upto 19th harmonics

7. Show the above as a 3-D surface representing the gradual transformation of cosinewaves into a triangular wave. Note that the coefficients decrease as 1/n

surf(y);shading interpaxis off ij

25

AMIR BAGHDADI Student Number 2802166Second Year

26

AMIR BAGHDADI Student Number 2802166Second Year

27

AMIR BAGHDADI Student Number 2802166Second Year

3D Surface of a triangular wave

EXERCISE 4: Fourier Series Of Half Rectified Sine WaveAim: To show that the Fourier series expansion for a half-wave rectified sinewaveform is made up of a sum a constant term and even harmonicsof sine and cosine waves.You will show this graphically using MATLAB.

t = [0:0.1:10];y =10/pi;figure;plot(t,y);title('The constant term ')

28

AMIR BAGHDADI Student Number 2802166Second Year

29

AMIR BAGHDADI Student Number 2802166Second Year

y = (10/pi)*(1 + (pi/2))*sin(t);figure;plot(t,y);title('The constant term plus fundamental frequency')

30

AMIR BAGHDADI Student Number 2802166Second Year

31

AMIR BAGHDADI Student Number 2802166Second Year

y = (10/pi)*(1 + (pi/2)*sin(t)-(2/3)*cos(2*t));figure;plot(t,y);title('The constant term plus fundamental frequency plus thirdharmonic')

32

AMIR BAGHDADI Student Number 2802166Second Year

33

AMIR BAGHDADI Student Number 2802166Second Year

y = (10/pi)*(1 + (pi/2)*sin(t)-(2/3)*cos(2*t)-(2/15)*cos(4*t));figure;plot(t,y);title('Constant term, fundamental, 2nd and 4th harmonics')

34

AMIR BAGHDADI Student Number 2802166Second Year

35

AMIR BAGHDADI Student Number 2802166Second Year

y = (10/pi)*(1 + (pi/2)*sin(t)-(2/3)*cos(2*t)-(2/15)*cos(4*t)-(2/35)*cos(6*t));figure;plot(t,y);title('Constant term, fundamental, 2nd and 4th harmonics')

36

AMIR BAGHDADI Student Number 2802166Second Year

37

AMIR BAGHDADI Student Number 2802166Second Year

EXERCISE 5: Exercise in solving Trigonometric Fourier SeriesShow that the Trigonometric Fourier series of the sawtooth wave

38

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 105

5.5

6

6.5

7

7.5The constant term

39

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 10-8

-6

-4

-2

0

2

4

6

8The constant term plus fundamental frequency

40

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 10-10

-8

-6

-4

-2

0

2

4

6

8

10The constant term, fundamental frequency and third harmonic

41

AMIR BAGHDADI Student Number 2802166Second Year

0 1 2 3 4 5 6 7 8 9 10-10

-8

-6

-4

-2

0

2

4

6

8

10The constant term, fundamental frequency, 2nd harmonic and 3rd harmonic

42

AMIR BAGHDADI Student Number 2802166Second Year

EXERCISE 6: Find the Discrete Fourier Transform (DFT) of a signal f(t) by usingthe Fast Fourier Transform (FFT) algorithm in MATLABFourier analysis is extremely useful for data analysis, as it breaks down a signal intoconstituent sinusoids of different frequencies.1. For analogue (continuous-time) signals, the Fourier Transform of a signal f(t) isdt e t f Gt jw -+88-

∫= ) ( ) (ω2. For sampled vector data, Fourier analysis is performed using the Discrete Fouriertransform (DFT).0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01-0.200.20.40.60.811.21.41.6Continuous-time SignalSampled signal(Sampling period = 1 mS)

Figure 1: Sample and Hold circuit (ADC)The fast Fourier transform (FFT) is an efficient algorithm for computing the DFT of asequence; it is not a separate transform. It is particularly useful in areas such as signal andimage processing, where its uses range from filtering, convolution, and frequency analysisto power spectrum estimation.The following exercises (6.1, 6.2, 7.1, 7.2 and 7.3) will investigate the Discrete FourierTransform and show you that a real continuous-time signal y(t) can be sampled (e.g. withan analogue to digital converter ADC as shown in figure 1) and the vector of discrete-timedata ‘y’ fed to the MATLAB algorithm fft(y) which will compute the Fourier Transformand plot the frequency spectrum.•The signal y(t) is sampled with a constant sampling period.•The sampled data is input to MATLAB by putting the data in a vector ‘y’.•The FFT algorithm operates on the data vector y and returns the frequency

43

AMIR BAGHDADI Student Number 2802166Second Year

spectrum in a vector Y where Y = fft(y, N). The elements of Y are complexnumbers to accommodate the fact that the spectrum has both a modulus and phaseat each frequency. N is the number of points over which the FFT will be computed•To present the results, each element of Y is multiplied by its complex conjugate togive a real value and this value is normalized by dividing it by the number ofpoints N in the FFT algorithm.Yy = Y.* conj(Y)/N•The final result is plotted to show the power at each contributing frequency

44

AMIR BAGHDADI Student Number 2802166Second Year

0 5 10 15 20 25 30 35 40 45 50-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Deterministic signal with two frequency components at 50Hz and 120 Hz

time (milliseconds)

45

AMIR BAGHDADI Student Number 2802166Second Year

0 50 100 150 200 250 300 350 400 450 5000

10

20

30

40

50

60

70

80Frequency content of y

frequency (Hz)

46

AMIR BAGHDADI Student Number 2802166Second Year

0 5 10 15 20 25 30 35 40 45 50-8

-6

-4

-2

0

2

4

6

8Noisy signal with two frequency components

time (milliseconds)

47

AMIR BAGHDADI Student Number 2802166Second Year

0 50 100 150 200 250 300 350 400 450 5000

20

40

60

80

100

120Frequency content of y

frequency (Hz)

A. Exercise 6.1 Find the frequencies in a noiseless (deterministic) signal y(t).Create the M-file FFT_deterministic.m, or cut and paste from Blackboard.

clear all;

t = 0:0.001:0.6; y = sin(2*pi*50*t) + sin(2*pi*120*t) %+ sin(2*pi*200*t) a = 1000*t(1:50);b = y(1:50); figure; plot(a,b);

48

AMIR BAGHDADI Student Number 2802166Second Year

49

AMIR BAGHDADI Student Number 2802166Second Year

clear all; t = 0:0.001:0.6; y = sin(2*pi*50*t) + sin(2*pi*120*t) %+ sin(2*pi*200*t) a = 1000*t(1:50);b = y(1:50); figure; plot(a,b); %figure; plot(t,y) Y = fft(y,512); Pyy = Y.*conj(Y)/512; f = 1000*(0:256)/512;

50

AMIR BAGHDADI Student Number 2802166Second Year

figure; plot(f,Pyy(1:257))

51

AMIR BAGHDADI Student Number 2802166Second Year

B. Exercise 6.2 Find the frequencies in a noisy signal y(t). Use the M-fileFFT_noisy.m

clear all; t = 0:0.001:0.6; x = sin(2*pi*50*t) + sin(2*pi*120*t); % + sin(2*pi*200*t) n = 1.2*randn(size(t)); y = x + n; a = 1000*t(1:50);b = y(1:50); figure; plot(a,b);

52

AMIR BAGHDADI Student Number 2802166Second Year

53

AMIR BAGHDADI Student Number 2802166Second Year

clear all; t = 0:0.001:0.6; x = sin(2*pi*50*t) + sin(2*pi*120*t); % + sin(2*pi*200*t) n = 1.2*randn(size(t)); y = x + n; a = 1000*t(1:50);b = y(1:50); figure; plot(a,b); %figure; plot(t,y) Y = fft(y,512); Pyy = Y.*conj(Y)/512;

54

AMIR BAGHDADI Student Number 2802166Second Year

f = 1000*(0:256)/512; figure; plot(f,Pyy(1:257))

55

AMIR BAGHDADI Student Number 2802166Second Year

56

AMIR BAGHDADI Student Number 2802166Second Year

57

AMIR BAGHDADI Student Number 2802166Second Year

EXERCISE 7.1 Find the frequency spectrum of a periodic rectangular signal whoseamplitude is ± 1 and the fundamental frequency is 50 Hz.You will find the spectrum by first creating a rectangular signal from its Fourier series andthen applying the Fast Fourier transform (FFT) algorithm to this signal to find thefrequencies contained in it. Recall that the Fourier series of this rectangular pulse was usedto synthesize the signal in Exercise 2.clear all, = 0:0.001:6; = zeros(size(t)); for k=1:2:19 x = x + sin(2*pi*50*k*t)/k; endy = x;figure; plot(1000*t(1:50),y(1:50))

58

AMIR BAGHDADI Student Number 2802166Second Year

59

AMIR BAGHDADI Student Number 2802166Second Year

clear all, t = 0:0.001:6; x = zeros(size(t)); for k=1:2:19 x = x + sin(2*pi*50*k*t)/k; endy = x;figure;plot(1000*t(1:50),y(1:50))title('Square Wave Signal')xlabel('time (milliseconds)')pause

60

AMIR BAGHDADI Student Number 2802166Second Year

0 5 10 15 20 25 30 35 40 45 50-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8Squarewave Signal

time (milliseconds)

Y = fft(y,512);Pyy = Y.* conj(Y) / 512;f = 1000*(0:356)/512;figure;plot(f,Pyy(1:357)) % this is a plot of the frequency versus signal power

61

AMIR BAGHDADI Student Number 2802166Second Year

62

AMIR BAGHDADI Student Number 2802166Second Year

Y = fft(y,512);Pyy = Y.* conj(Y) / 512;f = 1000*(0:356)/512;figure;plot(f,Pyy(1:357)) % this is a plot of the frequency versus signal powertitle('Frequency content of y')xlabel('Frequency (HZ)')

63

AMIR BAGHDADI Student Number 2802166Second Year

0 100 200 300 400 500 600 7000

10

20

30

40

50

60

70Frequency content of y

Frequency (Hz)

EXERCISE 7.2 Find the power frequency spectrum of a single shot (non-repeating)rectangular pulse. Let amplitude A = 1 and pulse width = 1 second. Use the M-fileFFT_Pulse.m

t = 0:0.1:2; y = [1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0]; figure; plot(t(1:20),y(1:20))

64

AMIR BAGHDADI Student Number 2802166Second Year

65

AMIR BAGHDADI Student Number 2802166Second Year

title('Signal: Single shot rectangular pulse') xlabel('time (seconds)')

66

AMIR BAGHDADI Student Number 2802166Second Year

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Signal: Single shot rectangular pulse

time (seconds)

Y = fft(y,512); Pyy = Y.* conj(Y)/512; f = 10*(0:256)/512;figure; plot(f,Pyy(1:257))

67

AMIR BAGHDADI Student Number 2802166Second Year

68

AMIR BAGHDADI Student Number 2802166Second Year

title('Frequency content of y') xlabel('frequency (Hz)')

69

AMIR BAGHDADI Student Number 2802166Second Year

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

0.02

0.04

0.06

0.08

0.1

0.12

0.14

0.16

0.18

0.2Frequency content of y

frequency (Hz)

EXERCISE 7.3 Find the power frequency spectrum of a single shot (non-repeating)unit pulse (area 1). Let amplitude A = 10 to represent infinity and pulse width = 0second. Use the M-file FFT_UnitPulse.m

t = 0:0.1:2; y = [10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ]; figure; plot(t(1:20),y(1:20))

70

AMIR BAGHDADI Student Number 2802166Second Year

71

AMIR BAGHDADI Student Number 2802166Second Year

title('Signal: Unit impulse') xlabel('time (seconds)')

72

AMIR BAGHDADI Student Number 2802166Second Year

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

1

2

3

4

5

6

7

8

9

10Signal: Unit Impulse

time (seconds)

Y = fft(y,512); Pyy = Y.* conj(Y)/512; f = 10*(0:256)/512;figure; plot(f,Pyy(1:257))

73

AMIR BAGHDADI Student Number 2802166Second Year

74

AMIR BAGHDADI Student Number 2802166Second Year

title('Frequency content of y') xlabel('frequency (Hz)')

75

AMIR BAGHDADI Student Number 2802166Second Year

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1

-0.5

0

0.5

1

1.5Frequency content of y

frequency (Hz)

EXERCISE 8: Find the Transfer Function of a circuit, find its step response andfrequency spectrum (using MATLAB) by carrying out steps 1 to 5:1. Show that equation 1 is the differential equation describing the dynamics of thefollowing series RLC circuit

76

AMIR BAGHDADI Student Number 2802166Second Year

-80

-60

-40

-20

0

Mag

nitu

de (

dB)

100

101

102

103

104

-180

-135

-90

-45

0

Pha

se (

deg)

Bode Diagram

Frequency (rad/sec)

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Step Response

Time (sec)

Am

plit

ude

77

AMIR BAGHDADI Student Number 2802166Second Year

-100

-80

-60

-40

-20

0

Mag

nitu

de (

dB)

100

101

102

103

104

-180

-135

-90

-45

0

Pha

se (

deg)

Bode Diagram

Frequency (rad/sec)

78

AMIR BAGHDADI Student Number 2802166Second Year

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.20

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Step Response

Time (sec)

Am

plitu

de

79

top related