How to use FFT on my data?

9 次查看(过去 30 天)
a

采纳的回答

Star Strider
Star Strider 2018-3-20
Other peaks may exist, although if the constant, (or ‘d-c’) offset is large enough, you will not be able to see them.
Try this:
id = data(:,2); % to load current values from the second column of my .txt
i = id - mean(id);
That should reveal the other peaks.
  8 个评论
Patrik Soukup
Patrik Soukup 2018-3-22
If I use the absolute value of I, the plot is upside down then, instead of being scaled 0 up to -1000, its scaled 0 to 1000. I used to have this part of the code in my code as well, but it seemed like there´s no way of ploting absolute value of fft data scaled in negative values, such as -dB. Then if I set the limits of Y axis, it deform the data completely
Star Strider
Star Strider 2018-3-22
Taking the absolute values first should not cause your data to plot upside down. Taking the absolute value is the correct way to calculate the spectrum and convert it to dB.
I described essentially this procedure in my earlier Comment:
Ia = abs(I);
Iref = max(Ia);
Inorm = 20*log10(Ia/Iref);
Note that decibels are defined with respect to the base 10 logarithm, not the natural logarithm. I corrected that in the code I posted here.
As for the scaling, you can certainly divide the dB values by 10 to get them to go from -100 to 0. However, this significantly distorts your amplitude information, and the units are no longer dB.
See if these changes improve your results.

请先登录,再进行评论。

更多回答(2 个)

Patrik Soukup
Patrik Soukup 2018-3-26
Hallo sir, I corrected everything that caused problems and the code works now, another problem I´m facing is windowing. I decided to use either Hann or Hamming window to filter my signal from spectral leakage, but the example I´ve found in help is far from what I was expecting. The syntax is w=hann(L);, where L is a positive integer calculated by L=N+1, where N is what I dont understand. Let´s say I´m using code similar to the above and I get an amount of magnitudes in freq. domain and I would like to apply, let´s say Hann window, where shall I start? Seen the equation and variables in help, yet I can´t understand.
Would appreciate any insight.
Regards, Patrik
  1 个评论
Star Strider
Star Strider 2018-3-26
The ‘L’ parameter is the length of the Hann window, in units of samples. (The purpose of the window functions is to reduce the effects of using a finite sequence to represent an infinite sequence.)
I use windows to design filters, and do not generally use them to calculate Fourier transforms, because they significantly distort the transformed data. My signal processing references only discuss them in the context of filters.
As I read my references, ‘L’ should be the length of your signal. See for example hanning ,hamming window in matlab? (link).

请先登录,再进行评论。


Patrik Soukup
Patrik Soukup 2018-4-5
Dear Star Strider,
I would like to ask you if you could help me to add some kind of marker to hightlight an area I want to emphasize. I´m trying to plot a signal in frequency domain via below and I would like to add some thin line (or something like that) on...lets say 49,4 Hz and on about 20 other frequency values. There´s probably a way to draw it line by line, but I´m looking for some easier way, because I´m about to do the same on about 10 other plots. I would highly appreciate any help.
Regards,
Patrik
  3 个评论
Patrik Soukup
Patrik Soukup 2018-4-6
编辑:Patrik Soukup 2018-4-6
Thanks for answer sir,
I gave you insufficient information and I´m sorry for that. I´m really trying to plot a vertical line on certain value of frequency, such as you suggested. In the meantime, I got to this kind of code
line([x x], get(gca, 'ylim'),'Color',[1 0 0],'LineWidth',0.35);
and it works fine,One thing I´m wondering about it the width of the line, it seems to me like the line can´t be thiner than 1, am I right? If I´m not, is there any way to make the line thiner than 1? Tried 0.35 but it looks the same as 1, when used width=2, there was a significant difference and the line was thicker.
Regards,
Patrik
Star Strider
Star Strider 2018-4-6
The default line width is 0.5 points. It may be that it is not possible to define a line width less than that. I cannot find that specific information in the documentation, so I do not know for sure.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by