sine waveform with frequency and samples
291 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Amir Hussain
le 29 Mar 2022
Commenté : Amir Hussain
le 29 Mar 2022
Generate 5 seconds of a sinusoidal waveform that has a frequency of 100 Hz and has 15 samples per cycle. Label axes appropiately
ive got here
%%Time specifications:
Fs = ; % samples per second
dt = 1/Fs; % seconds per sample
% Plot the signal versus time:
figure;
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
0 commentaires
Réponse acceptée
Mathieu NOE
le 29 Mar 2022
%%Time specifications:
f = 100; % signal frequency
sps = 15; % samples per signal period
Fs = sps*f; % samples per second
dt = 1/Fs; % seconds per sample (time increment)
t = (0:dt:5); % 5 seconds of data (time)
x = sin(2*pi*f*t); % 5 seconds of data (sinus)
% Plot the signal versus time:
figure;
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
2 commentaires
Plus de réponses (1)
Voss
le 29 Mar 2022
Here's how you can do that. This plot is zoomed in, so you can see it
% frequency = 100 Hz = 100 cycles/second
% sampling rate: 15 samples/cycle
%
% 15 samples/cycle * 100 cycles/second = 1500 samples/second
f = 100; % 100 Hz signal
Fs = f*15; % samples per second
dt = 1/Fs; % seconds per sample
% duration of signal: 5 seconds
% 5 seconds * 1500 samples/second = 7500 samples
T = 5; % 5 second total duration
N = T*Fs; % 5*1500 = 7500 samples
% time goes from 0 to 5 seconds, with N+1 = 1501 samples
% (+1 because linspace includes the end points)
t = linspace(0,T,N+1);
% another way to generate t:
% t = (0:N)*dt; % the same as above
% calculate x at those times:
x = sin(2*pi*f*t);
% Plot the signal versus time:
figure;
% plot(t,x);
plot(t,x,'.-'); % use '.' marker to see (and be able to count) the samples, for checking that it's correct
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
xlim([0 0.1]) % set the xlim to show 0.1 seconds -> should be 10 cycles, again just for verification
0 commentaires
Voir également
Catégories
En savoir plus sur Discrete Fourier and Cosine Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!