Sine Wave Becoming Increasingly Choppy
14 views (last 30 days)
Show older comments
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 Comment
Image Analyst
on 27 Aug 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.
Accepted Answer
Mathieu NOE
on 28 Aug 2023
Edited: Mathieu NOE
on 28 Aug 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 Comments
Mathieu NOE
on 29 Aug 2023
as always , my pleasure !
if you need to learn more about signals and signal processing , this is something for you :
More Answers (0)
See Also
Categories
Find more on Time-Frequency Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!