Borrar filtros
Borrar filtros

sine waveform with frequency and samples

291 visualizaciones (últimos 30 días)
Amir Hussain
Amir Hussain el 29 de Mzo. de 2022
Comentada: Amir Hussain el 29 de Mzo. de 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;

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 29 de Mzo. de 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 comentarios
Amir Hussain
Amir Hussain el 29 de Mzo. de 2022
class
Amir Hussain
Amir Hussain el 29 de Mzo. de 2022
that got really messy

Iniciar sesión para comentar.

Más respuestas (1)

Voss
Voss el 29 de Mzo. de 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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by