Calculating Period or Frequency of a Sinusoidal Signal
19 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to write some code to calculate the period (and hence frequency) of a decaying sinusoidal signal. I'm specifically interested in calculating the times that the signal crosses a particular value. For the purpose of this example, let's assume that value is zero.
I have the signal data in a vector, with each sample being 0.01 seconds apart. My intention was to use interp1() function to return the time stamp of each time the signal crosses my value of interest, e.g. the zero value. I was hoping interp1() would just would return a vector of ALL the crossings, that way I could access whichever ones I was interested in. Then I could just take the time difference between two consecutive 'zero crossings' and that would be half the period. What I'm finding is that the interp1() function is not returning a meaningful value, presumably because the signal crosses the zero line multiple times.
It's most likely that I'm using the completely wrong function to do this, but it's all I can think of at the moment (being relatively new to matlab). I don't have the signal processing toolbox, so can't use the FFT function.
Any other suggestions would be much appreciated. Thanks, Hugh.
0 个评论
采纳的回答
Star Strider
2017-3-6
编辑:Star Strider
2017-3-6
You can find the indices of the zero-crossings of your signal with this little utility function:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
You can use those indices in a for loop with interp1 to return the ‘exact’ x-values of the zero crossings. Note that there may be a ‘wrap-around’ effect at the end, so you may want to discard the last index.
If you want to fit a sinusoidal function to your data, How to filter noise from time-frequency data and find natural frequency of a cantilever? will offer guidance, including the calculation of the period.
EDIT — Added caution about the end-effect of my ‘zci’ function.
2 个评论
Star Strider
2017-3-7
My pleasure!
You absolutely understand the ‘zci’ function.
To get the zero-crossings, subtract the median (or mean, the median may be more accurate) from your signal, find the period, then add the median value back to your original signal.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!