sine waveform with frequency and samples
352 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mathieu NOE
2022-3-29
%%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;
更多回答(1 个)
Voss
2022-3-29
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!