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!