Square function with variable frequency
显示 更早的评论
Hello,
The purpose is to determine the # of cycles of a shaft starts to rotate. I must write a code that create square function with variable frequency between 1 & 1000HZ. I wrote it, and I calculated the # of cycles using peaks by determining periods.
t = 0.001:0.001:1; % Sampling frequency 0.001 HZ
y = square(2*pi*(15*exp(0.4*t)-4).*t);% The square wave works just like
%sin(t) and cos(t) except that it takes value +1 and -1.
% w=2*pi*f(t), Suppose f(t)= 15*exp(0.4*t)-4
[idx,idx]=findpeaks(y);
size(findpeaks(y));
t(idx(1));
for i=1:1:16
[T]=[t(idx(1+i))-t(idx(i))];
end
plot(t,y);
axis([0.001 1 -1.5 1.5]);
xlabel('Seconds');
ylabel('Amplitude');
grid on;
set( findobj(gca,'type','line'), 'LineWidth', 2);
title('Period determination')
set(gca,'xtick',[0.001:0.1:1])
axis([0.001 1 -1.1 1.1])
set(gca,'ytick',[-1.1:0.1:1.1])
But I want to find the number of cycles by using fft(x) (Fourier). I have no idea how to use fft with variable frequency function! How?
Are there any other method to solve that?
Thanks in Advance, Jeff

2 个评论
Walter Roberson
2015-5-27
You currently have
t = 0.001:0.001:1; % Sampling frequency 0.001 HZ
That is not a sampling frequency of 0.001 HZ, that is a sampling frequency of 1000 Hz.
If you want to be able to create a square wave of 1000 Hz, you need a sampling frequency of at least four times that, 4000 Hz, 0.00025 seconds, as it is necessary to have at least the first harmonic to the sine wave in order to distinguish it from the sine wave.
Jefff makalayli
2015-5-27
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!