how to generate a Sine wave with changable frequency in mfile?
조회 수: 4 (최근 30일)
이전 댓글 표시
Dear all,
I would like to generate something similler to a PLL sine signal locked on a measured sine signal. for that i have detected the Zeros of my measured, lets say, voltage signal and calculated the freuqncy from counting the number of points between two zero crossing. (the frequency of the measured signal is not constant and changing with time). by using the following equation that was achieved:
f = 1./(2*diff(Zeros));% where Zeros are my detected zerocorssing times in s.
so by knowing the following:
1- I know the frequency of my measured signal (f vector length is not equal to the length of measured signal)
2- I know my sample rate of my measured signal and my time.
3- sin(2*pi*f*t) will generate my locked sine signal to the measured sine wave signal (Voltage)
my question: why am i not getting a correct sine wave signal with the same frequency of the measured signal?
note: Zeros is a vector containing the interpolated time values when my sine wave signal corss the zero value. (so i only have frequency values at the diff(Zeros) values and not at the same sample rate of the measured signal).
Can anyone help me to condition my calculated frequency signal to have the same lenght as the measured signal (and the correct time steps) in order to make the sin(2*pi*f*t) works correctly?
Best Regards
댓글 수: 2
dpb
2014년 8월 7일
Can't really tell w/o some actual code and a (small) dataset that illustrates the problem, but --
a) if it's not constant frequency your description seems to only have an average over the whole period so it wouldn't ever match any one portion, and
b) zeros is a builtin (and heavily used) Matlab function; use something else for your data array of crossing points to avoid high confusion/unintended behavior.
채택된 답변
Daniel kiracofe
2014년 8월 13일
편집: Daniel kiracofe
2014년 8월 13일
the short answer is that you cannot just multiply f by t to get what you want. You need to integrate f with respect to time to get theta. i.e. instead of sin(2 * pi * f * t) you want sin(2 * pi * cumtrapz(t, f)).
this short tutorial I wrote goes into more detail: http://mechanicalvibration.com/Generating_signal_from_freq.html
댓글 수: 2
Daniel kiracofe
2014년 8월 14일
I think the easiest way is to just use interp1(). i.e.
Wtnew = interp1( time_Zeros, W, t); Sine = sin(Wtnew);
in this way, Sine will have a sample at every value of the vector t (which could have any sampling rate you want, even a non-constant one). you could also use cubic spline if linear interpolation is not good enough.
note the mod(Wt, 2*pi) is not necessary. it doesn't hurt, but it also is not doing anything for you.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!