Question

In: Electrical Engineering

Write a new MATLAB function as described in the following: 1. The new function will have...

Write a new MATLAB function as described in the following:

1. The new function will have three input parameters: f, W, C. 2. Parameter f will specify the frequency of the square wave. 3. The parameter W will specify the width of the single pulse as a number of sample periods. 4. The parameter C will specify the number of square wave cycles. 5. Calculate a number of samples, N, to run the simulation for both waveforms. 6. Create one signal that is a square wave of period 2W samples and lasts for a duration of C cycles. 7. Create a signal beginning with a single pulse of amplitude 1 and a width of W samples followed by N-W samples with amplitude of 0. 8. Plot time and frequency domain plots for each. Use subplots to show all four graphs on the screen at once, arranged the same way as in the reference lecture slide. Scale the plots as necessary so that the desired characteristics can be easily seen. Label the x-axis with the correct units of time/frequency. Run the new function with f=1000, W=20, and C=10.

Solutions

Expert Solution

(F,W,C) function signal-pulse:

% define default input parameter values
if nargin < 3 C = 10;

end % C = number of cycles of square wave
if nargin < 2 W = 20;

end % W = number of samples for pulse width
if nargin < 1 f = 1e3;

end % f = frequency of square wave
disp(f)
fs = f*W*2;

% fs = sampling frequency
N = fs/W;
t = [0: N-1]* 1/fs;
% generate the square waves
S1 = square(f*t);

% Periodic Squarewave
S2 = square(f*t);

% Aperiodic Squarewave
F1 = abs(fft(S1));
F2 = abs(fft(S2));
% Plot each sinewave and then various sums
figure % plot should open figure
subplot(2,2,1);

plot(t,S1);

title('Periodic Squarewave(Time Domain)');

xlabel('Time');

ylabel('Amplitude');
subplot(2,2,2);

plot(t,S2);

title('Aperiodic Squarewave(Time Domain)');

xlabel('Time');

ylabel('Amplitude');
subplot(2,2,3);

plot(fs,F1);

title('Periodic Squarewave(Frequency Domain)');

xlabel('Frequency');

ylabel('Amplitude');
subplot(2,2,4);

plot(f,F2);

title('Aperiodic Squarewave(Frequency Domain)');

xlabel('Frequency');

ylabel('Amplitude');
end
signal_pulse(1000,20,10);

% calling function


Related Solutions

I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
MATLAB QUESTION: I have to write a function that pretty much cleans number. these are the...
MATLAB QUESTION: I have to write a function that pretty much cleans number. these are the instructions Inputs: number1 - a 1d of array of number, size doesn't matter outputs: number2 - all number in number1 that are 0 need to be set to nan and return via number2. data - storing the number of 0's in number1 that pretty much are being set to nans here's the code: function [number2, data] = cleanNumber(number1) %add your code below.. end code...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered. (Using Matlab) and "while" function 2.   Write a program that prompts the User for if they would like to enter a real...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input...
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input 3 positive integers. 2. Of the two integers a and b, the function returns the integer that has the most factors fact. 3. If both integers a and b have the same amount of factors fact, the function will return the larger integer. Test your function with the following: >> result=moreFactors(24,32,3) result = 24 (24 = 3^1 · 2^3 , 32 = 2^5 )...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
Use Matlab to write the following 1. Write code to determine whether a year is a...
Use Matlab to write the following 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100, but not by 400, are not leap years. Years divisible by 4, but not by 100, are leap years. All other years are not leap years. For example, the years 1800,...
Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT