Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an mfile using the switch statement to allow the user to choose what te

ID: 3639301 • Letter: 1

Question

1. Write an mfile using the switch statement to allow the user to choose what temperature scale they would
like to use for the input value: Celsius, Fahrenheit or Kelvin. The program will accept a temperature from the
user in their scale and output a temperature in the other scales. The user should specify the value of the
temperature as a numeric input and the temperature scale as a “string” or “character” input.
The scales used for this assignment are Celsius, Kelvin and Fahrenheit.
The following problem considers temperature conversions. The program must use the following
equations and any algebraic manipulation of the following equations that give relationships between
temperatures in Fahrenheit (TF), Celsius (TC), Kelvin (TK), and Rankine (TR):
TF ? TR ? 459.67
32
5
9
TF ? TC ?
TR TK
5
9
?
Use fprintf to output the data in complete sentences. Also restate the input data (showing 1 decimal place for
the input temperature scale of data) and then state the data in the equivalent scales.
Output the Celsius temperature in a decimal format with 2 decimal places.
Output the Fahrenheit temperatures in a decimal format with 3 decimal places.
Ouput the Kelvin temperature in exponential format with 3 decimal places.
Put in a condition of error in the program if the wrong “string” or wrong “character” is given.
Use fprintf to notify the user of the error.
Use the following data for input that will be submitted as the execution of the program:
74 degrees Fahrenheit, 88 degrees Celsius, 125.5 degrees Kelvin. Execute the program 4 times in the
command window to show each scenario given in the sample output.
(use filename system: Lastname_12temperature_first_initial.m )
Sample Output
Scenario1
(Heading goes here)
What scale is your temperature on?
Enter c-for Celsius: f-for Fahrenheit: k-for Kelvin: c
Please enter the temperature value: 88.0
For the input temperature of 88.0 degree Celsius:
88.0 degree Celsius is equal to XXXX Fahrenheit.
88.0 degree Celsius is equal to XXXX Kelvin. (see
Scenario2
(Heading goes here)
What scale is your temperature on?
Enter c-for Celsius: f-for Fahrenheit: k-for Kelvin: f
Please enter the temperature value: 74.0
For the input temperature of 74.0 degree Fahrenheit:
74.0 degree Fahrenheit is equal to XXXX degree Celsius.
74.0 degree Fahrenheit is equal to XXXX Kelvin.
Scenario3
(Heading goes here)
What scale is your temperature on?
Enter c-for Celsius: f-for Fahrenheit: k-for Kelvin: k
Please enter the temperature value: 125.5
For the input temperature of 125.5 Kelvin:
125.5 Kelvin is equal to XXXX degree Celsius.
125.5 Kelvin is equal to XXXX degree Fahrenheit.
Scenario4
(Heading goes here)
(Error message of your choice)

Explanation / Answer

Fs=48000; %Specify Sampling Frequency Ts=1/Fs; %Sampling period. Ns=512; %Nr of time samples to be plotted. Num = [0.0818 0.1691 -0.0355 0.7979 -0.0355 0.1691 0.0818]; %Numerator Coefficients as generated by fda tool t=[0:Ts:Ts*(Ns-1)]; %Make time array that contains Ns elements %t = [0, Ts, 2Ts, 3Ts,..., (Ns-1)Ts] f1=2400; f2=10000; f3=11500; f4=20000; x1=sin(2*pi*f1*t); %create sampled sinusoids at different frequencies x2=sin(2*pi*f2*t); x3=sin(2*pi*f3*t); x4=sin(2*pi*f4*t); x=x1+x2+x3+x4; %Calculate samples for a 4-tone input signal grid on; N=6; %FIR requires filter order (N) to be EVEN %when gain = 1 at Fs/2. A=1; %FIR filters have no poles, only zeros. B=Num; %Taking Coefficients generated by fda tool for j=1:Ns %Now apply this filter to our 4-tone test sequence sum=0; %Calculating the output using convolution for i=1:7 if((j-i)>0) sum=sum +Num(i)*x(j-i+1); end end y(j)=sum; end subplot(2,1,1); %Two subplots will go on this figure window. Npts=200; plot(t(1:Npts),x(1:Npts)) %Plot first Npts of this 4-tone input signal title('Time Plots of Input and Output'); xlabel('time (s)'); ylabel('Input Sig') subplot(2,1,2); %Now go to bottom subplot. plot(t(1:Npts),y(1:Npts)); %Plot first Npts of filtered signal. xlabel('time (s)'); ylabel('Filtered Sig'); figure; %Create a new figure window, so previous one isn't lost. subplot(2,1,1); xfftmag=(abs(fft(x,Ns))); %Compute spectrum of input signal. xfftmagh=xfftmag(1:length(xfftmag)/2); %Plot only the first half of FFT, since second half is mirror imag %the first half represents the useful range of frequencies from %0 to Fs/2, the Nyquist sampling limit. f=[1:1:length(xfftmagh)]*Fs/Ns; %Make freq array that varies from %0 Hz to Fs/2 Hz. plot(f,xfftmagh); %Plot frequency spectrum of input signal title('Input and Output Spectra'); xlabel('freq (Hz)'); ylabel('Input Spectrum'); subplot(2,1,2); yfftmag=(abs(fft(y,Ns))); yfftmagh=yfftmag(1:length(yfftmag)/2); %Plot only the first half of FFT, since second half is mirror image %the first half represents the useful range of frequencies from %0 to Fs/2, the Nyquist sampling limit. plot(f,yfftmagh); %Plot frequency spectrum of input signal xlabel('freq (Hz)'); ylabel('Filt Sig Spectrum');