Not sure of how I can sample this Nyquist wave? Combining data problems
Show older comments
I was given a task of creating a continuous time signal consisting of two different sine waves added together, with this new wave then being sampled after its creation. I managed to complete the first part with ease by making two different sets of data and combining them to make a new sine. Though there came an issue with it, as I could not properl use the stem function to discretely "sample" the data.
This is what I got for my initial output:
As you can see, while the wave did end up fine in the end, discrete data was all over the place as you can see with the blue lines not fitting at all into the wave.
This is what I was supposed to get for my output:
Over in this image, you can see that the lines fit; the data is being correctly sampled discretely.
This is the code I used to get my intial output
%Time Base
t = 0:0.001:1.8;
%Nyquist Frequencies
Fn1 = 1;
Fn2 = 6;
%Nyquist Rates
Fnr1 = 2*(Fn1);
Fnr2 = 2*(Fn2);
%Sampling Period
Sp1 = 5*(Fnr1);
Sp2 = 5*(Fnr2);
Ts1 = 1/(Sp1);
Ts2 = 1/(Sp2);
T1 = 1/(Fn1);
T2 = 1/(Fn2);
%Number of Samples
N1 = (T1/Ts1);
n1 = 0:1:N1;
N2 = (T2/Ts2);
n2 = 0:1:N2;
nTs1 = n1 * Ts1;
nTs2 = n2 * Ts2;
x_c = sin(2*pi*Fn1*nTs1);
x_c1 = sin(2*pi*Fn1*t);
x_c2 = sin(2*pi*Fn2*nTs2);
x_2 = sin(2*pi*Fn2*t);
signal = x_c1 + x_2;
ct = nTs1 + nTs2;
nqsignal = x_c + x_c2;
%Second Part
h = stem(ct, nqsignal, 'linewidth', 2);
hold
plot(t, signal, 'linewidth', 2)
lgd = legend('Discrete Data', 'Continuous Data');
set (lgd, "fontsize", 12)
set(gca,'XTick',[0:0.2:1.8]);
set(gca,'YTick',[-2:0.5:2]);
title('Time vs Magnitude','fontweight','bold','fontsize',16);
xlabel('Time(s)','fontweight','bold','fontsize',14)
ylabel('Magnitude','fontweight','bold','fontsize',14)
grid
2 Comments
Mathieu NOE
on 26 Oct 2020
hello
if I understand well from the attached picture, you just need to plot the original continous sine wave and it's sampled version
your first explanation is a bit confusing, I was thinking you have 2 different signals and you need to make a combination of the two... it's not what I guess from the pictures.
Joel Okanta
on 28 Oct 2020
Accepted Answer
More Answers (1)
Joel Okanta
on 22 Jan 2021
0 votes
Categories
Find more on Signal Operations 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!