fft and discrete functions
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a vector that contains the time (epoch) of an occurrence (many occurrences per second, for 300 seconds), and I want to determine the frequency of these occurrences, that is, plot its spectrum.
What I have done so far is counted the number of occurrences per second, but its FFT does not give me what I want.
I think that what I really need is a "signal" that is 1 at the times specified in the vector and 0 otherwise (such as stem). The FFT of that signal will give me what I want. But how can I create such a signal? I know the stem function only plots it. How can I have the FFT of that "stem" signal?
0 个评论
采纳的回答
Star Strider
2016-12-23
You can probably do what you want with a combination of thresholding and logical indexing. The Signal Processing Toolbox findpeaks function could be helpful, and would be what I would use first.
I don’t know what your data are or what counts as an ‘occurrence’, so I cannot be more specific.
4 个评论
Star Strider
2016-12-23
编辑:Star Strider
2016-12-23
My pleasure!
I am not certain where in your vector the Inf value is being calculated. It represents an overflow condition, so it occurs where the packet time is large enough that when divided by the sampling interval, it produces an infinite result. If it occurs at or near the end of the vector, I would replace it with the length of the vector by adding this line just after the ‘Intvls’ calculation assignment:
Intvls(isinf(Intvls)) = max(Intvls(isfinite(Intvls)));
If it occurs earlier in the vector, this will not produce correct data. In that instance, we need to find an alternative solution.
EDIT — If two packets are so close as to cause a nearly infinite result, either this:
MinDPktTimes = min(DPktTimes(DPktTimes > 0)); % Minimum Difference (Becomes Sampling Interval)
or this:
MinDPktTimes = min(DPktTimes(DPktTimes > 1E-8)); % Minimum Difference (Becomes Sampling Interval)
should solve the problem. You may have to tweak the threshold (here 1E-8) to get the result you want.
Another alternative is to sort the ‘DPktTimes’ sampling intervals and choose the first non-zero value as the correct one. With a large vector, this will slow your code.
更多回答(1 个)
Image Analyst
2016-12-23
Why is the mean frequency simply not the count divided by the observation time? If you have 300 thousand in 300 seconds, they occurred at a rate of one thousand per second. What other information do you need?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!