Matlab code for sine wave with varying frequency
38 ビュー (過去 30 日間)
古いコメントを表示
How do I generate a sine wave with varying frequency and constant amplitude? I've tried the following code, but it is showing harmonics. How do i eliminate the harmoics?
clc;
fs = 2000; %sampling frequency
dt = 1/fs; %seconds per sample
StopTime = 10; %seconds
t = (0:dt:StopTime);
F = 50.*t; %Sinewave frequency {Hertz)
amp = 1000;
for i= 1:length(t);
data(i) = amp*sin(2*pi*F(i)*t(i));
end;
audiowrite('varFsin.wav', data, fs);
sound(data);
figure(1)
clf(1);
plot(t, data)
title('Sine Wave');
figure(2)
spectrogram(data, [80], [40], [256], fs, 'yaxis')
y = fft{data};
n = length(data); %number of samples
f = (0:n-1)*(fs/n); %frequency range
power = abs(y).^2/n; %power of the DFT
figure(3);
plot(f, power)
xlbel('frequency')
ylabel('power')
0 件のコメント
採用された回答
Chunru
2021 年 9 月 1 日
clc;
fs = 2000; %sampling frequency
dt = 1/fs; %seconds per sample
StopTime = 10; %seconds
t = (0:dt:StopTime);
F = 50.*t; %Sinewave frequency {Hertz)
amp = 1000;
The following is equivalent to LFM (linear frequency modulation) signal.
for i= 1:length(t);
data(i) = amp*sin(2*pi*F(i)*t(i));
end;
%audiowrite('varFsin.wav', data, fs);
sound(data);
figure(1)
clf(1);
plot(t, data)
title('Sine Wave');
figure(2)
spectrogram(data, [80], [40], [256], fs, 'yaxis')
y = fft(data);
n = length(data); %number of samples
f = (0:n-1)*(fs/n); %frequency range
power = abs(y).^2/n; %power of the DFT
figure(3);
powershift = fftshift(power);
fshift = (-n/2:n/2-1)*(fs/n); % zero-centered frequency range
plot(fshift,powershift)
xlabel('frequency')
ylabel('power')
This is not really harmonic. The spectrum has transition region around 0 and +/-fs/2. You have no harmonics to remove.
その他の回答 (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!