필터 지우기
필터 지우기

Sine plot at a period T over a 20 second interval

조회 수: 4 (최근 30일)
Ketan Shende
Ketan Shende 2021년 3월 10일
댓글: Walter Roberson 2021년 3월 10일
Write a MATLAB script (m) file that builds an array e(k) which consists of the waveform sin(πt) sampled at a period T over a 20 second interval. Initially choose a sample period that is small compared to the period of the waveform.
My code is as follows.
clear all
clc
T=20;
freq = 1/20;
t=0:0.01:20;
y=sin(t*pi);
figure(1)
plot(t,y)
xticks(0:2:20);
grid on
grid minor

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 10일
T=20;
ok. But you never use T.
freq = 1/20;
Is the 20 a coincidence? But it doesn't matter, as you never use freq. Note by the way that a "freq"uency of 1/20 would mean that one period requires 20 seconds.
t=0:0.01:20;
That is a frequency of 1/0.01 which is 100 Hz.
y=sin(t*pi);
Only if your t is in radians per second instead of samples per second.
If you want 1 Hz thenyou need to complete 1 period in 1 second. 1 period is 2*pi radians. Therefore over 1 second you need to complete 2*pi radians. Your current code completes 1 radian per second instead of 2*pi radians in 1 seconds.
  댓글 수: 13
Ketan Shende
Ketan Shende 2021년 3월 10일
편집: Walter Roberson 2021년 3월 10일
Thanks alot. You are awesome!
Taking this ahead, I want to compute the fft of the original signal where timesamp was t = 0:0.01:20. For the same signal, how do I convert the time axis to frequency axis since fft has to be plotted against frequency and not time.
Here is what I have come up with for plotting FFT vs time.
clear
clc
t=0:0.01:20;
y=sin(t*pi);
f = fft(y);
figure(1)
plot (t,abs(f))
I need to find out what frequencies and what part of the FFT that is useful.
This is the information that I have, 'The first peak of the FFT magnitude should occur at a frequency of 0.5 Hz because that is the frequency of the waveform. What scale factor must you apply to the horizontal axis so that the axis shows the frequency in Hz? As a hint, determine the largest and smallest frequencies that can be represented in the duration of the time array. Apply this scale and reproduce your plot. Notice that the frequency spectrum is symmetric about the center. It turns out that information from the latter half of the curve is redundant. This is an example of what is termed frequency folding or aliasing. If L is the length of the frequency array, exclude all information beyond the middle of the array and plot only the first half with the proper frequency scale on the horizontal axis. Can you predict what frequency corresponds to the middle of the array based on the sample rate and number of samples? Provide a succinct formula for the frequency scaling.' The Figure attached illustrates the results of this for a particular sample rate.
Walter Roberson
Walter Roberson 2021년 3월 10일
See the first example in the documentation for fft()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by