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







采纳的回答
Star Strider
2021-9-18
编辑:Star Strider
2021-9-18
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 个评论
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;
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







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.
.
What do you mean my "visualized correctly"?
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.
@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.
.
@Paul Yes, as Star Strider pointed out, I was expecting to see a perfect cosine form, so that is why I used "visualized correctly".
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.
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.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Frequency Transformations 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
