Write a function file that takes a domain vector t, a scalar amplitude A, and a scalar period T as inputs, and outputs a vector 5 that evaluates the ideal square wave given in Eq.1. Your function file header should match the following function S = SquareWave(t.A.T)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please use matlab.

 

Qla -
Write a function file that takes a domain vector t, a scalar amplitude A, and a scalar period T as
inputs, and outputs a vector 5 that evaluates the ideal square wave given in Eq.1. Your function file
header should match the following
function S = SquareWave(t,A.T)
Note: You must write the algorithm yourself. Do not use any built-in functions that explicitly
approximate a square waveform. Don't forget to document your function!
Q1b
Using the function from Q1a, plot a square wave having amplitude A = 1, period T = 2r, over the
domain-T ≤ t ≤T. The vector, t, must be resolved to 0.1 units.
Use a black dotted line of width 2 when creating your plot.
Q1e -
Write a function file that takes a domain vector t, a scalar amplitude A, a scalar period T and a scalar
representing the number of Fourier series terms n as inputs, and outputs a vector F that evaluates
the Fourier series solution given in Eq.2. Your function file header should match the following
function F = FourierSqWave(t.A.T.n)
Q1d
Using the same domain, amplitude, and period as specified in Q1b with the input vector t again
resolved to 0.1 units, evaluate the Fourier series for a square wave F(t) for n 11, 5, 10 and 20
terms. Plot each one on a separate 2-by-2 subplot in a new figure window.
Q1e
Using a while loop and starting with n=1 determine the minimum number of Fourier terms for
the average error Emean between solutions S(t) and F(t) to become less than 0.01. For each
iteration, also calculate the maximum error Emax and the corresponding location max- You may
refer to the appendix for the error calculation formulas.
Inside your loop, use fprintf() to output every 10th iteration as a table for tmax Emax and Emean
accurate to 4 decimals. For example, the first 3 values of the table should be:
t Emax
Emax
Enean
1
10
20
3.1568
3.1568
3.1568
1.0194
1.1928
1.3797
0.3433
0.0555
0.0382
Your table must include results for n = 1 and the final value at which the 0.01 accuracy is reached.
Note: You will need to store each iteration, as elements in vectors for Emean, Emax, and tmax to
complete question Q1g.
Transcribed Image Text:Qla - Write a function file that takes a domain vector t, a scalar amplitude A, and a scalar period T as inputs, and outputs a vector 5 that evaluates the ideal square wave given in Eq.1. Your function file header should match the following function S = SquareWave(t,A.T) Note: You must write the algorithm yourself. Do not use any built-in functions that explicitly approximate a square waveform. Don't forget to document your function! Q1b Using the function from Q1a, plot a square wave having amplitude A = 1, period T = 2r, over the domain-T ≤ t ≤T. The vector, t, must be resolved to 0.1 units. Use a black dotted line of width 2 when creating your plot. Q1e - Write a function file that takes a domain vector t, a scalar amplitude A, a scalar period T and a scalar representing the number of Fourier series terms n as inputs, and outputs a vector F that evaluates the Fourier series solution given in Eq.2. Your function file header should match the following function F = FourierSqWave(t.A.T.n) Q1d Using the same domain, amplitude, and period as specified in Q1b with the input vector t again resolved to 0.1 units, evaluate the Fourier series for a square wave F(t) for n 11, 5, 10 and 20 terms. Plot each one on a separate 2-by-2 subplot in a new figure window. Q1e Using a while loop and starting with n=1 determine the minimum number of Fourier terms for the average error Emean between solutions S(t) and F(t) to become less than 0.01. For each iteration, also calculate the maximum error Emax and the corresponding location max- You may refer to the appendix for the error calculation formulas. Inside your loop, use fprintf() to output every 10th iteration as a table for tmax Emax and Emean accurate to 4 decimals. For example, the first 3 values of the table should be: t Emax Emax Enean 1 10 20 3.1568 3.1568 3.1568 1.0194 1.1928 1.3797 0.3433 0.0555 0.0382 Your table must include results for n = 1 and the final value at which the 0.01 accuracy is reached. Note: You will need to store each iteration, as elements in vectors for Emean, Emax, and tmax to complete question Q1g.
BACKGROUND
An ideal square wave as pictured in Figure 1.1 is a non-sinusoidal waveform where the amplitude
transitions instantaneously between a fixed minimum and maximum periodically. Square
waveforms are used in a wide range of applications from electrical switches and clock timers to
sound reproduction and image processing.
Ampilude
Figure 1.1-Square Wave
A square wave with amplitude A and period I can be defined by the piecewise function
0<t<T
-T<t<0'
Eq. 1
A,
s(t) = (-A.
In practice, an ideal square wave can never be realised as the physical processes that generate the
waveform always take a finite amount of time to transition between maximum and minimum values
(i.e., they cannot act instantaneously). Therefore, these processes can introduce errors known as
artifacts around the step-discontinuity of square waves when t = T.
F(t) =
A Fourier series consists of an infinite summation of sine waves of different amplitudes, phases, and
frequencies and can be used to model any waveform - even non-sinusoidal ones! In practice, we are
limited to a finite number of Fourier series terms. The Fourier series for a square wave is given by
11-00
4A
T
Period
k=1
sin((2k-1) wt)
2k-1
1
4A
=[sin (wat)+sin(3wt)+sin(5wt) +...],
1
Where w = 2π/T and n is the number of Fourier terms.
Eq.2
Transcribed Image Text:BACKGROUND An ideal square wave as pictured in Figure 1.1 is a non-sinusoidal waveform where the amplitude transitions instantaneously between a fixed minimum and maximum periodically. Square waveforms are used in a wide range of applications from electrical switches and clock timers to sound reproduction and image processing. Ampilude Figure 1.1-Square Wave A square wave with amplitude A and period I can be defined by the piecewise function 0<t<T -T<t<0' Eq. 1 A, s(t) = (-A. In practice, an ideal square wave can never be realised as the physical processes that generate the waveform always take a finite amount of time to transition between maximum and minimum values (i.e., they cannot act instantaneously). Therefore, these processes can introduce errors known as artifacts around the step-discontinuity of square waves when t = T. F(t) = A Fourier series consists of an infinite summation of sine waves of different amplitudes, phases, and frequencies and can be used to model any waveform - even non-sinusoidal ones! In practice, we are limited to a finite number of Fourier series terms. The Fourier series for a square wave is given by 11-00 4A T Period k=1 sin((2k-1) wt) 2k-1 1 4A =[sin (wat)+sin(3wt)+sin(5wt) +...], 1 Where w = 2π/T and n is the number of Fourier terms. Eq.2
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education