Not sure of how I can sample this Nyquist wave? Combining data problems
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joel Okanta
el 26 de Oct. de 2020
Comentada: Joel Okanta
el 22 de En. de 2021
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 comentarios
Mathieu NOE
el 26 de Oct. de 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.
Respuesta aceptada
Mathieu NOE
el 29 de Oct. de 2020
hi
to be honest with you, I rewrote the entire code, simply because the idea is to have one signal at Fs that will be then decimated to show the sampling .
so here is it - enjoy !
%Time Base
Fs = 1000;
dt = 1/Fs;
t = 0:dt:1.8;
samples = length(t);
%Sine Frequencies
Fn1 = 1;
Fn2 = 6;
signal = sin(2*pi*Fn1*t) + 0.25*sin(2*pi*Fn2*t);
% decimated signal for tem plot
decim = 50; % decimation factor
ind = (1:decim:samples);
t2 = t(ind);
x2 = signal(ind);
%Second Part
h = stem(t2, x2, '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
7 comentarios
Mathieu NOE
el 22 de En. de 2021
hello Joel
the sampling theory (Shannon theorem) states that the highest frequency of you signal must be below the Nyquist frequency but there are no fixed ratio between the two .
There is no need to add the signal frequencies to define the sampling frequency (otherwise a very complex signal like music or speech should be sampled at very high Fs !)
So you are free to choose F Nyq > 9 hz . Let's say 10 so Fs = 20 Hz min.
the multipliers (individual frequencies amplitudes) are completely free - and I don't think that it makes any difference for the purpose of this exercise.
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!