Question
Using the following matlab code: % Example 5.2 Example to evaluate and unknown process is linear. % clear all; close all; t = 0:2*pi/500:2*pi; %
Using the following matlab code:
% Example 5.2 Example to evaluate and unknown process is linear.
%
clear all; close all;
t = 0:2*pi/500:2*pi; % Sine wave time function, 500 points
for k = 1:100 % Amplitudes (k) will vary from 1 to 100
x = k*sin(t); % Generate a 1 cycle sine wave
y = 30*filter([1 0 0 0 -1],1,x); % Input sine to process
output(k) = max(y); % Save max value of output
if k == 2
plot(t,x,'k',t,y+6,'k'); hold on; % Added for Figure 5.8
plot([0 t(end)],[0 0],'k'); % Add baselines
plot([0 t(end)],[6 6],'k'); % Add baselines
xlabel('Time (sec)','FontSize',14);
ylabel('x(t) and y(t)','FontSize',14);
ylim([-2.5 10]);
end
end
figure;
plot(output,'k'); % Output, horizontal scale will be in amplitude
xlabel('Input Amplitude','FontSize',14);
ylabel('Output Amplitude','FontSize',14);
Answer:
Assignment #1-1 (2 pts): Help/Doc MATLAB filter function and find the description of Y = filter(B,A,X).
Assignment #1-2 (3 pts): Based on the answer obtained from Assignment #1-1, explain what the following MATLAB code does (Note: vectors ([1 0 0 0 -1],1) defines the transfer function of this filter by defining its numerator and denominator)?
y = 30*filter([1 0 0 0 -1],1,x);
Assignment #1-3 (10 pts): But what does this filter actually do to a given input signal x? To find that out, write a script based on Ex_5.2.m such that the two sinusoidal functions of two selected amplitudes, 1 and 100, indicated below are used as the input signals and are filtered by y = 30*filter([1 0 0 0 -1],1,x). Plot the input and output signals in different colors and in one graph for each case; include the script and a snapshot picture of your results in your lab report. What is the amplitude ratio of the output and the input in each case? Find the answer from the pop-up figure window with Tools Data Statistics?
x0 = sin(t);
x100 = 100*sin(t)
Assignment #1-4 (10 pts): Modify Ex_5.2.m by replacing y=process_x(x); with y1=30*filter([1 0 0 0 -1],1,x); . Run the modified script and include a snapshot picture of the plots in your lab report. Notice that the output-input amplitude relationship is plotted as well. What code(s) are associated with the plotting of the amplitudes? Is this filtering process a linear operation? What is the slope of the output-input plot (Figure 2 Tools Data Statistics)? Is the slope value the same as the amplitude ratios you just found from Assignment #1-3?
Assignment #1-5 (5 pts): What do the for/end and if/end loops do in Ex_5.2.m? Notice that the y+6 segment in the plot function shifts the plot up by 6 units for better clarity.
Assignment #1-6 (10 pts): Now write codes in a new section to examine the linearity of two other filtering processes shown below. Write the codes such that (1) the input and output signals of each case are plotted in one graph at a selected amplitude value and (2) the output-input amplitude relationship in the 1~100 amplitude range for both filters is plotted. Are these two processes linear?
y2 = filter([1 1],1,x.*x);
y3 = filter([1 1 1],1,x);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started