Thursday, October 8, 2009

Matlab FFT Frequency Axis Reconstruction

Time and time again, I find myself needing to remember how to accurately reconstruct the frequency axis of an FFT in Matlab. This is one of the ways that I have documented as being a pretty close approximation of the frequency axis. This code will also properly compute the magnitude of each frequency component.

The code below uses the signal below as an example:
y=5*sin(10*2*pi*x)+3*sin(22*2*pi*x)+cos(13*2*pi*x)+7;

Now the Code:


Now the result:


Hope you find this useful.

Monday, October 5, 2009

Eclipse C/C++ IDE File/Folder Restore

Well, I am only human and it was only a matter of time before I slipped and deleted a precious piece of code from my thesis source code folder...I was definitely freaking out because I remembered struggling to get that particular piece of code working the way I needed it.

Luckily Eclipse has a bunch of smart programmers to realize such a case. As you may or may not know, when you delete a file in Eclipse, it does not go into the trash. So if you accidentally delete something in eclipse you might initially think "I am screwed...". Little did I know, I had absolutely nothing to worry about. If you need to restore a deleted file in Eclipse just go to the project's source folder and right click on it and select:

"Restore From Local History..."

You will get a friendly window showing you several restore points for the folder.

Thursday, October 1, 2009

Matlab TightAxis Function

During one of my graduate classes I decided to create a function that makes a window that turns off all the Matlab figure toolbars and makes the axis fill the window AND scales the window to fit the image's native resolution so that no pixilization or aliasing occurs. If the image does not fit in the monitor's native resolution then the function will keep the current window size. When calling the TightAxis function make sure the current axis is the axis you want to modify as I use:
gca

If the axis you are currently interacting with is the one you want to modify just issue the command:
TightAxis(FIGURENAME)

Where FIGURENAME is a string that will be used to label the figure window.
Here is the function:

function TightAxis(title)
%First create an axis if
%the user doesn't have a gca
%and get the handle
haxis=gca;
%Best Image Fit Algorithm
set(gcf,'Visible','off')
set(haxis,'Position',[0,0,1,1])
monitorRes=get(0,'ScreenSize');
imageSize=get(haxis,'PlotBoxAspectRatio');
pos=get(gcf,'Position');
%Check for over sized images
%IF the native resolution of
%the image fits in the screen resolution
%AND the image does not contain a
%1-pixel dimension
%THEN scale the image to be displayed
%at 1x Resolution
if (imageSize(1)<=monitorRes(3)
&& imageSize(1)>1
&& imageSize(2)<=monitorRes(4)
&& imageSize(1)>1)
set(gcf,'Position',[0,0,imageSize(1:2)])
else
set(gcf,'Position',[0,0,pos(3:4)])
end
set(gcf,'Name',title,'NumberTitle','off')
set(gcf,'MenuBar','none')
zoom on;
movegui(gcf,'center')
set(gcf,'Visible','on')