An Introduction to Internet-of-Things Approach to Digital Signal Processing

Tutorial for Java/NetBeans Ethernet TCP Interface to FRDM-K64F Using Mbed

  Copyright Thomas P. Weldon, 2016


Notes:

1 Overview


Before doing anything, look over these items first:
This tutorial describes the use of Java/NetBeans to create a graphic interface that runs on a laptop with capability of sending and receiving messages and data over Ethernet/TCP to the RJ-45 port of an NXP FRDM-K64F.  In addition, this tutorial briefly describes the use of the mbed.org online compiler interface to program the FRDM-K64F to receive/send data over Ethernet/TCP, run the ADC (analog-to-digital converter), run the DAC (digital-to-analog converter), and perform a fast Fourier transform using the mbed CMSIS  DSP library.   The FRDM-K64F has an ARM Cortex-M4 core running up to 120MHz, 1024KB Flash, 256KB RAM, 16-bit ADCs, 12-bit DAC, and Timers.   The NetBeans interface builder is shown on the left below, and the FRDM-K64F board is on the right below.  (Note picture below for correct usb port on FRDM-K64F)

      
NetBeans interface builder on left, FRDM-K64F board on right.

The following sections cover:

 

2 Getting Started

To get your project up and running quickly, we will just compile the interface program "as is" in NetBeans (on your laptop), download the the binary to the FRDM-K64F, and run the software "as is."  

We will be using the FRDM-K64F mbed boards and your personal laptops for our projects, where the laptop acts as a server to control the FRDM-K64F mbed board as a client over Ethernet RJ-45 cables.  We will primarily use the mbed.org online compiler to create, edit, and compile client-side software program code for the FRDM-K64Fboard.  NetBeans on your personal laptops will be used  to create, edit, and compile server-side software program code

2.1 Install Netbeans

In 2016, do not install any version of NetBeans later than 8.0.  Version 8.0 works, but version 8.1 has the "JUnit  hamcrest" bug. Make sure to install the full version package that includes the Java and C++ tools.  If you do not have NetBeans installed on your laptop, install NetBeans.

The NetBeans IDE is a tool for building applications and allows the user to quickly  add buttons and widgets to a custom GUI (Graphical User Interface).  Downloads and documentation for NetBeans are available on https://netbeans.orgWARNING: if you decide to download NetBeans to your home computer, make sure that you get the same or recommended version as being used in class.

2.2 Sign up for an mbed.org developer account and download the course software 

Mbed.org hosts an online compiler that we will use to create, edit, and compile program code for the FRDM-K64Fboard.   Follow the steps below to obtain an mbed.org account to access the compiler, and follow the instructions to update your firmware before doing anything else.

z
Mbed.org compiler view.

Download the course software

  If you have not already done so, update our FRDM-K64F board firmware is updated to latest version!

2.3 Load the software binary into the FRDM-K64F and run it

The next step is to load the binary onto the FRDM-K64F board to execute the code.  In a later section below, editing the source code in mbed will be discussed.  For present purposes of getting everything up and running, only the binary executable is needed.


Flashing green LED as program is loaded.

zz

Reset button (blue arrow) on FRDM-K64F, and RGB-LED (red circle).

Run the software on the FRDM-K64F with teh ADC connected to the DAC

zz
Jumper wire connecting the DAC0out pin and the A0/PTB2 pin of the FRDM-K64F.

2.4 Run a tty/terminal to see output from the FRDM-K64F

zz
Terminal settings for TeraTerm on a winXP PC.

tpw$ ls /dev | grep usb
               cu.usbmodem1412
               tty.usbmodem1412
tpw$ screen /dev/tty.usbmodem1412 9600

zz
Terminal session output from FRDM-K64F after pressing reset button.

2.5 Compile and run the NetBeans GUI server-software used in the course

The next step is to compile and run the NetBeans software and verify that it communicates with the FRDM-K64F over the Ethernet RJ-45 interface.
z
Opening the course software from within NetBeans.

zz
NetBeans showing the interface provided in the course software.
z
NetBeans course software program twDspNetBeansFrdmK64Fether_b DSPsoundv55UI compiled and running.

2.6 Compile the FRDM-K64F client-software on the mbed compiler

The binary software that was loaded onto the FRDM-K64F has hard-coded Ethernet addresses that are not likely to be suitable for most local networks or user laptops.  Therefore, it is important to be able to change the Ethernet addresses in the code, to work with your laptop and your local area network.  The following describes the steps to upload the frdm_etherClient_netBeans_b code to mbed.org, edit the Ethernet addesses, and re-compile the code.

Importing the FRDM-K64F project into mbed

zz
Mbed import of course software.


zz
View of main.cpp, showing server addresses and port number.

const char* ECHO_SERVER_ADDRESS = "169.254.194.47";
const char* CLIENT_ADDRESS = "169.254.194.211";
const int ECHO_SERVER_PORT = 8881;
const char* SERVER_MASK = "255.255.255.0";  // Mask

   2.6.1 Checking the Ethernet address (or forcing the address on a PC/winXP)

zz
Finding the IP address of the RJ-45 on an Apple/Mac/Yosemite.

   2.6.2 Changing/editing the Ethernet address on the FRDM-K64F

z
Mbed compiling main.cpp.


2.7 Run everything: NetBeans communicates with the FRDM-K64F

Once the Ethernet addresses are correctly set in the FRDM-K64F and laptop, it should be possible to test that the NetBeans program on the laptop is able to communicate properly with the FRDM-K64F. 

To start all over, after turning everything off:
z
NetBeans running program window after getTime button is pressed.
z
Printout are in NetBeans after getTime button is pressed.

txbuf=14,0.000000E+00,0.000000E+00
txbuf=15,0.000000E+00,0.000000E+00
begin while isconnected
waiting for message from server

z
NetBeans running program window after getFreq button is pressed.

2.8 Optional items

You may wish to install one of the offline IDEs to work offline or to have debug capability (mbed.org comiler does nto support debug)

3. Mbed FRDM-K64F Tutorial

We will be using the FRDM-K64F mbed boards for our projects, and we will primarily use the mbed.org online compiler to create, edit, and compile program code for the FRDM-K64Fboard.  The following sections describe the FRDM-K64F hardware and the software used in the course.

FRDM-K64F hardware background info and users guides

The following links should help familiarize you with the hardware.  The FRDM-K64F has an ARM Cortex-M4 core running up to 120MHz, 1024KB Flash, 256KB RAM, 16-bit ADCs, 12-bit DAC, and Timers.

Note on dc bias for FRDM-K64 ADC input

The input range for the FRDM-K64F ADC (analog-to-digital converter) is approximately 0 to 3.3 Volts.  Therefore, to digitize an audio signal, it is best to add a blocking capacitor to revent any external dc voltages, and add a 1.65 volt dc bias after the blocking capacitor as illustrated below.  Suggested values are C1=1uF and R1=R2=2000 ohms.  If audio gain is needed for a project, a useful audio amplifier is the TLV2462 in the DIP package.


z
Suggested circuit for interfacing between and external audio signal and the ADC on the FRDM-K64F.



ARM, mbed, and FRDM-K64F software info and users guides

Optional: Simple mbed FRDM-K64F Blinky Example

Overview of the FRDM-K64F code in mbed

The following describes the software code for the project.

Libraries in FRDM-K64F mbed code

A number of libraries are used in the code.

#include "mbed.h"                           //functions for LED, print, ADC, DAC, digital I/O
#include "EthernetInterface.h"        //used to do Ethernet and TCP
#include "arm_math.h"                   //used in math and DSP and FFT
#include "arm_common_tables.h"  //used in math and DSP and FFT

DigitalOut pinD0(D0);                     //a digital output
DigitalOut grnled(LED_GREEN);  //green RGB-LED
DigitalOut bluled(LED_BLUE);    
DigitalOut redled(LED_RED);
Serial pc(USBTX, USBRX); //default 9600 baud, N-8-1
AnalogOut  dac0out(DAC0_OUT);   //12-bit DAC
AnalogIn  adc0in(A0); //A0 = PTB2  //16-bit ADC
Ticker timer1;                                     //timer used to time ADC and DAC

FRDM-K64F Ethernet mbed code

zz
View of main.cpp, showing server addresses and port number.

const char* ECHO_SERVER_ADDRESS = "169.254.194.47";
const char* CLIENT_ADDRESS = "169.254.194.211";
const int ECHO_SERVER_PORT = 8881;
const char* SERVER_MASK = "255.255.255.0";  // Mask

eth.init(CLIENT_ADDRESS,SERVER_MASK,CLIENT_GATEWAY);
eth.connect();


while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) {
  pc.printf("Client waiting: Unable to connect to (%s) on port (%d) eth.getIPAddress= %s\n",
  ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT,eth.getIPAddress() );
  wait(1);
}

nrx = socket.receive(rxbuf, RX_BUF_LEN);

        if(strncmp("tdat",rxbuf,4)==0) {
            pc.printf("client time data requested:\n");
            txbuf[0]=(char)0;
            sprintf(txbuf,"%d\n",TEST_LENGTH_SAMPLES);
            pc.printf("txbuf=%s ",txbuf);
            socket.send_all(txbuf, strlen(txbuf) );
            for(int nn=0; nn<TEST_LENGTH_SAMPLES; nn++) {
                txbuf[0]=(char)0;
                sprintf(txbuf,"%d,%E,%E\n",nn,timeDat[nn*2],timeDat[nn*2+1]);
                pc.printf("txbuf=%s \n",txbuf);
                socket.send_all(txbuf, strlen(txbuf) );
            }

FRDM-K64F ADC/DAC and digital I/O mbed code

The FRDM-K64F code also uses a timer to control timing of the 12-bit DAC (digital-to-analog converter) and 16-bit ADC (analog-to-digital converter). 

timer1.attach(&myDacAdc,12.5e-6f); // calls the myDacAdc function every 12.5 microseconds
while(adcCount<TEST_LENGTH_SAMPLES)

(PTC->PDOR)=dat0; //clear    these 4 code lines send a pulse whennever this code runs
(PTC->PDOR)=dat1; //set   
(PTC->PDOR)=dat1; //set
(PTC->PDOR)=dat0; //clear
dacOut=((adcCount & 0x07)<<9);
DAC0->DAT[0].DATL = (uint8_t)((uint16_t)(dacOut)      & 0xFF); //low 8 bits of DAC
DAC0->DAT[0].DATH = (uint8_t)(((uint16_t)(dacOut) >> 8) & 0x0F); //high 4 bits of 12-bit DAC
tpAdc0in=adc0in.read_u16();

z
Signals at D0 pin (yellow trace) and DAC0out pin (blue trace).

 

FRDM-K64F FFT mbed code

For signal processing in the embedded processor of the FRDM-K64F
See the Mbed CMSIS DSP libraries for DSP functions (FFT, matrices, serial, etc.s
       float32_t fftDat[TEST_LENGTH_SAMPLES*2];
        for (int nn=0; nn<TEST_LENGTH_SAMPLES*2; nn++)
             fftDat[nn]=timeDat[nn];
        pc.printf("begin fft  \r\n");
        arm_status status = ARM_MATH_SUCCESS;
        arm_cfft_radix2_instance_f32 S;
        ifftFlag = 0;   //forward (ifftFlag=0) or inverse (ifftFlag=1)
        doBitReverse = 1; //Set=1 for output to be in normal order
        fftSize = TEST_LENGTH_SAMPLES ;//WARNING: only choose power of 2 from 16 to 4096
        status = arm_cfft_radix2_init_f32(&S, fftSize,   ifftFlag, doBitReverse);  
        pc.printf("begin fft  \r\n");
        arm_cfft_radix2_f32(&S, fftDat);
        pc.printf("end fft  \r\n");
        for (int nn=0; nn<TEST_LENGTH_SAMPLES; nn++)
        pc.printf("fft dat=%u %f %f \r\n", nn,fftDat[2*nn],fftDat[2*nn+1]);

4. Java/Netbeans Tutorial

The following tutorial introduces Java/NetBeans tools for use in course projects.  In the following, audio sound files are used as the source of signals that will be digitally processed.   Similar data can be obtained using the ADC in the FRDM-K64F.  The audio files have the added benefit of allowing the results of digital filtering operations to be heard.   In addition,  the graphic user interface provides display of the time and frequency domain for the signals.  Finally, the user can easily add DSP functionality to buttons on the interface by editing/adding Java code, as outlined below.

However, please note that in this course the focus is on doing the signal processing in the embedded processor of the FRDM-K64F, as illustrated on the FFT example included in the mbed software file frdm_etherClient_netBeans_b_zip_k64f.zip .  See the Mbed CMSIS DSP libraries for FRDM-K64F DSP functions such as FFT, matrices, serial, etc.
The advantage of Java and NetBeans is that it is readily available and portable across many machines/platforms.  The Java programming language is quite similar to C++, and C++ users will quickly adapt to Java.  Notable differences are that Java does not support overloaded operators, and "this" in Java is equivalent to "*this" in C++. 

Start NetBeans

See installation of NetBeans above.  When you first run NetBeans, you should see something similar to the window shown below.  NetBeans has many different views and window panes.  A typical layout of NetBeans is shown below.

xx

Above: Typical layout
.


Load the twDspNetBeansFrdmK64Fether_b-DSPsoundv55a GUI for the class

    1. You should already have the NetBeans course software downloaded, as described above
    2. You should already have compiled and run the NetBeans course software, as described above
    3. In Netbeans, use the menu-bar command File->OpenProject as shown below to navigate and open the twDspNetBeansFrdmK64Fether_b project in your new folder  (NetBeans>File>OpenProject ) (In some versions of NetBeans, the "open as main project" field should be highlighted when you select twDspNetBeansFrdmK64Fether_b)
xx

Above: OpenProject dialog.  Notice "Project name" field indicating a valid project folder.


NetBeans should have opened the project directory. This directory contains all of the project's  files, including its Ant script, directories for storing sources and tests, and a directory for project-specific metadata. To view the project hierarchy, use NetBeans' Projects window pane as illustrated in the image on the left below.  Click on the twDspNetBeansFrdmK64Fether_b icon to expand the hierarchy. To view the directory hierarchy, use NetBeans' Files window.  Both views are shown below..


     x           x 

Above: Projects view on left, files view on right.  Use tabs to select each view.



Open the twDspNetBeansFrdmK64Fether_b-DSPsoundv55a GUI (Graphical User Interface) 

    1. In the ProjectsPane,  navigate down through the hierarchy to twDspNetBeansFrdmK64Fether_b>SourcePackages> tpw.DSPsoundv55a>DSPsoundv55aUI.java as shown on the left below
    2. Right-click on DSPsoundv55aUI.java and select "Open" to open the interface
    3. The GUI should appear in the center of the NetBeans window, as shown below.   You may toggle between the graphical view shown below and the corresponding source code using the "Source" and "Design" buttons.
    4. Although you will not need to add any buttons to your interface, you can just drag a jButton from the palette of widgets and drop it wherever you want it (try dropping it to the left of the "output filename" on the interface.  You can use the  "NetBeans>Edit>Undo" command from the top menu bar to undo it.
    5. To preview your GUI design, click the "Design Preview" icon: x.

The twDspNetBeansFrdmK64Fether_b-DSPsoundv55aUI GUI shown below contains all of the buttons and graphical display areas that will be used in the course.  Some of the buttons are functional, but you will need to add the remaining functionality throughout the projects in the course.



Above: Opening DSPsoundv55aUI.java from project pane. 



Saving Backup Copies of a Project

Now would be a good time to save a backup copy of your work.  This is easily done in the ProjectPane.  Make sure the ProjectsTab is selected so that the ProjectPane is visible in NetBeans.  Then, right-click your top-level project (twDspNetBeansFrdmK64Fether_b) in the ProjectPane, and select  CopyProject.  The default name of the backup copy, twDspNetBeansFrdmK64Fether_b_1, should appear.


Building and Running a Project

At this point try to build the project

zz

x

Above: Running project window.


If the program was correctly downloaded, the default audio input files sin3264.au and sin32.au should already be in the project directory, available to load.  So, try the following tests to make sure everything is working.
  1. Click the Read1 and Read2 buttons to see if two different signals of peak amplitude 0.929 with length 2048  (0-2047) appear in the window.
  2. Click the Play button to hear the audio.
  3. Click Zoom2 and Zoom 4 to toggle zoom on the beginning of the signal.
  4. Click WritePng to write the graphics to an output file that you can view later or import into your reports.
  5. Click Read2 and then 2lnFFT to show a somewhat unusually displayed frequency domain (not in dB!!), as shown in the figure below.


x
Above: Running project window.

Adding Actions to Buttons (Event Handlers)

The window has many other buttons, but nothing happens when the other buttons are pressed (except for a printout at the bottom of the window).  To make something happen, we need to add code to the event handlers. 

For example, suppose we wish to change the message for the "A" key.  To do this:

1. Close any running versions of twDspNetBeansFrdmK64Fether_b-DSPsoundv55a
2. In NetBeans,  right-click the "A" button in the GUIbuilder pane as shown below, and select Events>Mouse>mouseClicked[jButtonAMouseClicked]

zz
Above: Accessing mouseClicked event function from GUIbuilder by right-clicking "A" button.


3. The source code for the function associated with the "A" button, jButtonMouseClicked(), should appear as shown below.  This function is called anytime the "A" button is pressed.  The jEditorPaneBottom.setText() function sets the message at the bottom of the window.   The refreshDisplay() function is supplied for your convenience, so that you do not have to worry about redrawing the display.  You should call the refreshDisplay() function at the end of every buttonFunction that you implement, so the display is always updated after any button is pressed.  Every time refreshDisplay() runs, it plots the real part (not imaginary) of the signal stored in the variable dispData.  So, to change the plot, just change the contents of dispData (more on that later).


zz
Above: Source code view of the jButtonAMouseClicked() function associated with the "A" button.


4. To see what happens, change the first line from "String fkey = new String("A");" to "String fkey = new String("A hello");" and Rebuild and Run the program.  When the "A" key is pressed, you should see ""A hello clicked" print at the bottom of the window.

5. Finally, note that you can access the "MouseClicked" action functions from the source code view by simply clicking on the function in the NavigatorPane at the lower left of the NetBeans window (also shown above).  Alternatively, you can scroll through the source code view.

Note, for the Ethernet FRDM-K64F project:

Using the Myclass Java Class

While simple functions may be directly coded in Java, it is often much easier to create a new Java class to encapsulate functions and data.   Such a Java class enables quick re-use of common functions such as addition, multiplication, Fourier, convolution, etc.

In the DSPsoundv55a program, a Java class called "Myclass" is included.  This class includes arrays of real and imaginary data, and provides functions  for Fourier, addition, etc.  To view the class, right-click the Myclass.java file in the ProjectPane and open the file.  As shown below, the Myclass functions are listed in the NavigatorPane in the lower left.  Click on the plus(int x) in the NavigatorPane to jump to the plus(int x) function in Myclass.java, as shown below. 

Above: Source code view of plus(int x) function in Myclass.java class.

In the source code above, plus(int x) uses a for-loop to add the integer value stored in variable x to all the elements in the array of real parts of the data, (this.re)[nn].  Notice that there is no return value (hence the declaration of "public void"), and the operation is done on the original copy of the data.  Further, note that there is a different plus function defined for adding two Myclass arrays together, plus(Myclass x).  Finally, note that there is an equals(Myclass x) function to implement "=" that would normally be implemented as operator= in C++.  (Recall that Java does not support overloaded operators.)

Note, for the Ethernet FRDM-K64F project:

Data Structure of Myclass Java Class

The basic data structure of the "Myclass" Java class is declared at the top of  Myclass.java:
public class Myclass {
private byte  data[];        //byte-data (data) array
private float  re[];        //real data array
private float  im[];        //imaginary data array
private int n;
From this, it can be seen that the class consists of  an array of bytes called data[], two arrays of floating point called re[] and im[], and an integer n.  In use, the integer n holds the size of the arrays, and arrays re[] and im[] hold the real and imaginary data, as "floats" (floating point arrays).  (In Java, the array indices range from 0 to n-1.)  Hence, a Myclass object can hold the sequence of sound samples  in the real part of the array.  For example, a 2048-sample sound clip could be stored in the array re[] from re[0] to re[2047].  Similarly, the complex values of a Fourier transform of the sound clip could be stored with the real parts in re[] and imaginary parts in im[].  The byte array is only used for internal use in reading audio files and playing sound, so do not use the byte array and assume that any operation such as addition, division, etc. is NOT performed on the byte array.

Constructors, Equals, and Functions of Myclass Java Class

As in C++, a constructor is used to create/instantiate a new instance of a Myclass object.  For example:
Myclass a = new Myclass();
Myclass b = new Myclass(1024);
a.equals(b);
a.equals(b.fft());
a.plus(b);
In the above, the first statement creates a new Myclass object using the default constructor.  The default constructor is defined by the function Myclass() in Myclass.java, and creates a default-sized array of size n=10.  In the second statement above, the constructor used is Myclass(int nn), since the second invocation has an int argument, i.e., 1024.  Therefore, the second constructor creates a Myclass object "b" with arrays of size 1024, and loads "n" with the value n=1024.  Next, recall that Java methods (Java functions) are invoked by the syntax "object.method."  So, on the left side of the period must be a Myclass object, and the right side must be a valid Myclass method.  The statement "a.equals(b);" would set the contents of "a" equal to "b."  The statement "a.equals(b.fft());"  sets "a" equal to the FFT of "b."  Note that the function fft() is a somewhat unique function that it returns a Myclass result on the stack, and can therefore be used as the argument of the equals() function.  In addition, because the result is returned on the stack, you MUST use the equals operator to immediately fetch the result off the stack.  This Myclass return value is evident in the declaration of the FFT function as "public Myclass fft()" whereas a declaration "public void whatever()" would return no value on the stack, and is the more typical behavior.

The final statement above, "a.plus(b)," would add the contents of b to the contents of "a" and place the result in "a."  The following Java code is a simple implementation of a function "public void plus(Myclass x)" that would implement the above function to add two Myclass arrays together.  In the example below, a for-loop adds the corresponding byte-data, real, and imaginary arrays.  As in C++, the value of n in "xx < n" below would refer to "this.n", the value of n associated with the Myclass that invoked the function.  More specifically, the value of n would correspond to "a.n" for the invocation "a.plus(b)".  Also note that it would be better to add some code at the beginning of the function to check that the two arrays were the same size and that they were not null arrays (uninitialized).
public void plus(Myclass x)
{
for (int xx = 0; xx < n; xx++)
        {
          (this.re)[xx]  =  (this.re)[xx] + (x.re)[xx];
          (this.im)[xx]  =  (this.im)[xx] + (x.im)[xx];
        }
}
 
In the code above, an extremely important concept is the keyword "this,"  where "this" is a handle/pointer that refers to the invoking object.  The invoking object is the object to the left of the period, so "a: is the invoking object in the "a.plus(b)"  example. 

Another important feature in Java is the concept of overloaded methods, where the particular function/methofd that is invoked depends on the types of arguments used.  For example, there can be another declaration of the "plus" method that adds an integer "c" to the Myclass variable "a" that would be called by writing the comand a.plus(c).   In essence, the method "plus" is overloaded, meaning that it has different algorithms that may be called, depending on the types of variables involved.  The new example of an integer "plus" command would be declared in the class perhaps as follows:
public void plus(int yy)
{
for (int xx = 0; xx < n; xx++)
        {
          (this.re)[xx]  =  (this.re)[xx] + yy;
          (this.im)[xx]  =  (this.im)[xx] + yy;
        }
}

Example of the Power of Java Classes

A good example of the power of Java classes is the implementation of the 2lnFFT button.  The code to implement taking the FFT and log-magnitude of a soundfile using the 2lnFFT button is essentially only two lines long:

private void jButton2lnFFTClicked(java.awt.event.MouseEvent evt) {                                     
// TODO add your handling code here:
         dispData.equals(dispData.fft());
         dispData.lnmag();
        refreshDisplay();            
    }                 

Note the simplicity of the above code, and the readability of the code. 

So, encapsulate all of your complex code into powerful functions in the Java class Myclass.  This efficient use of your Java class will make the high-level code much easier to read and will make it easy to re-use your functions.

Data Storage in dispData, inData1, inData2 in DSPsoundv55aUI.java

Returning to the twDspNetBeansFrdmK64Fether_b GUI program DSPsoundv55aUI.java, three Myclass variables are used to store/access data.  These variables are defined near the bottom of theDSPsoundv55aUI.java file, and are accessible to all of the functions  in DSPsoundv55aUI.java.  Variables inData1 and inData2 are used to store the contents of sound files read in by the "Read1" and "Read2" buttons.  Variable dispData is used to hold the contents of the data displayed on-screen.  Anything stored in dispData will be plotted on-screen at the next invocation of the refreshDisplay() function. 

For example, consider the implementation of the "Read1" button in  "private void Read1Clicked(...)." as illustrated below. 

private void Read1Clicked(java.awt.event.MouseEvent evt) {                             
// TODO add your handling code here:

        inFileName1 = jTextFieldInfilename1.getText();
        inData1.readau(inFileName1);
        dispData.equals(inData1);

        refreshDisplay();            
 }                            

The first statement fetches the filename from the window text field and stores it in the global String variable inFileName1.  The second statement uses the global Myclass variable inData1 to invoke the readau() function to read the file.  This readau() function resizes the arrays in inData1 and stores the audio data in the real array re[] contained in inData1.  Finally, the contents of inData1 are stored in dispData, so that the newly read sound file will be displayed after refreshDisplay() is called in the final statement.  (Recall that the refreshdisplay() function always refreshes the display using the current contents of dispData.)


File Output in twDspNetBeansFrdmK64Fether_b DSPsoundv55aUI.java

As part of the function refreshDisplay() in DSPsoundv55aUI.java, three ASCII text files are written every time the display is refreshed.  Files  F1.txt and F2.txt are written with the contents of global variables inData1 and inData2 (typically the soundfile data read in by buttons "Read1" and "Read2.").   File disp.txt is written with the contents of global variable dispData, the data currently displayed on-screen.  These files allow the user to see the raw data associated with the plots on-screen.

In addition, the "Write png" button allows the user to save the current display as a ".png" image file for easy inclusion of data in project reports.


More Java Resources

If learning Java, try not to become bogged down in details of window design, widgets, graphics, pop-ups, and so forth.   NetBeans takes care of most of the user interface issues.  Also, do not study applets, these are not required.  Your time will be best spent of  1) what is a Java class, 2) for-loops, 3) arrays, 4) constructors, 5) variables.
java tutorials 1
java tutorials 2
java tutorials 3

for loops
arrays
math operators

NetBeans : http://www.netBeans.org/ 

Some Differences between Java and C++

  1. java - no overloaded operators (operators such as +, * /  can only work for primitive types such as int and float)
  2. java - no overloaded equal
  3. Java - no pointers
  4. C++ "*this" is equivalent to "this" in Java
  5. Java - no prototypes
  6. java - no headers
  7. java - no destructor
  8. java - uses "new" but not "delete" - java garbage collector frees memory
  9. java array declaration would be "Myclass w0 = new Myclass( 10 );"  instead of C++ syntax "Myclass w0(10);"

Miscellaneous tips/notes

Execution Problems when Running Outside NetBeans
Note:
if the windows-click-and-run is installed incorrectly, you will need to open a command-prompt window and type "java -jar myjarfile.jar" to run myjarfile.jar. The jar files are most commonly in the "dist" subdirectories of NetBeans projects.  Or, you may just run your application from within NetBeans.

Some Error Problems

On occasion, the project may not run on a machine that is running an older version of Java.  You may get error messages such as "Unsupported major.minor version 49.0."  You can check the version of Java on the machine with the "java -version" command.  This tutorial used version 1.5 of Java.  You may need to upgrade the version of Java on the machine to get your code to run properly.
 

Other References:


java:  https://www.oracle.com/java/index.html
and https://en.wikipedia.org/wiki/Java_(programming_language)
NetBeans : http://www.netBeans.org/  




Oracle and Java are registered trademarks of Oracle and/or its affiliates.  NetBeans is a trademark or registered trademark of Oracle America, Inc.  NXP, CodeWarrior, Kinetis, and Processor Expert, are trademarks of NXP.  Texas Instruments, TI, C2000, and Code Composer Studio are a registered trademarks of Texas Instruments Incorporated.   Adafruit is a registered TradeMark of Limor Fried.  ARM, Cortex and Keil are registered trademarks of ARM Limited (or its subsidiaries).  Apple, Yosemite, Mac OS, iPhone, iPad, MacBook, Mac, iTunes, and Xcode are trademarks of Apple inc. Arduino is a registered trademark of Arduino. All other product or service names are the property of their respective owners.