Matlab code for sine wave with varying frequency
Afficher commentaires plus anciens
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')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spectral Measurements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


