I am new to matlab and I am struggling with the basics. I was asked this question in class and I'm just not sure what to do "Plot one second of a sine wave with frequency 97 Hz and phase shift 97 (in degrees). The x-axis should be time not samples". Please help.

 採用された回答

sixwwwwww
sixwwwwww 2013 年 10 月 22 日
編集済み: sixwwwwww 2013 年 10 月 22 日

1 投票

Dear Niamh, you can do the following way:
time = -1:0.01:1;
frequency = 97;
phase = 97;
phase_in_rad = degtorad(phase);
y = sin(2 * pi * frequency * time + phase_in_rad);
plot(time, y), xlabel('Time'), ylabel('Sine wave')
Do you need it or something else?

2 件のコメント

Image Analyst
Image Analyst 2013 年 10 月 22 日
編集済み: Image Analyst 2013 年 10 月 22 日
What you've actually inadvertently given is a good example of aliasing but you probably didn't even notice. However I don't think this is what the poster wanted. Do you know what aliasing is? How many periods to you see in 1 second? 97, or 3? Voila! Aliasing! With a step size of 0.01, how many samples will you get in 1/97 of a second? Only one! One sample per period, actually a little bit less so that's why you see only 3 periods instead of 97. Now, how many samples do you require to avoid aliasing? Check out http://en.wikipedia.org/wiki/Nyquist_frequency
Image Analyst
Image Analyst 2013 年 10 月 22 日
編集済み: Image Analyst 2013 年 10 月 22 日
Niamh, I knew this would happen. I think you accepted the wrong answer. Did you not notice that not all of the cycles were displayed in this answer? Only 3 instead of 97 like you'd expect to see in a one second time period. From what this Answer displays you'd think the frequency was 3 hertz, not 97 hertz! Did you run only this Answer and totally ignore mine? Did you not understand my explanation of aliasing and Nyquist frequency ? It would be wise of you to study up on that so you understand these very very important concepts.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 22 日
編集済み: Image Analyst 2013 年 10 月 22 日

3 投票

Hopefully this was just a question asked verbally in class and not an actual homework assignment. Wouldn't it just be something like this:
% Make 1000 samples in the range 0 to 1 second.
t = linspace(0, 1, 1000);
% Assign period and phase shift of 97 degrees.
period = 1/97; % 97 hertz = period of 1/97 of a second.
phaseShift = 97 * pi/180; % In radians.
y = sin(2*pi*t/period - phaseShift));
plot(t,y, 'bo-', 'LineWidth', 2);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Of course with 97 periods across the screen of width 1920 pixels, you won't see much - it will be all smashed together horizontally. You might want to plot fewer periods.

カテゴリ

ヘルプ センター および File Exchange で Graphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by