How to plot a complex power spectrum using MATLAB?

I have all the |C_n|^2 and need to plot bars which represent the energy at intervals of w (angular frequency).
I guess this would be a bar graph but I want lines instead (which I can label if possible).
Something like this but only need labels for the x axis:
https://www.oreilly.com/library/view/elegant-scipy/9781491922927/assets/elsp_0402.png
Thanks

 采纳的回答

This might have what you are looking for https://www.mathworks.com/help/matlab/ref/fft.html
You could transform the data from output space (voltage vs time or similar) into a frequency spectrum (power vs frequency or similar) and then plot that.

5 个评论

[AV's Answer moved to Comment...dpb]
I've already done the math and have my data. I just don't know how to use MATLAB very well for plotting.
What, specifically are the Cn; the coefficients or a PSD (magnitude)? Is the meaning of "complex" here in terms of the complex plane or that the spectrum has a whole bunch of structure and therefore "complex" in its shape?
Presuming it is the PSD so values of Cn are real, then look at
doc stem % for one possible choice of something like you describe
The bar plot can be made to have bars of whatever width one wants altho they do tend to get kinda' messy with a whole bunch of 'em as one would expect you would have...
Ok that is exactly what I needed. Thanks. Is there a way to add a small label at the top of each bar?
Alex...use the "COMMENT" button for clarifications, comments...they're answers to questions about the original question, yes, but not an Answer to your original question -- dpb
C_n is the complex Fourier coefficient. I need to do a complex power spectrum. So the x-axis is w (angular fequency) at intervals of pi, since w_0=pi. And at each of those frequencies I want a line going up that represents the energy of the freqrency (calculated as |C_n|^2). As I said, I only need to know how to plot the graph. I do not need help with computations.
Look at the example of computing PSD at
doc fft
It shows how to compute the frequency against which to plot the PSD and plots it with plot which is the normal thing.
You would simply call one of the other routines in place of plot to try something different. I've never done a PSD by either, so no idea how well it will actually work to display the information in a useful format, but you can give it a go... :)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Parametric Spectral Estimation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by