Friday, January 22, 2010

DSP Tutorial #5: Frequency Analysis

This example computes the spectrum of a complex signal using the ComputeSpectrum function.

Couple important things to notice:
- Our range of frequencies on the x-axis is Fs/2
- As Fs increases, the resolution in the frequency domain is much better
- As our FFT bins (2^N) increases, the more bins we have (we can still resolve the freq content provided we meet the sample theorem, we have more bins - basically a finer plot)
- As our windows length increases, the better resolution we have

close all;
clear all;
% Time Domain Plot
figure('Color',[1 1 1]);
plot(tn,x);box off;
title(['Time Domain Signal']);
figure('Color',[1 1 1]);
title(['Freq Domain']);


claypipkin said...

I'm getting the following error after copying and pasting your code:

Error in DSP5 (line 15)

Any thoughts as to why matlab doesn't like this? I have the signal analysis toolbox installed.

Me said...

It looks like the ComputeSpectrum function is an existing function, just not one Matlab supports. I found documentation for it here.
However, it just takes the FFT of the signal. Matlab does this with functions like FFT, and freq. Here's the MatLab help page:
Good luck!