Top Banner
Matlab Experiments Matlab Experiments Convolution
22

Matlab ExperimentsMatlab Experiments - UCS Home

Feb 03, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Matlab ExperimentsMatlab Experiments - UCS Home

Matlab ExperimentsMatlab Experiments

Convolution

Page 2: Matlab ExperimentsMatlab Experiments - UCS Home

GoalGoal

We are going to write Matlab programsWe are going to write Matlab programs using convolution to perform calculations of sine wave and squares inputs applied toof sine wave and squares inputs applied to two low pass filters: an ideal low pass filter and an non-ideal filter using a simple RCand an non ideal filter using a simple RC circuit.

Page 3: Matlab ExperimentsMatlab Experiments - UCS Home

Impulse Response h(t)Impulse Response h(t)

• The impulse response to the Non-Ideal LowThe impulse response to the Non Ideal Low Pass (RC) filter is

11( ) ( )t

RCh−

• The impulse response to an Ideal Low Pass

1( ) ( )RCh t e u tRC

=

The impulse response to an Ideal Low Pass filter is

( ) 2 sinc(2 ) -c ch t f f t tπ= ∞ < < ∞

• See the Appendix for details

where is the cutoff frequencycf

See the Appendix for details

Page 4: Matlab ExperimentsMatlab Experiments - UCS Home

Experiments1. Write a Matlab program to calculate the output for each of the types

f f Cof filters: Ideal and RC. 2. The inputs will be sine and square waves. 3. The impulse responses are those given for each type of program.4 The cutoff frequencies should be the same for each filter4. The cutoff frequencies should be the same for each filter5. The frequencies used for each of the input signals should be the

same.6. Perform at least (more would be preferable) 3 experiments for the ( p ) p

sine wave input and at least (more would be preferable) 3 experiments for the square wave input for each of the two filters.

a) Input frequency is less than the cutoffb) Input frequency is around the cutoffb) put eque cy s a ou d t e cutoc) Several where the Input frequency is greater than the cutoffd) For the Ideal filter case with the square wave input find the frequency where

the output is undistorted7. The output of the program should plot the input signal, the impulse p p g p p g , p

response, and the output signal. It should also display the cutoff frequency of the filter and the frequency of the input signal.

8. Write a professional report which includes the Matlab code used for the Ideal and RC filters the Matlab outputs for each of thethe Ideal and RC filters, the Matlab outputs for each of the experiments, an explanation of the results, and comparison of the performance of these filters.

Page 5: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

A. Input: Sine Wavei. input frequency < cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 0.5

-1 0 1 2 3 4 5

0

Time (Seconds)Convolution

-0 5

0

0.5

1

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

0.5

Time (Seconds)

Page 6: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

A. Input: Sine Waveii. input frequency close to the cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 1.5

-1 0 1 2 3 4 5

0

Time (Seconds)

1Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 7: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

A. Input: Sine Waveiii. input frequency > cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 5

-1 0 1 2 3 4 5

0

Time (Seconds)

1Convolution

-1

-0.5

0

0.5

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

Time (Seconds)

Page 8: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

A. Input: Sine Waveiv. input frequency >> cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 25

-1 0 1 2 3 4 5

0

Time (Seconds)

1Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 9: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

B. Input: Square Wavei. input frequency < cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 0.5

-1 0 1 2 3 4 5

0

Time (Seconds)

1Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 10: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

B. Input: Square Waveii. input frequency close to the cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 1.5

-1 0 1 2 3 4 5

0

5

Time (Seconds)Convolution

-0 5

0

0.5

1Convolution

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

0.5

Time (Seconds)

Page 11: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

B. Input: Sine Waveiii. input frequency > cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 5

-1 0 1 2 3 4 5

0

Time (Seconds)Convolution

0 5

0

0.5

1Convolution

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

-0.5

Time (Seconds)

Page 12: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples1. RC Filter

B. Input: Square Waveiv. input frequency >> cutoff frequency.

5

10

Signals Cutoff Frequency 1.5915 Signal Frequency 25

-1 0 1 2 3 4 5

0

Time (Seconds)

1Convolution

-1

-0.5

0

0.5

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

Time (Seconds)

Page 13: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

A. Input: Sine Wavei. input frequency < cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 0.5

-1 0 1 2 3 4 5-1

0

Time (Seconds)Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 14: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

A. Input: Sine Waveii. input frequency close to the cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 1.5

-1 0 1 2 3 4 5-1

0

1

Time (Seconds)Convolution

0 5

0

0.5

1Convolution

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

-0.5

Time (Seconds)

Page 15: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

A. Input: Sine Waveiii. input frequency > cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 5

-1 0 1 2 3 4 5-1

0

Time (Seconds)Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 16: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

B. Input: Square Wavei. input frequency < cutoff frequency.

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 0.5

-1 0 1 2 3 4 5-1

0

1

Time (Seconds)Time (Seconds)

0

0.5

1Convolution

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

-0.5

Time (Seconds)

Page 17: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

B. Input: Square Waveii. input frequency close to the cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 1.5

-1 0 1 2 3 4 5-1

0

1

Time (Seconds)Convolution

0 5

0

0.5

1Convolution

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

-0.5

Time (Seconds)

Page 18: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

B. Input: Sine Waveiii. input frequency > cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 5

-1 0 1 2 3 4 5-1

0

Time (Seconds)Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 19: Matlab ExperimentsMatlab Experiments - UCS Home

ExamplesExamples2. Ideal Filter

B. Input: Square Waveiv. input frequency << cutoff frequency.

1

2

3

Signals Cutoff Frequency 1.5915 Signal Frequency 0.1

-1 0 1 2 3 4 5-1

0

Time (Seconds)Convolution

-0.5

0

0.5

1

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

Time (Seconds)

Page 20: Matlab ExperimentsMatlab Experiments - UCS Home

Some HintsSome Hints

• Remember the “conv” is a discreteRemember the conv is a discrete function and so the result must be multiplied by the sampling periodmultiplied by the sampling period.

• For the impulse response for the Ideal FilterFilter

1. Be careful on how you program its value for t=0.2 Recognize that h(t) is valid for all values of t2. Recognize that h(t) is valid for all values of t.

Page 21: Matlab ExperimentsMatlab Experiments - UCS Home

Appendix:RC L P FilRC Low Pass Filter

c ri idVout Vin Vouti C i

=− Vin

R

1k

C Vouti

1( )

c rdVout Vin Vouti C i

dt RdVout Vout VinC

dt R RVinC V t

= = =

+ =

+

C 1n Voutir ic

1( )

1 10;

at

pC VoutR R

Vout Ae B

pC pR RC

+ =

= +

+ = =

1

1

1 1

j CVout VinR

j C

V

ω

ω

=+

1

1

(0) 0

tRC

tRC

CB Vin

Vout Ae Vin

Vout Ae Vin

=

= +

= = +

2

1 11 1 ( )

1The cutoff (radian) frequency is defined as .c

VoutVin j CR CR

RC

ω ω

ω

= =+ +

=

1

1

(0) 0

(1 ) ( )

RC

tRC

t

Vout Ae VinA Vin

Vout Vin e u t−

= = += −

= −

RC

1(1 ) ( )( ) (1 ) ( ) ((t

RC tRCd e u th t e t

dtδ

−−= = − − −

1 11 1) ) ( ) ( )t t

RC RCe u t e u tRC RC

− −=

Page 22: Matlab ExperimentsMatlab Experiments - UCS Home

AppendixId l L P FilIdeal Low Pass Filter

It can be shown that the impulse response to an ideal low pass filter is( ) 2 sinc(2 ) here is the c toff freq enc and the "sinc" f nction is gi en as:

c ch t f f t tf

π= −∞ < < ∞where is the cutoff frequency and the "sinc" function is given as:

sin( )sinc( )

cfxx

x=

|H(f)|

fc f