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

(This is for C++) To implement a channel identification method to measure the ef

ID: 3916613 • Letter: #

Question

(This is for C++)

To implement a channel identification method to measure the effect of the channel, we need a comparison technique. What is the best way to compare two signals? The answer for this critical question is found in mathematics: Euclidean Distance. In digital voice communication, channel identification is been done by applying the Euclidean distance technique.

EUCLIDEAN DISTANCE

In mathematics, the Euclidean distance or Euclidean metric, is the "ordinary" distance between two points that one would measure with a ruler, and given by the Pythagorean formula. In one-dimensional signal processing, the distance between two points on the real line is the absolute value of their numerical difference. Thus, if x and y are two points on the real line, then the distance between them is given by: sqrt((x-y)2)=|x-y|

If we measure the distance between two data series rather than two points, the Euclidean distance formula becomes

where:
q1,q2,q3,.....,qN represent reference signal data

p1,p2,p3,.....,pN represent channel data

If there were no distortion in a given channel, that channel output file would be exactly the

same as the reference signal. In that case, Euclidean distance would be zero. (q1=p1, q2=p2,... qN=pN).

-------------------------------------------------------------------------------------------------------------------------------------------------------

Your task is to develop a C++ program that will do this:

- Request information from the user.

- Open data files and write data to 1-D arrays.

- Calculate Euclidean distance for each channel, compared to the reference channel.

- Determine channel classification based on the given decision criteria.

- Report on the quality of the communication channel(s) in a single file.

GIVEN:

REFERENCE SIGNAL: This is the input data file, consisting of a one-dimensional data array with one data point per second.

THREE CHANNEL OUTPUT SIGNALS: These are output data files from three different channels, in the same format as the input data file. Each file contains one data point per second, in the form of a one dimensional array. The channel output signals have the same number of data points as the reference signal. Assume that there is no delay in any of the channels. Use these files to test your program.

DO NOT ASSUME a given number of data entries in the data files. The user may provide files with an arbitrary number of data points. You may assume that the data files will have the same number of data points as the reference signal file.

USER INTERFACE:

-Ask user to enter the name of the reference file.

-Ask user to enter the name of the output (channel data) file.

-Display an error message and end the program if either file cannot be found.

-Display a confirmation message to inform user that the analysis is complete.

-Write the classification report to a text file named as LastName_Channel.txt which will be saved to the default folder.

-Ask the user if they want to analyze another channel.

-Using the same reference file (do not ask user again for reference file name), ask

user to enter the name of the next output file.

-If a subsequent data file cannot be found, display an error message and end the program normally.

-Each channel report will be appended as a new line in the classification report file. Only one text file will be written.

-To end the program normally (if at least one channel was analyzed), display a message that the analysis has been saved to LastName_Channel.txt. Close all files before ending the program.

-The results file, named according to the convention LastName_Channel.txt, will appear as in the screen shot below, with one exception. Instead of naming the channels as Channel 1, Channel 2, etc., the channels will be designated with the filename that the user provided. The word "Decision" will be replaced with the classification for that channel.

Detailed Requirements:

Three Functions

1. The function ReadData will read a single data file and store the data in an array. The user will supply the name of the file, as described in the User Interface section. Use the following syntax to convert the user's filename to a C-style string when you open the file:

in_file.open(filename.c_str())

This example assumes that the input file stream object is named "in_file" and the string in which the user's filename will be stored is named "filename". For other naming conventions, change the example accordingly.

The ReadData function will be called each time the user supplies a filename. If a file cannot be found, then an error message must display.

2. The function EuclidDistance will calculate the Euclidean distance for the given channel. It will produce a numeric result according to the Euclidean distance formula. Additional information about producing code to calculate Euclidean distance is found on the next page.

3. The function ChannelResult will classify the channel according to the criteria found on the next page. The resulting channel classification will be appended to the results file named according to the conventionLastName_Channel.txt.

PSEUDOCODE FOR EUCLIDEAN DISTANCE CALCULATION:

Distance (D) i = Reference Signal(RS) i – Measured signal at the Output of the Channel (MOC)

i Di = RS i – MOC I for example q21 – p21

Square of the distance SqD = Di2 for example (q21 – p21)2

Do this calculation for all data points for a particular channel.

Cumulative Distance(CD) = Sum of all N SqD = (SqD1 + SqD2 + SqD3 + ....... + SqDN)

Euclidean Distance ( ED) = square root of Cumulative Distance ?(CD) => ED

You are going to calculate Euclidean Distance (ED) by utilizing the EuclidDistance function for each channel requested by the user.

DECISION CRITERIA (CHANNEL CLASSIFICATION):

Develop a function named ChannelResult for channel classification. The input for this function is the Euclidean Distance (ED), and the output is the decision about that particular channel. There are four possible classifications.

-If the Euclidean Distance (ED) less than or equal to 0.5 then that channel can be used for communication. This channel is classified as BEST.

-If the ED is less than or equal to 1.0 and greater than 0.5 then that channel can be seen as a viable alternative if something happens to the BEST channel. This channel is classified as GOOD.

-If the ED is less than or equal to 3.0 but greater than 1.0 that channel will be considered as a worst case option. This channel is classified as LAST OPTION.

-If the ED is greater than 3.0 then the channel is useless. This channel is classified as NOT GOOD.

NOTES:

NOTE 1: Use the input data files attached to the assignment to test your program. However, your program will get file names from the user. Do not use hard-coded file names. Remember to convert to c-style strings for compatibility with C++3.

NOTE 2: You may clear the screen with system("CLS"); if needed.

--------------------------------------------------------------------------------------------------------------------------------------------------------------

A total of 4 Input Data files are used for this program:

Channel_1_output.txt

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
#include<math.h>

using namespace std;

int readData(string, double[]);
double euclidDistance(double[] , double[]);
string channelResult(double);

//For testing
int main(){


ofstream outfile;
string filename;

//In the array the the first value, i.e. index 0, contains the number of elements in the array ahead
double refer[100];//Assuming a max data of 100
double inp[100];
char exi = 'y';


//For reference data
cout<<"Please enter reference data file name: ";
cin>>filename;

if(readData(filename, refer) == -1){//Unsuccessful attempt
cout<<"Reference file not available, Exiting ";
return -1;
}


//For output file
cout<<"Please enter output file name: ";
cin>>filename;
outfile.open(filename.c_str(), ofstream::out | ofstream::app);
if(!outfile){
cout<<"File not available. Exiting ";
return -1;
}
cout<<"All files inputted correctly"<<endl;


while(exi != 'n' && exi != 'N'){
cout<<"Please enter input data file name: ";
cin>>filename;

if(readData(filename, inp) == -1){//Unsuccessful attempt
cout<<"Input file not available, Exiting ";
return -1;
}


string str = channelResult(euclidDistance(refer, inp));
cout<<"This channel is ""<<str<<"" ";
outfile<<str<<endl;

cout<<"Do you wish to continue?(y/n)";
cin>>exi;
}
outfile.close();
return 0;
}

int readData(string name, double arr[]){
ifstream in_file;
in_file.open(name.c_str());

if(!in_file){
return -1;//Not successful
}

int i = 0;
while(in_file){
i++;
in_file>>arr[i];
}

arr[0] = i-1;

in_file.close();
return 0;//Success

}

double euclidDistance(double refer[], double inp[]){
int i = 0;
double ans;
ans = 0;

for(i = 1; i <= (int)refer[0]; i++){
ans += (refer[i] - inp[i])*(refer[i] - inp[i]);
}

ans = sqrt(ans);

return ans;

}

string channelResult(double val){

cout<<val<<endl;;
if(val >= 0 && val <= 0.5)
return "BEST";
else if(val > 0.5 && val <= 1)
return "GOOD";
else if(val > 1 && val <= 3)
return "LAST OPTION";

return "NOT GOOD";
}