Elec3730 digital and computer electronics - parsing an


Objectives

The main objective is to review some basics of C programming while at the same time learn some common techniques used in embedded system programming. There will be opportunities to reuse code from this assignment in future assignments. The first part of the assignment requires code to be written to run under Windows. The second part of the assignment takes some of the code written for Windows and targets the STM32 hardware.

The basics of reading information from files, decoding, processing and writing results back into files will be covered. This will introduce concepts of real-time processing and the use of circular buffers to temporarily store data. Audio files of a certain format will be used as the basis for questions. The audio data from these files will be read, decoded, filtered and results saved in an output file. he results of filtered wave files can also be directly observed using a media player.

While wave files are used in this assignment, the concepts used are applicable to a wide range of problems. In general, data is read from files or a stream, decoded and appropriate action taken. An example is the processing of packets used in communication, such as Transfer Control Protocol (TCP) and Internet Protocol (IP) packets. Usually information is contained in a packet consisting of a header and a payload. The header provides information about the payload to give it meaning and to allow it to be processed appropriately.

PART I

The first part of the assignment requires code to be written to run under Windows. Write your source code into Ass-01-Q01.c to Ass-01-Q04.c corresponding to each of the questions. The prototypes for all of the functions to be written are included in Ass-01.h. The sample data files referred to in each question has been included in the template. The code is run using the Ass-01 WINNT run configuration.

Whether a microprocessor is little endian or big endian determines how multi-byte information is stored. As the software written for this assignment is targeting only Windows running on an Intel Pentium processor and the STM32F4 which is a ARM Cortex-M4 processor, we will assume that little endian is being used.

Question 1

A binary file has filter coefficient data stored with the following format:

  • The first four bytes contain an integer n which is in stored in little endian format which represents the number of filter coefficients.
  • The next 8n bytes contain an array of n floating point numbers stored as 8 byte double precision which represent the filter coefficients.

A function is required that reads the filter coefficient data stored in the file filename. The number of filter coefficients is passed back in the variable pointed to by coeff_num_p. The function allocates enough memory using malloc() to store the filter coefficients and passes back a pointer to the filter coefficients pointed to by coeff_values_p. The function returns 0 if it was successful in reading the file else it returns -1.

Write the function described using the following prototype:

externintread_coefficients(int   *coeff_num_p,double  *coeff_values_p[], char *filename);

Sample data files need to be stored in the folder where the program is run.

Question 2

A Waveform Audio File Format (WAVE or WAV) is a file format standard for storing audio data. It can be used to store audio data in various formats, including Pulse Code Modulation (PCM). A reference that describe a WAV file for storing PCM audio data is given onPage 4. In general terms, it contains a header section which describes the attributes of the data section. Information in the header include:

  • Audio format code
  • Sample rate
  • Number of bits per sample
  • Number of channels (mono or stereo)
  • Data rate
  • Block alignment information

A function is required that reads information in the WAV file named filename. The header section is read and the information loaded into the structure pointed to by header_p which is of type pcm_wavefile_header_t provided by the calling function. Memory for the data section is allocated by the program and passed back using the pointer data_p. The function returns 0 if it was successful in reading the file else it returns -1. The function should also print out the header information.

Write the function read_pcm_wavefile() described above and also the corresponding function to write to a WAV file write_pcm_wavefile() using the following prototypes:

externintread_pcm_wavefile(pcm_wavefile_header_t   *header_p, char **data_p,char  *filename);

externintwrite_pcm_wavefile(pcm_wavefile_header_t   *header_p, char *data,char  *filename);

Typically the file extension of a WAV file will be .wav. When reading a WAV file, use the mode "rb" to indicate explicitly that the file to be read is a binary file.

Sample data files need to be stored in the folder where the program is run.

Question 3

Digital filters are often used to remove or enhance audio recordings. One type of filter is a Finite Impulse Re- sponse (FIR) filter. The filtering action is described by a series of coefficients, which can be stored in a file as described in Question 1. Information about filters can be found onPage 5.

A function to implement FIR filter is required which reads from an input file input_wavefilename and writes the filtered result to file output_wavefilename. The coefficients for the FIR filter are file filter_filename. having the following format: Write the above described function using the following prototype:

externintfilter(char   *filter_filename, char *input_wavefilename,char  *output_wavefilename);

Example audio files and filter coefficient files need to be stored in the folder where the program is run. The example FIR filter coefficient files have specific filtering properties. Use a media player to listen the result of the filtering.

Question 4
Parsing an string from the command line into individual words or tokens make further processing easier. The main() function already passes the input command line as an array of strings. If a terminal program is being implemented, then the code for this parsing function needs to be written.

Given a pointer inp to a NULL terminated character string, a function is required that will return the number of words and update an array of pointers *array_of_words_p[] to point to the start of each word in the input string. A word is defined as being separated by one or more spaces. Memory needs to be allocated to store the array of pointers and to store the words.

Write the function described above that has the following prototype:

externintstring_parser(char   *inp,char  **array_of_words_p[]);

The function should be able to cope with zero length strings.

PART II

The second part of the assignment targets the STM32 hardware and consists of only one question. There is actually no further coding to do other than to check that you code runs correctly and to give you some experience using the development tools and hardware. The code is run using the Ass-01 STM32 run configuration.

Question 5

Rather than using the Windows command line, the USART2 interface on the STM32F4 microcontroller will be used for serial input and output. The template project has already redirected STDIN and STDOUT to the serial port. Use PuTTY for serial.

There is no further code to write to complete this question. All that is required is to test that your code is working correctly and capture the transcript from PuTTY to demonstrate this. Try different sequences of words with one or more spaces between them. See what happens if the backspace key is used to the output of the program.

Additional Information
The following provides information of writing your source code with System Workbench using the project template provided and how to submit your source code and output transcript on Blackboard. An overview of the Software Development Tools is also available on Blackboard. Information about WAV files and digital filters are also provided.

System Workbench Template Project

A template project is available on Blackboard in the folder containing resources for Assignment 1. The one template is used to target both the hardware (STM32) and Windows (WINNT):

- Ass-01-Template-vXX.zip
Unzip the contents into the System Workbench workspace and import the project from the option in the File menu. Select General then Existing Projects into Workspace. After electing the root directory as the template project, which is Ass-01, the project will be highlighted and then click Finish. The options should be at their default values.

The run or launch configurations are not stored with the setting files in the template project, however the files for both the STM32 and WINNT targets are available to import. Using the import tool as before, select Run/Debug and the Launch Configurations. Navigate to the workspace folder and select the two files with extension
.launch and click Finish. These two will not be available from the Run menu and Debug menu. The two different targets are selected by setting the Build Configuration.

The template project is self contained and fully functional, albeit without the code to be written for the assignment. The code that tests the code to be written is already included in Ass-01.c, although you can extend the tests. Comments indicate where code is required. The following source files have been included for you to write code for each question:

- Ass-01.h
- Ass-01-Q01.c
- Ass-01-Q02.c
- Ass-01-Q03.c
- Ass-01-Q04.c
Note that some questions draw on code from previous questions. The include file only requires updating if additional functions have been defined. Note that Ass-01-Q05.c should not need to be altered.

Attachment:- template.zip

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Elec3730 digital and computer electronics - parsing an
Reference No:- TGS02809553

Expected delivery within 24 Hours