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!