Question

2. Develop a live script document in Matlab that allows setting a phase and magnitude of...

2. Develop a live script document in Matlab that allows setting a phase and magnitude of a signal in dynamic mode. The script shall include a plot of the signal.

3. The script shall allow the setting of a sampling rate in dynamic mode. The live script shall sample the signal at the dynamically set sampling rate given in samples per cycle and will store the samples into a matrix. Plot the samples within the script.

4. Within the same live script, calculate the corresponding real and imaginary components filters. Apply the filters to the sampled values saved previously and display the real and imaginary filter outputs in a plot.

5. Calculate the magnitude of the sampled signal and display in a plot together with the original signal and sampled signal. Plot separately the calculated phase angle. Label all plots properly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2 answer

Live scripts are program files that contain your code, output, and formatted text together in a single interactive environment called the Live Editor. In live scripts, you can write your code and view the generated output and graphics along with the code that produced it. Add formatted text, images, hyperlinks, and equations to create an interactive narrative that you can share with others.

To create a live script in the Live Editor, go to the Home tab and click New Live Script. You also can use the edit function in the Command Window. For example, type edit penny.mlx to open or create the file penny.mlx. To ensure that a live script is created, specify a .mlx extension. If an extension is not specified, MATLAB® defaults to a file with .m extension, which only supports plain code.

Open Existing Script as Live Script

If you have an existing script, you can open it as a live script in the Live Editor. Opening a script as a live script creates a copy of the file and leaves the original file untouched. MATLAB converts publishing markup from the original script to formatted content in the new live script.

To open an existing script (.m) as a live script (.mlx) from the Editor, right-click the document tab, and select Open scriptName as Live Script from the context menu. Alternatively, go to the Editor tab, click Save, and select Save As. Then, set the Save as type: to MATLAB Live Code Files (*.mlx) and click Save.

Add Code

After you create a live script, you can add code and run it. For example, add this code that plots a vector of random data and draws a horizontal line on the plot at the mean.

n = 50;
r = rand(n,1);
plot(r)

m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')

By default, MATLAB autocompletes block endings, parentheses, and quotes when entering code in the Live Editor. For example, type if and then press Enter. MATLAB automatically adds the end statement.

MATLAB also autocompletes comments, character vectors, strings, and parentheses when split across two lines. To escape out of an autocompletion, press Ctrl+Z or the Undo button. Autocompletions are enabled by default. To disable them, see Editor/Debugger Autocoding Preferences.

When adding or editing code, you can select and edit a rectangular area of code (also known as column selection or block edit). This is useful if you want to copy or delete several columns of data (as opposed to rows), or if you want to edit multiple lines at one time. To select a rectangular area, press the Alt key while making a selection.

For example, select the second column of data in A.

Run Code

To run the code, click the vertical striped bar to the left of the code. Alternatively, go to the Live Editor tab and click Run. While your program is running, a status indicator appears at the top left of the Editor window. A gray blinking bar to the left of a line of code indicates the line that MATLAB is evaluating. To navigate to the line MATLAB is evaluating, click the status indicator.

If an error occurs while MATLAB is running your program or if MATLAB detects a significant issue in your code, the status indicator becomes an error icon . To navigate to the error, click the icon. An error icon  to the right of the line of code indicates the error. The corresponding error message is displayed as an output.

You do not need to save your live script to run it. When you do save your live script, MATLAB automatically saves it with a .mlx extension. For example, go the Live Editor tab, click  Save, and enter the name plotRand. MATLAB saves the live script as plotRand.mlx.

Display Output

By default, MATLAB displays output to the right of the code. Each output is displayed with the line that creates it, like in the Command Window.

ou can change the size of the output display panel by dragging left or right on the resizer bar between the code and output.

To clear an output, right-click the output or the code line that created it, and select Clear Output. To clear all output, right-click anywhere in the script and select Clear All Output. Alternatively, go to the View tab and in the Output section, click the Clear all Output button.

When scrolling, MATLAB aligns the output to the code that generates it. To disable the alignment of output to code, right-click the output section and select Disable Synchronous Scrolling.

To move the output in line with the code, click the  output inline button to the right of the live script. You also can go to the View tab and in the View section, click the  Output Inline button.

To only display output, controls, and formatted text and hide the code, click the hide code button. To show the code again, click the output inline button or the output on right button.

To modify figures in the output, use the tools in the upper-right corner of the figure axes or in the Figure toolstrip. You can use the tools to explore the data in a figure and add formatting and annotations. For more information, see Modify Figures in Live Scripts.

To open individual outputs, such as variables and figures, in a separate window, click the button in the upper right corner of the output. Variables open in the Variables editor, and figures open in a new figure window. Changes made to variables or figures outside of a live script do not apply to the output displayed in the live script.

Format Text

You can add formatted text, hyperlinks, images, and equations to your live scripts to create a presentable document to share with others. For example, add a title and some introductory text to plotRand.mlx:

  1. Place your cursor at the top of the live script and, in the Live Editor tab, select Text. A new text line appears above the code.

  2. Click Aa Normal and select Title.

  3. Add the text Plot Random Data.

  4. With your cursor still in the line, click the button to center the text.

  5. Press Enter to move to the next line.

  6. Type the text This script plots a vector of random data and draws a horizontal line on the plot at the mean.

For more information including a list of all available formatting options, see Format Files in the Live Editor.

To adjust the displayed font size in the Live Editor, use the Ctrl + Mouse Scroll keyboard shortcut. The change in the displayed font size is not honored when exporting the live script to PDF, Microsoft® Word, HTML, or LaTeX.

3 answer

The sampling rate is the number of samples collected per second. In most typical cases, this is (roughly) a fixed (single) value during the time you are sampling.

For a given sampling frequency F, the differences between time points of each sample (dT) is 1/F, hence, when you know dT , you also know F (=1/dT).

You can estimate dT based on your data as, for instance, the average/median or mode value of the differences between the time stamps.

t = [0.00 0.31 0.59 .90 1.21 1.48 1.81] % time stamps in in seconds
dt = mean(diff(t))
F = 1 / dt % Hz

answer 4

here is an example showing amplitude and phase plots of your defined function:

t = 1:100;
y = 4 * sin(50 * t) ./ (6 * t);
figure, plot(t, abs(y)), title('Amplitude plot')
figure, plot(t, angle(y)), title('Phase plot')

and explination of code is

fs = 100; % It is sampling frequency
t=0:1/fs:5; % It is time series used to generate signal x
x = 4 * cos(2 * pi * 10 * t + pi / 6); % x is function of t
X = fft(x); % This statement computes Fourier transform of x
n = length(x); % length(x) gives the array length of signal x
c = (-1 * fs) / 2:fs / n:fs / 2 - fs / n; % It generates the frequency series to plot X in frequency domain
subplot(4, 1, 1),plot(t,x); % This subplot shows the signal x vs. time series t
subplot(4, 1 ,2),plot(c,fftshift(abs(X))); % This subplot shows the Fourier spectrum of x with zero frequency component shifted to center
subplot(4, 1, 3),plot(c,phase(X)); % This subplot shows the phase distribution of X (Fourier transform of x)
subplot(4,1 ,4),plot(c,real(X)); % This subplot shows the real component of X spectrum

Add a comment
Know the answer?
Add Answer to:
2. Develop a live script document in Matlab that allows setting a phase and magnitude of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Starting with the definition of complex power and the symmetrical sequence components, develop the expression...

    1. Starting with the definition of complex power and the symmetrical sequence components, develop the expression of the 3-phase complex power in terms of the symmetrical sequence components. Show steps in detail. For numerical example use the following per-unit values: ?" = 1.3∠5°, ?* = 1.4∠ − 114°, ?- = 1.25∠124° V" = 1.2∠15°, ?* = 1.35∠ − 110°, ?- = 1.15∠134° 2. Develop a live script document in Matlab that allows setting a phase and magnitude of a signal...

  • Using MATLAB!!! Please and thank you (5 points) Use Matlab to plot the magnitude and phase...

    Using MATLAB!!! Please and thank you (5 points) Use Matlab to plot the magnitude and phase of as a function of ω over the interval 0 If the input is ω 2π (5 points) What is the FS representation of y[n]? (5 points) Plot x[n] and y[n] over the range 0 to 24. If either has an imaginary component you must plot both real and imaginary parts .You must hand in a published .pdf of your script that shows the...

  • Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. •...

    Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. • Get acquainted with Matlab/Octave 1) Start MATLAB and change the “Current Directory” in the top of the window (or type) >> cd '' (example: >> cd 'C:\NIU\lab2') Alternatively, if you don't want to use MATLAB, you can open a web-browser and go to “octave-online.net”. 2) Download and execute LAB2forStudent_A.M with >> lab2forStudent_A and observe that it produces a Discrete-Time (DT) signal xVec. 3) TO...

  • summatize the following info and break them into differeng key points. write them in yojr own...

    summatize the following info and break them into differeng key points. write them in yojr own words   apartus 6.1 Introduction—The design of a successful hot box appa- ratus is influenced by many factors. Before beginning the design of an apparatus meeting this standard, the designer shall review the discussion on the limitations and accuracy, Section 13, discussions of the energy flows in a hot box, Annex A2, the metering box wall loss flow, Annex A3, and flanking loss, Annex...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT