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)
