Plotting sinewave looks weird.

20 visualizaciones (últimos 30 días)
Dexter James Barit
Dexter James Barit el 17 de Oct. de 2020
Comentada: Image Analyst el 9 de Nov. de 2022
I'm trying to plot a sinewave with a length of 1000 samples, with a sample rate of 40kHz and center frequency at 19kHz. For some reason when I plot the sinewave it looks weird. Am I plotting this correctly?
fs=40000;
freq=19000;
w=freq/fs;
n=0:999;
x1 = sin(2*pi*w*n);
plot(x1)

Respuestas (1)

Image Analyst
Image Analyst el 18 de Oct. de 2020
This is what I get
% Plot a sinewave with a length of 1000 samples, with a sample rate of 40kHz and center frequency at 19kHz.
dt = 1/40000 % Samples are separated by 1/40000 of a second.
% 19 kHz means the period is 1/19000 of a second.
period = 1/19000
% Use 1000 samples
t = dt * (1 : 1000);
y = sin(2 * pi * t / period);
plot(t, y, 'b-');
grid on;
xlabel('time', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
  4 comentarios
Suhas
Suhas el 9 de Nov. de 2022
if sampling frequency is twice the highest frequency in signal i.e if sampling frequency > 19*2 = 38kHz , shouldn't that be enough according to nyquist theorom?
Image Analyst
Image Analyst el 9 de Nov. de 2022
If you sample more than twice per period you can still have the appearance of aliasing. Look below where I plot just over the first dozen period, and look at the blue spots where the samples are taken from. If you plotted just the blue dots with lines between them it would look unlike the original signal.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 30;
% Plot a sinewave with a length of 1000 samples, with a sample rate of 40kHz and center frequency at 19kHz.
dt = 1/40000 % Samples are separated by 1/40000 of a second.
% 19 kHz means the period is 1/19000 of a second.
period = 1/19000
% Plot 12 periods of the full, unsampled waveform.
t = linspace(0, 12 * period, 2000);
y = sin(2 * pi * t / period);
plot(t, y, 'r-', 'LineWidth', 2);
grid on;
% Use samples spaced at dt up through the 12th period.
tMax = max(t);
t = 0 : dt : tMax;
y = sin(2 * pi * t / period);
hold on;
plot(t, y, 'b.', 'MarkerSize', markerSize);
grid on;
xlabel('time', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
legend('Full Unsampled Waveform', 'Sample Locations')
fontsize(gca, 15, 'points');
See, in each period there is about 3 samples.

Iniciar sesión para comentar.

Categorías

Más información sobre Test and Measurement en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by