Question
Introduction In many engineering applications, created or measured data contains a signal of interest plus noise. The noise causes the data to vary in a
Introduction
In many engineering applications, created or measured data contains a signal of interest plus noise. The noise causes the data to vary in a random way (often dramatically) such that it becomes difficult to see trends in the signal. It is typically desirable to reduce the impact of noise on the signal by smoothing the data. Smoothing reduces large and short-term variations in the data. There are many methods that may be used to smooth data. A simple one is to replace each data point with the median of three data points the data point of interest, the data point before it, and the data point after it. The median of a set of numbers is the middle number when the list of numbers is sorted in ascending order. In other words, it is the value above which half of the numbers lie and below which the other half of the numbers lie. For example, the median of the three numbers 8, 1, 2 is 2. Note that the median is different than the average (or mean). To smooth a set of numbers using the median method, a window three numbers wide is slid across the list of numbers. The number in the center of the window is replaced with the median of the three numbers in the window. For example, below is a list of noisy numbers. The lines above and below the list represent windows three numbers wide. Above (or below) each window is the median value for the three numbers in that window. If the process is repeated throughout the list, the result is the list of smoothed numbers shown below the list of noisy numbers.
Noisy List 3 -5 2 -8 6 -7 -6 7 9 2 1
Smoothed List 3 2 -5 2 -7 -6 -6 7 7 2 1
Notes: - This method requires that the list contain a minimum of three numbers.
- The list may contain an even or odd number of numbers.
- The first and last numbers in the list are unchanged.
- For this lab a smoothed number will NOT be used to smooth the next number in the list. In other words, only original (noisy) numbers are used when calculating median values.
In this lab, you will write a C++ program that will read a sequence of numbers from a file and smooth the numbers using the median method described above. The program will then write the original numbers and smoothed numbers to a different file in addition to the average and standard deviation of the numbers before smoothing and after smoothing (see Lab 4 for average and standard deviation equations).
Program Specification
Write a C++ program that does the following:
- Prompts the user to enter the name of the input file that contains the noisy numbers.
- Checks for input file open failure. If a failure occurs, notify the user and terminate the program.
- Prompts the user to enter the name of the output file to which the noisy numbers, smoothed numbers, and the average and standard deviation of both lists will be written.
- Checks for output file open failure. If a failure occurs, notify the user and terminate the program.
- Reads in the noisy numbers from the input file.
- Calculates the average and standard deviation of the list of noisy numbers.
- Smooths the list of noisy numbers to create a list of smoothed numbers.
- Calculates the average and standard deviation of the list of smoothed numbers.
- Writes the list of noisy numbers, the list of smoothed numbers and the average and standard deviation of both, to the output file.
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