Sampling frequency and correct signal plotting

Hi, I have been trying to understand effects of the sampling frequency to the time axis plots and it got me curious that why we have "corrupted" data points in the plotted figures although we have Fs > 2* (signal frequency). FFT results and plots are expected, but I could not understand the "corruption" in the time domain plots ( or the visual effect - it is not like a cosine anymore). Is there any mathematical reasons that 1kHz or 2kHz samping frequencies are not enough to visualize a cosine signal with 350 Hz. Here is my simple testing code:
L = 800;
Fs = [1e3 1.5e3 2e3 4e3 8e3 16e3 24e3];
for index=1:length(Fs)
Ts = 1/Fs(index);
x = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*x);
figure
plot(x(300:450),y(300:450))
title("Fs = " + string(Fs(index)))
end

 Respuesta aceptada

Star Strider
Star Strider el 18 de Sept. de 2021
Editada: Star Strider el 18 de Sept. de 2021
I believe this is simply an interaction of the sampling frequency and the signal frequency, typically referred to as ‘aliasing’.
I did the Fourier transforms to see if I could detect any irregularity, and the only finding was that the frequencies do not appear to be what they are intnded to be.
L = 800;
Fs = [1e3 1.5e3 2e3 4e3 8e3 16e3 24e3];
for index=1:length(Fs)
Ts = 1/Fs(index);
x = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*x);
figure
plot(x(300:450),y(300:450))
title("Fs = " + string(Fs(index)))
xc{index} = x;
yc{index} = y;
end
for index=1:length(Fs)
Fn = Fs(index)/2;
N = 2^nextpow2(numel(yc{index}));
FTy = fft(yc{index},N)/numel(yc{index});
Fv = linspace(0, 1, fix(N/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTy(Iv))*2)
title("Fs = " + string(Fs(index)))
end
EDIT — (18 Sep 2021 at 17:44)
Changed:
FTy = fft(yc{index})/N;
to:
FTy = fft(yc{index},N)/numel(yc{index});
.

10 comentarios

One line should be modified and then the FFTs yield the expected results:
FTy = fft(yc{index},N)/N; % was FTy = fft(yc{index})/N;
Star Strider
Star Strider el 18 de Sept. de 2021
Noted!
Actually, the amplitudes should be normalised by the number of elements in the original signal vector to approximate the correct amplitude, and ‘N’ should be an argument to the fft call. (I missed that early this morning!)
.
Hello, firstly thank you for your answers, after running your scripts I saw that fourier transform results are expected and we see harmonics ( due to multiplication of original cosine signal with a rectangular pulse), I guess, due to finite computation of cosine signal with fft. Hence, can we say that effect of harmonics is higher when we have lower sampling frequency? If it is, is there any rule of thumb to prevent this so that data can be visualized correctly?
Thank you all kindly.
L = 2000;
Fs = [1e3 1.5e3 2e3 4e3 8e3 16e3 24e3];
f = 350;
for index=1:length(Fs)
Ts = 1/Fs(index);
x = (0:L-1)*Ts;
y = .5*cos(2*pi*f*x);
xc{index} = x;
yc{index} = y;
end
for index=1:length(Fs)
Fn = Fs(index)/2;
N = 2^nextpow2(numel(yc{index}));
FTy = fft(yc{index},N)/numel(yc{index});
Fv = linspace(0, 1, fix(N/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTy(Iv))*2)
title("Fs = " + string(Fs(index)))
end
Star Strider
Star Strider el 19 de Sept. de 2021
My pleasure!
That is simply the nature of sampling theory, and there are books written on it (as well as extended discussions in digital signal processing texts), so I won’t go into that here. It is an important topic, and I encourage you to explore it on your own. As for visualising it corrctly, the problems can be mitigated through the use of an anti-aliasing filter, that is a lowpass filter with the passband frequency of slightly less than half the sampling frequency. In hardware, this is done with a Bessel analog filter at the input of the ADC. In software, it can be done with any suitable filter (IIR filters tend to be more efficient), and using the filtfilt function to apply the filter to the signal.
.
Paul
Paul el 19 de Sept. de 2021
What do you mean my "visualized correctly"?
Berkay Yaldiz
Berkay Yaldiz el 19 de Sept. de 2021
Hi, yes at first glance I thought it was like an "aliasing" problem; nonetheless, sampling frequency is higher than the required minimum frequency, at least theoritically. (If f = 350 Hz, Fs > 700 Hz. Please correct me if I am wrong. For example, for Fs = 1kHz, we have -0.7*pi and 0.7*pi rad/s frequencies between -pi and pi interval, so there should be no aliasing.). I just want to be sure about this concept because like you said, it is an important one. Hence, I started to think this aliasing is caused due to practical implementation of signal processing on a software. Thank you.
Star Strider
Star Strider el 19 de Sept. de 2021
@Berkay Yaldiz — As always, my pleasure!
I agree with you with respect to the problem being due to the sampling pulse. Pulses in general in the time domain become sinc functions in the frequency domain. Those frequencies are convolved with and so become part of the sampled signal.
@Paul — I was responding to this Comment that uses that phrase. I assume that it implies a relatively undistorted depiction of the waveform.
.
Berkay Yaldiz
Berkay Yaldiz el 19 de Sept. de 2021
@Paul Yes, as Star Strider pointed out, I was expecting to see a perfect cosine form, so that is why I used "visualized correctly".
Paul
Paul el 19 de Sept. de 2021
Editada: Paul el 19 de Sept. de 2021
That comment seemed to be talking about visualization in the frequency domain, because it referenced Fourier transform results and harmonics.
But it sounds like the real concern is how the signal is visualized in the time domain using Matlab's plot() command? If that's the case, the look of the plot is determined by how plot() fills in the space between the sample points that are input to the plot() command. Perhaps I still don't understand exactly what the desired or expected result is.
Berkay Yaldiz
Berkay Yaldiz el 20 de Sept. de 2021
Hi, yes plot command fills the space between sample points, but for "relatively" lower sampling frequencies, although these frequencies are higher than the minimum required frequencies to not have aliasing, we observe more like a noise rather than a cosine waveform and this issue stuck in my mind, that is why I used that term. Hence, we checked Fourier domain to see if anything went wrong.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 18 de Sept. de 2021

Comentada:

el 20 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by