- I added a ChangeParameter to be able to dynamically change the parameters, thus no need to re-sample again. This contains the code that was initially on the constructor.
- All the global variables on the cpp files were pushed to the header files, making them class level variables. This way, if I choose to make two instances of Goertzel, then those variables will be instantiated. But since I already used a ChangeParameter, this second option may be rarely used.
Software, Firmware, Object Oriented Software Design, Architecture, Design Patterns,3D Printing, R&D, Reverse Engineer, Electronics... This is my passion. :) I love innovation
Disclaimer: I don't post details of the projects in my professional/freelance work. Most of the projects I post here are things that I do in my free time.
Friday, 12 February 2016
Arduino Signal Experiment #3-A: Goertzel using Arduino
This is the third series of the Arduino Signal Experiment. Now we will be dwelving with Goertzel Algorithm. Before we go to the actual experiment (which I will be posting on the next blog), I will discuss the Goertzel library that we will be using this time. I searched for an Goertzel Library and I found this https://github.com/jacobrosenthal/Goertzel and from my initial experiment, this pretty worked well, however, I faced some hurdles when doing multiple tone detection. I therefore checked and forked the source code. After that, I did some modifications:
Arduino Signal Experiment #2 FFT Analysis using Arduino
From the previous blog, we were able to see signals in the time domain. Now, we will try to analyze things in frequency domain. I will be using this FFT Library http://wiki.openmusiclabs.com/wiki/ArduinoFFT . To start with, I created three different sine waves on Audacity (I will be sticking to sine waves to avoid the unwanted harmonics of a square wave):
The three different sine waves are: 200Hz, 625Hz and 850Hz. I also opened the built-in Frequency Analyzer of Audacity for us to have an idea of what those 3 frequencies are.
This is the code that I wrote for Arduino http://codepad.org/UnFPb87k
On the code, notice that I used 450usec on the delay. This value is ideal for the 3 target frequencies that I will generate from Audacity and this is the explanation: The FFT bin size is 256. The output array will be FFT bin size divided by 2 (256/2 = 128). In this case, my array dimension is from 0 to 127.
@ array 0, index * (1/T) / binsize = 0 * (1/450usec) / 256 = 0 Hz
@ array 1, 1 * (1/450usec) / 256 = 8.680555555555555 Hz
@ array 2, 2 * (1/450usec) / 256 = 17.36111111111111 Hz
@ array 127, 127 * (1/450usec) / 256 = 1102.4305555555554 Hz
Which means, I will be measuring only up to 1102 Hz.
Now, after I played the tones and measured it using the Arduino program, I tried to plot the values using OpenOffice Calc:
We can clearly see that the FFT works as shown by the rise on the magnitude on 200Hz, 625Hz and 850Hz. :)
The three different sine waves are: 200Hz, 625Hz and 850Hz. I also opened the built-in Frequency Analyzer of Audacity for us to have an idea of what those 3 frequencies are.
This is the code that I wrote for Arduino http://codepad.org/UnFPb87k
On the code, notice that I used 450usec on the delay. This value is ideal for the 3 target frequencies that I will generate from Audacity and this is the explanation: The FFT bin size is 256. The output array will be FFT bin size divided by 2 (256/2 = 128). In this case, my array dimension is from 0 to 127.
@ array 0, index * (1/T) / binsize = 0 * (1/450usec) / 256 = 0 Hz
@ array 1, 1 * (1/450usec) / 256 = 8.680555555555555 Hz
@ array 2, 2 * (1/450usec) / 256 = 17.36111111111111 Hz
@ array 127, 127 * (1/450usec) / 256 = 1102.4305555555554 Hz
Which means, I will be measuring only up to 1102 Hz.
Now, after I played the tones and measured it using the Arduino program, I tried to plot the values using OpenOffice Calc:
We can clearly see that the FFT works as shown by the rise on the magnitude on 200Hz, 625Hz and 850Hz. :)
Arduino Signal Experiment #1 Sine Wave Input to Arduino using Laptop Speaker
Most of us who would like to do actual experiments for FFT or Goertzel algorithms using Arduino will need a simple signal generator to be fed into the analog pins of Arduino. We could buy some cheap signal generators from Ebay or Aliexpress, but there is a cheaper alternative that is already in front of you.... your PC or Laptop's Speaker output. In this blog post, I will show a step-by-step guide on how to use this.
Our PC or Laptop's speaker output has a DC offset of 0V(due to AC coupling) as seen on majority of audio designs. This means that the sine wave can reach down to negative voltage which is not an ideal input to Arduino since it will not be able to measure the negative voltages. To resolve this, the sine wave must have a DC offset to be able to read the positive and negative peak of the sine wave. Here is a simple circuit to do that:
On the simulation, we can see that the input V_speakerInput was offset to Vcc/2. On the actual circuit, the R4 must be removed since it was only placed here to act as a dummy load (some simulators have trouble simulating circuit without load). The R1 and R2 can range from 1K to 3K. The R3 can range from 100 to 470 ohms. Here is the actual circuit:
I am using the great Arduino Mega 2560 and I soldered the surface mount resistor and capacitor on a separate bare PCB board. As you notice, there is only 1 wire from the TRRS audio jack that I used. This is because I omitted the ground wire to avoid ground loop. I will just simply use the USB's ground as the main ground source of the circuit.
Next part is the software to generate the sine wave -----> the great open source Audacity. This is a beautiful piece of software which I use most of the time for music recording/composition. I never expected to use this someday on my engineering work as well. :) Going to back to our project, once you run Audacity, go to Generate menu > Tone and you can see that:
For the Arduino, here is the code that I am using currently using to verify if Arduino can read the sine wave (with DC offset) http://codepad.org/infZ2OLV
To prove that it works, I generated a sine wave tone on Audacity at 400Hz. I captured it using Arduino and graphed it:
Voila! A sine wave with DC offset. :)
Our PC or Laptop's speaker output has a DC offset of 0V(due to AC coupling) as seen on majority of audio designs. This means that the sine wave can reach down to negative voltage which is not an ideal input to Arduino since it will not be able to measure the negative voltages. To resolve this, the sine wave must have a DC offset to be able to read the positive and negative peak of the sine wave. Here is a simple circuit to do that:
On the simulation, we can see that the input V_speakerInput was offset to Vcc/2. On the actual circuit, the R4 must be removed since it was only placed here to act as a dummy load (some simulators have trouble simulating circuit without load). The R1 and R2 can range from 1K to 3K. The R3 can range from 100 to 470 ohms. Here is the actual circuit:
I am using the great Arduino Mega 2560 and I soldered the surface mount resistor and capacitor on a separate bare PCB board. As you notice, there is only 1 wire from the TRRS audio jack that I used. This is because I omitted the ground wire to avoid ground loop. I will just simply use the USB's ground as the main ground source of the circuit.
Next part is the software to generate the sine wave -----> the great open source Audacity. This is a beautiful piece of software which I use most of the time for music recording/composition. I never expected to use this someday on my engineering work as well. :) Going to back to our project, once you run Audacity, go to Generate menu > Tone and you can see that:
- You can generate Sine/Sawtooth/Squarewave
- You can set the amplitude and time duration
- You can even produce and mix different tones and play them all together!
For the Arduino, here is the code that I am using currently using to verify if Arduino can read the sine wave (with DC offset) http://codepad.org/infZ2OLV
To prove that it works, I generated a sine wave tone on Audacity at 400Hz. I captured it using Arduino and graphed it:
Voila! A sine wave with DC offset. :)
Thursday, 11 February 2016
MyHDL Project #2: Flexible Multiplexer Demultiplexer
https://github.com/fwswdev/MyHDLCollection/blob/master/02_FlexibleMuxDemux.py
This is a MyHDL program that contains multiplexer and demultiplexer. They both share a group of select pins. Users can change the number of mux and demux by just simply changing the BIT_WIDTH constant.
Few years back, I designed a UART Multiplexer/Demultiplexer using lots of 74HC4051. If I only knew MyHDL and XC2C128 by that time, my design could have been more compact. :)
This is a MyHDL program that contains multiplexer and demultiplexer. They both share a group of select pins. Users can change the number of mux and demux by just simply changing the BIT_WIDTH constant.
Few years back, I designed a UART Multiplexer/Demultiplexer using lots of 74HC4051. If I only knew MyHDL and XC2C128 by that time, my design could have been more compact. :)
MyHDL Project #1: Two Counters with 2 to 1 Multiplexer
Recently, I had been studying MyHDL with Xilinx CoolRunner XC2C128 CPLD. MyHDL is a very good software. I can simply reuse my existing Python skills and get started quickly with HDL designs.
https://github.com/fwswdev/MyHDLCollection/blob/master/01_TwoBlinkingLightsWith2to1Mux.py
This is a MyHDL program that has two counter (fast and slow) that outputs square waves. The counters are being controlled by a rising edge clock signal coming from a square wave signal generator (on my experiment, I used a 555 timer on astable mode). It is then fed into a 2 to 1 mux. This is tested working with XC2C128, Xilinx ISE 14.7, and Bus Pirate as the programmer.
This is the resulting test bench waveforms (I modified the internal counters to 5 and 10)
Special Thanks to this Online Wave Viewer http://www.edaplayground.com/w/home
https://github.com/fwswdev/MyHDLCollection/blob/master/01_TwoBlinkingLightsWith2to1Mux.py
This is a MyHDL program that has two counter (fast and slow) that outputs square waves. The counters are being controlled by a rising edge clock signal coming from a square wave signal generator (on my experiment, I used a 555 timer on astable mode). It is then fed into a 2 to 1 mux. This is tested working with XC2C128, Xilinx ISE 14.7, and Bus Pirate as the programmer.
This is the resulting test bench waveforms (I modified the internal counters to 5 and 10)
Special Thanks to this Online Wave Viewer http://www.edaplayground.com/w/home
Saturday, 16 January 2016
FileDB: a .NET NoSQL DB
http://www.eztools-software.com/tools/filedb/
This is a very good .NET NoSQL solution. Very lightweight. I did some example projects just for practice session using Visual Studio 2015 Community Edition. https://github.com/fwswdev/NoSQLPractice
This is a very good .NET NoSQL solution. Very lightweight. I did some example projects just for practice session using Visual Studio 2015 Community Edition. https://github.com/fwswdev/NoSQLPractice
Review: DX.com's 5A USB Charger
5V/5A (25W) USB Charger
Here is product that I bought from DX.com created by ZnDIY-BRY. Link
Recently, we have lots of devices in our home that uses USB chargers. But why did I build one?
- I know for a fact that there are USB chargers that have high current output. But some of them have very bad regulation. I bought a cheap USB charger for my mom, and it destroyed her Samsung Galaxy S3. I checked the charger and saw the voltage rise up to 5.6V at 1A, but I don't know the actual voltage when the scenario happened. We also bought from an unknown manufacturer and the voltage rises up randomly when the current draw is greater than 1A.
- Last year, I bought one product from ZnDiy-BRY, a 2 port USB charger 3A. This is a very good product. I use it in my office to charger my Galaxy Tab and Samsung Galaxy Note. Given this company's very good reputation, I bought their 5A, 4port USB charger.
- DIY and building is fun!
After I received the item, I did a very simple 3D printed bottom cover just enough to avoid the bottom part of the PCB to be in contact with our house floor.
Since this is a 25W (5V/5A) device, I chose a DC supply of 12V, 3A (36W). This is to give enough margin for the efficiency of the USB charger and the DC supply
In this test, I placed 4 devices that are in charging state - A Samsung Galaxy Note, Two Samsung Note 2, and a Sony Xperia C5. All of them are in charging state and none of them are in fully charged state. The voltage is at 4.93V on this test (my USB doctor have some issues, but if I use a multimeter, it is exactly 5V). Then, I touched the heatsink and I am surprise that there's not much heating at all.
In summary, I am very happy with this device. It passed my expectations. Now I can keep all our 220V to 5V chargers inside a cabinet and just use this superb 5A charger..
Subscribe to:
Posts (Atom)








