Generate a sinus signal and plot the output

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

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

Hey, thanks for your answer!
How do I create a time axis with 8192 samples on the function as well? This accounts for 0-20. But it might not be possible with creating weird cluster or am I wrong?
If you want one full cycle of the lower frequency sine wave with 8192 samples instead of the fixed dt of 0.01 seconds, change the definition of t to this:
tmin = 0;
tmax = 20*pi;
t = linspace(tmin, tmax, 8192);
This will look very similar since the step for this definition of t is
mean(diff(t))
ans = 0.0077
which is pretty close to 0.01.
Thank you so much! I really appreciate!
I just noticed that your problem statement (quoted below) doesn't match with your code. Check your definition of T1, T2, and tmax to make sure they are consistent with the problem statement. I think you are multiplying by two pi twice. I believe your f1 and f2 are really omega1 and omega2.
Generate a signal 𝑓(𝑡) = sin (𝜔1𝑡) + sin (𝜔2𝑡), 𝜔1 = 0.1 rad/s and 𝜔2 = 10 rad/s
Yes, those are infact omega 1 and 2. But I already knew it because on my document where we recieved the question it says . I copy pasted the question so that's why it says w1 and w2.
Thanks for your concern tho!
You are quite welcome.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Asked:

on 29 Sep 2022

Commented:

on 29 Sep 2022

Community Treasure Hunt

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

Start Hunting!