Sine Wave Becoming Increasingly Choppy

11 visualizaciones (últimos 30 días)
Matthew
Matthew el 27 de Ag. de 2023
Comentada: Mathieu NOE el 29 de Ag. de 2023
Here is the text of my code:
clc
clear
t = 0:100:1000;
x = 3*sin(2*pi*1000*t);
n = 0.1*randn(1,length(x));
y = x+n;
subplot(3,1,1)
plot(t,x)
xlabel('time');
ylabel('Amplitude');
title('Input Signal');
subplot(3,1,2)
plot(t,n)
xlabel('time');
ylabel('Amplitude');
title('Noise Signal');
subplot(3,1,3)
plot(t,y)
xlabel('time');
ylabel('Amplitude');
title('Output Signal');
An image for the visually minded, as well as my problematic graph:
Is anyone able to point me in the right direction why my sine wave is so choppy? I've tried adjusting the t variable parameters dozens of times and for whatever reason the wave changes everytime. At one point it was even a declining saw tooth type wave, despite me never changing the x variable that creates the sine wave.
Apologies if this question is simplistic. I've tried looking up similar questions but no one gives an explanation as to why the t variable or why the frequency of the sine wave is so finicky. I also saw someone recommend changing the solver but I was unable to find where that was on Matlab and after looking that up, it seems to be a functionality of Simulink. All help is appreciated.
  1 comentario
Image Analyst
Image Analyst el 27 de Ag. de 2023
Increasingly choppy as what changes? Noise amplitude? Sampling distance (the middle 100 in your definition of t)? Of course if you sample your curve less frequently than the Nyquist frequency your sine wave will not look like a sine wave.

Iniciar sesión para comentar.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 28 de Ag. de 2023
Editada: Mathieu NOE el 28 de Ag. de 2023
hello
your sampling rate is completely wrong
You want to draw a 1000 Hz sine wave , so as pointed out already by @Image Analyst, your sampling rate must be at least twice the max frequency you want to generate. I would even consider a upsampling factor >= 8 if you want a clean sine wave
here I opted for a sampling rate 10 times faster than your signal (Fs = 10 kHz for a 1 kHz sine wave)
clc
clear
dt = 1e-4; % sampling interval (seconds) (= 1/Fs)
t = 0:dt:1e-2;
x = 3*sin(2*pi*1000*t);
n = 0.1*randn(1,length(x));
y = x+n;
subplot(3,1,1)
plot(t,x)
xlabel('time');
ylabel('Amplitude');
title('Input Signal');
subplot(3,1,2)
plot(t,n)
xlabel('time');
ylabel('Amplitude');
title('Noise Signal');
subplot(3,1,3)
plot(t,y)
xlabel('time');
ylabel('Amplitude');
title('Output Signal');
  2 comentarios
Matthew
Matthew el 28 de Ag. de 2023
Thank you for your help. I was unaware of the nyquist rate, being very new to MATLAB. I figured it was related to the frequency as well as the time parameters I was choosing but was unable to see results as I adjusted the time parameters. Also thank you for the succinct explanation as well as showing me the improved code!
Mathieu NOE
Mathieu NOE el 29 de Ag. de 2023
as always , my pleasure !
if you need to learn more about signals and signal processing , this is something for you :

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by