Generate a sinus signal and plot the output
30 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposta accettata
Les Beckham
il 29 Set 2022
Modificato: Les Beckham
il 29 Set 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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!