Plotting Frequency Stem Graph in Matlab

In summary: Hz. It seems like the FFT is tricked into thinking it's the 329.63 Hz fundamental when it's not. The Fundamental Frequency is the frequency that the FFT is analysing. It is not necessarily the frequency you hit the string at.
  • #1
inadaze
20
0
Hi,
I need some generous person to help me! I am having problems figuring out how to analyze my recorded sounds in Matlab. I would like to plot a stem graph where my x-axis is the frequencies present in the sound and my y-axis to be the magnitude of these frequencies in dB.
If there is some one out there with a heart of gold who could help, please do...
Everything that I have tried has given me one or neither of what I need.

Thanks
Jay
 
Physics news on Phys.org
  • #2
The command you want is 'fft' for "fast Fourier transform".

It analyzes the data you give it and breaks it up into frequencies and magnitudes.

The tricky part is formatting the data you're sending into the fft.

I can't find the exact page I used to figure out the code (and I haven't used it for some months now, so I can't recall well enough to explain). http://www.ele.uri.edu/~hansenj/projects/ele436/fft.pdf .pdf seems to be a decent explanation of the process. It has some simple examples.

Give it a shot. If you're still having problems, post your code and we'll take a further look.

Welcome to the forums!
 
  • #3
Frequencies

Hey thank you!
That was very helpful. One problem is that I what I need is to measure the magnitude in dB of the fundamental frequency in Hz. What I mean by frequency in Hz is something that can be translated into a musical note (ex: the note middle C = 261.626Hz). Is there a way to transfer the magnitude of the sinusoid (if I understood correctly: that is what the fft does?) into the magnitude in musical note sense?

Thanks again.
Jay
 
  • #4
If you have data of a pure sinusoid with frequency of 261.626Hz (by pure I mean computer generated with no white noise), the fft function will be a single vertical line at 261.626.

If you add in white noise, either computer generated or from experimental error, you'll have other lines which will be orders of magnitude smaller. If you're doing an experiment, you'll probably also find that the harmonics show up as well.

I'm not entirely certain, but I'm pretty sure that the length of the lines are the strength of the frequency in dB. If it isn't, you should be able to do a google search to find a way to code the conversion.
 
  • #5
What you're describing is actually somewhat difficult to do. The FFT is the heart of the process, but there's a bit more to it.

The FFT returns power values. Depending upon the FFT routine you're using, you might be getting back complex values as well. The first step, if you have complex values, is to take the modulus of each complex value. If your FFT routine already returns real values, don't worry about this step.

Now, find the largest power value in the FFT. That's the fundamental, which you're going to label as 0 dB. You'll measure the power in the other harmonics as relative to the fundamental. Call the largest value in the FFT, say, fundamental_power.

To get the values into decibels, first divide each value in the FFT by the power in the fundamental (fundamental_power), then take 20 times the base-10 logarithm of each.

- Warren
 
  • #6
What your saying may solve the problem I am having, but I don't fully understand. I am new to this sort of thing. I noticed that when I record a sound in x, then run:
F = abs(fft(x,fs));
I get a bunch of peeks at what seems to be frequency levels. I was told that the first peek is the fundamental and all the others are harmonics. This does not always seem to be the case though. But you say that it is the peek with the highest amplitude? Are you sure?

Does this fft return what you say is complex values? if so how do I take the modulus?

I guess once I understand the above, perhaps I may understand what you wrote about the dB and such.

Thanks
Jay
 
  • #7
Since you're taking the absolute value of the fft results, you're seeing real numbers. The highest peak is the normally the fundamental -- your ear hears the loudest component the most, and that defines the basic note that's being played. Of course, if you have two peaks of nearly equal intensity, it'd be hard to say which is really the fundamental. Normally, the lowest frequency component is the fundamental.

- Warren
 
  • #8
I just thought of something. Is the Fundamental Frequency always the intented frequecny. What I mean is if I hit the low E string on my guitar which should be analyzed at 329.63 Hz (if my sources are correct) could it be possible that the fundamental of this string is something other then 329.63 Hz.
The reason I say this is because when I record my low E string, I find a peak at the 329.63 Hz mark but it is neither the first nor the highest peak. How can this be?

Jay
 
  • #9
Low E

Here is an example of my low E on a guitar after the FFT.
here you can see what I was talking about.

Jay
 

Attachments

  • LowE.bmp
    16.4 KB · Views: 667

Related to Plotting Frequency Stem Graph in Matlab

What is a frequency stem graph in Matlab?

A frequency stem graph in Matlab is a visual representation of the frequency distribution of a dataset. It plots the number of occurrences of each data point on a vertical axis against the data points themselves on a horizontal axis.

How do I create a frequency stem graph in Matlab?

To create a frequency stem graph in Matlab, you can use the stem function. First, load your dataset into Matlab and then use the stem function with the dataset as the input argument. You can also customize the appearance of the graph by adding labels, titles, and changing the color and style of the stem lines.

Can I plot multiple datasets on the same frequency stem graph in Matlab?

Yes, you can plot multiple datasets on the same frequency stem graph in Matlab by using the hold on command. This will allow you to plot multiple stem functions on the same graph, each representing a different dataset. You can also use the legend function to label each dataset on the graph.

How can I save my frequency stem graph in Matlab as an image?

To save your frequency stem graph in Matlab as an image, you can use the saveas function. This will allow you to specify the file format and location where you want to save the image. You can also use the print function to save the graph as an image in different file formats, such as jpeg or png.

Can I change the scale of the frequency stem graph in Matlab?

Yes, you can change the scale of the frequency stem graph in Matlab by using the xlim and ylim functions. These functions allow you to specify the minimum and maximum values for the x and y-axis, respectively. This can be useful if you want to zoom in on a specific area of the graph or change the range of data displayed.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
795
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Back
Top