Generate a sinus signal and plot the output

17 views (last 30 days)
Hello, I'm stuck on a problem that I don't really know how to solve. I'm suppose to do these tasks:
Generate a signal 饾憮(饾憽) = sin (饾湐1饾憽) + sin (饾湐2饾憽), 饾湐1 = 0.1 rad/s and 饾湐2 = 10 rad/s. Use the
sampling frequency Fs = 100 Hz to sample the signal. Create a time axis with 8192 ( = 2^13)
samples. Filter the input signal through the circuit. Plot the input signal and the output signal
in the same diagram. Explain what happened to the input signal based on the Bode
diagram.
When i tried to code this I got an output, however the graph became a giant clump. I immediately checked it and it was wrong. Here's my code:
dt = 1/100;
tmin = 0;
tmax = 2^13;
t = tmin:dt:tmax;
T1 = 20*pi;
f1 = 1/T1;
T2 = 0.2*pi;
f2 = 1/T2;
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
stem(t,x);
This code is exclusive of the filtering and the bodeplot because I want to get the function and time graph right. Does anyone know what I've done wrong?
Thanks!

Accepted Answer

Les Beckham
Les Beckham on 29 Sep 2022
Edited: Les Beckham on 29 Sep 2022
Your tmax is huge so you are plotting many many thousands of cycles. Also, stem clutters up the plot with circles on every datapoint of which you have a lot.
Try this:
dt = 1/100;
tmin = 0;
tmax = 20*pi;
T1 = 20*pi;
f1 = 1/T1;
T2 = 0.2*pi;
f2 = 1/T2;
t = tmin:dt:tmax;
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
plot(t,x)
grid on
This looks a little funny in the browser due to pixel resolution aliasing. If you plot it using your desktop Matlab and make the figure window bigger you will see that this is a clean sum of sinusoids.
figure
plot(t, x)
grid on
xlim([0 20])
  6 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by