fft and discrete functions
조회 수: 2 (최근 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!