sine waveform with frequency and samples
287 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amir Hussain
am 29 Mär. 2022
Kommentiert: Amir Hussain
am 29 Mär. 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 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 29 Mär. 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 Kommentare
Weitere Antworten (1)
Voss
am 29 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!