sine waveform with frequency and samples

조회 수: 58 (최근 30일)
Amir Hussain
Amir Hussain 2022년 3월 29일
댓글: Amir Hussain 2022년 3월 29일
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;

채택된 답변

Mathieu NOE
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;
  댓글 수: 2
Amir Hussain
Amir Hussain 2022년 3월 29일
class
Amir Hussain
Amir Hussain 2022년 3월 29일
that got really messy

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
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

카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by