Frequency power spectrum of Sine, Square, Sawtooth, and Triangle Waveforms

Today I came across an interesting MATLAB code example today from the University of Maryland: http://terpconnect.umd.edu/~toh/spectrum/HarmonicAnalysis.html. Prof. Tom O’Haver did a wonderful job with this example, but I had some problems with MATLAB crashing while running it. The program may be more resource-intensive than it appears.

My screenshots can be seen in a Picasa web album for higher resolution here: http://picasaweb.google.com/kruckenberg.1/FFTOfWaveformPower

Sine wave:
The frequency analysis of a basic sine wave shows that it consists of only a single frequency at 250 Hz.

Square wave:

A square wave with the same frequency has its highest peak at the fundamental frequency and the power is reduced by 1/4 at each odd harmonic of the fundamental frequency.

Sawtooth Wave:

A sawtooth wave includes both odd and even harmonics, and the power reduces by half at each harmonic.

Triangle Wave:

A triangle wave has a similar set of harmonic frequencies to a square wave (odd harmonics), but each one is distributed over a wider range rather than focused at a specific frequency. At each odd harmonic, the power is reduced significantly.

A triangle wave was not included in the original post, but I added one for my own purposes. In MATLAB, a triangle wave is created using the sawtooth function as shown:

y=sawtooth((f1+f2/100)*x,.5);

Categories: Math problems, PC Software

Current Project: Using Excel for macro scripting in a spreadsheet

Current Project: Using Excel for macro scripting in a spreadsheet

Hologram Manufacturing

February 13, 2009 Leave a comment

The Honors program at Ohio State University offers a course about the science and art of holograms, taught by Dr. Harris Kagan. The course numbers are Art H455 and Physics H455. The course is fantastically interesting, but the instructors are typically unprepared for lectures so only about 5 hours of coursework takes place in a 10 hour week of classes. That’s a lot of time for busy people to invest.

The image on the right shows a sculpture I made in the holography laser lab. Students have opportunities to form concepts and create holograms on holographic film using the physics concepts learned in class discussions. Here I’m displaying a concept of the noteworthiness of creating an identity among giants. The title of this piece is “Identity.”

Here’s a presentation I gave on the manufacturing of holograms for security and entertainment purposes using embossing techniques.
PowerPoint Presentation (pptx)
Hologram embossing video (wmv)

Real-time USB in Matlab (2 of 2)

December 24, 2008 1 comment

Posting history:

Real-time USB in Matlab (1 of 2)

Real-time USB in Matlab (2 of 2)
Last month I had started a project using a TI MSP430 to communicate over USB with MATLAB and Simulink, and today I finished the real-time display of room temperature in Simulink.

Here is the end result. It’s a simple display and scope at the top level, but I used a roundabout method to choose data from the stream of USB data.

The completed files for displaying temperature from the USB MSP430RF2500 can be downloaded here:

Save GMail messages as files, including attachments

December 7, 2008 2 comments

GMail does not make it easy to save messages as files, but there are some practical reasons you may want to do so:

  • You may want to email several messages to another person as an attachment. This is supported in most email clients, but not typically in webmail.
  • You may want to save a copy of a message on your computer to access it offline.

Saving a *.eml file from the GMail Interface
It is possible to save a GMail message as an *.eml file including both the message and attachments, but it is not intuitive in the web-based interface.
  1. In the top right corner of any message, there is a down arrow ▼ that gives more options for dealing with messages. Select “Show original” from this list.
    More Options > Show original
  2. Lots of text is shown in a new window. This is the actual content of the email message with attachments appended at the end. Different browsers support saving this page differently, but in any browser you can copy the text and paste it in Notepad. In Internet Explorer or Mozilla Firefox you can choose to save the page from the File menu and select “Text File.”
  3. Save the file with a *.eml extension (mymessage.eml).

The *.eml extension is probably associated with your email client, so you should be able to double-click on the file to open it and view the original content and any attachments. If you would like to forward these attachments, you can attach them to an email like any other file.

Making the process easier… but more complicated
If you would use this process a lot and would like to look into some coding, this process could be automated. The GMail URL’s allow for a shortcut method to view the files using a bookmarklet or greasemonkey script. These are the URL’s of the “Show Original” link and the original message:
Original Message
“Show Original” output
A script would simply need to do some text manipulation to put the message ID in the right place to show the original email text. Automatically saving as a *.eml file would be a plus, too.
Categories: Innovation, PC Software

Real-time USB in Matlab (1 of 2)

November 8, 2008 3 comments

The TI MSP430 wireless development tool (eZ430-RF2500), pictured on the right, can communicate with a PC using a virtual serial port over USB and also use wireless ZigBee communication to communicate with other low power modules.
The development kit comes with a demo program to show how both the wireless and serial communication can be used. The eZ430-RF2500 Sensor Monitor Demo displays the temperature, voltage, and signal strength (~distance) of all nearby modules.
Today I’m interested in establishing real-time communication between the USB-adapted device and a PC using MATLAB Simulink.
Virtual serial port communication with MATLAB
* Note: When the MSP430 drivers are properly installed, the device is listed in the Device Manager  under Ports (COM & LPT) as MSP430 Application UART (COM11).
The following MATLAB *.m file code is used to read the transmitted serial signals from the MSP430 device:
s = serial(‘COM11’);
set(s,’BaudRate’,300000,’DataBits’,8,’Parity’,’none’,’InputBufferSize’, 128);

fopen(s);
s.ByteOrder = ‘bigEndian’;
data = fread(s);
values(:,1) = data;

fclose(s)
delete(s)
clear s

disp(char(data)’)
This is the output of the MATLAB script, which corresponds to the signals sent by the MSP430 device.
Node:HUB0,Temp: 79.1F,Battery:3.6V,Strength:000%,RE:no  
This method allows real-time communication with the device by simply looping this code to display signals as they are received.
Applying this concept to Simulink
The same results can be achieved by using MATLAB Simulink if the INSTRUMENT CONTROL TOOLBOX is available.
The Simulink model uses only the “Query Instrument” block from the “Instrument Control Toolbox.”
The only trick to using the virtual COM port at COM11 is that the block’s drop down menus only allow serial COM ports COM1 through COM4. The workaround is to define the variable ‘s’ used in the *.m file version of the communication above, which points to COM11. This is done by running two lines of code when the model starts in the following way:
1.  When viewing the Simulink model, open the Model Properties at File > Model Properties.
2.  Look at the “Callbacks” tab.
3.  Add the following text to the InitFcn callback:
s = serial(‘COM11’);
set(s,’BaudRate’,300000,’DataBits’,8,’Parity’,’none’,’InputBufferSize’, 60);
4.  Double-click on the Query Instrument block in the Simulink model.
5.  Choose the “Use interface object from the MATLAB workspace” radio button and type in “s” (no quotes).
This procedure displays each byte received from serial communication with the MSP430 as received in the MATLAB *.m file version. I’d like to go further to condition the received data and identify battery voltages and temperatures to be plotted independently, but that will have to be left for a future project.

Stylianos Kyriakides

August 17, 2008 Leave a comment
Status of Stylianos Kyriakides and Spiridon Louis at 1-mile marker of Boston Marathon

Kyriakides won the 1946 Boston Marathon to bring the world’s attention to the suffering Greek people crushed by the Nazis. He survived the massacre of Kalavryta in WWII and the Greek civil war to run Marathons and show that his people were still proud and strong.

This is a well-made video tribute to Kyriakedes by NBC shown before the 2004 Olympic Games in Athens
NBC Documentary about Stelianos Kyriakides found here:
  1. http://video.google.com/videoplay?docid=-3674732552610240499#8m6s
  2. http://video.google.com/videoplay?docid=-3674732552610240499&q=kyriakides&total=18&start=0&num=10&so=0&type=search&plindex=0
Categories: Appreciation, Inspiration