Plot a sine wave with decreasing frequency over time

32 ビュー (過去 30 日間)
Alison Huffman
Alison Huffman 2021 年 8 月 4 日
コメント済み: Eike Blechschmidt 2021 年 8 月 9 日
Hi! I'm trying to plot a sine wave whose frequency decreases linearly over time (amplitude stays the same). This is my code:
clear all;
close all;
clc
period = 0.08;
for x = 0:4/1000:2
a = 5;
b = ((2*pi)/(period + 0.001));
c = 300;
d = 30;
c = c * -1;
output = a.*sin(b.*(x+c))+d;
plot(x, output, 'Linewidth', 2);
end
When I run the code, my plot is blank. I know Matlab doesn't require the use of a "for" loop when plotting sinusoids, however I'm unsure of how else I can modify the frequency over time if I don't use a "for" loop. Any help is much appreciated!

回答 (3 件)

Eike Blechschmidt
Eike Blechschmidt 2021 年 8 月 4 日
How about
f_upper = 50;
f_lower = 10;
t = 0:0.01:10;
f = linspace(f_upper, f_lower, numel(t));
a = 10;
x = a * sin(2*pi*f.*t);
plot(t,x)
  1 件のコメント
darova
darova 2021 年 8 月 4 日
DOesn't work well
f_upper = 5;
f_lower = 1;
t = 0:0.01:10;
f = linspace(f_upper, f_lower, numel(t));
a = 10;
x = a * sin(2*pi*f.*t);
plot(t,x)

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


darova
darova 2021 年 8 月 4 日
Modify x coordinate
x = 0:.1:30;
y = sin(x);
x1 = x - 10*(x/max(x)).^2; % shift last point 10 units
plot(x1,y)
  5 件のコメント
darova
darova 2021 年 8 月 8 日
Because requency changes i think
Eike Blechschmidt
Eike Blechschmidt 2021 年 8 月 9 日
@darova changed the x-axis after calculating the sin. So I'm unsure (as in "I have not mathematically checked") if that solution is still expressable with a single sin function (you can always find multiple sin-waves to express any kind of time signal -> fourier transformation) which was my understanding of "is it still a sin function". My first solution does that as I only manipulate the input to the sin function. So I guess my question was not precise.

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


Eike Blechschmidt
Eike Blechschmidt 2021 年 8 月 5 日
The easiest and correct is probably to use:
f1 = 50;
f2 = 10;
t = 0:0.001:10;
y = chirp(t,f1,t(end),f2);
plot(t, y);
  3 件のコメント
Alison Huffman
Alison Huffman 2021 年 8 月 5 日
編集済み: Alison Huffman 2021 年 8 月 5 日
@Eike Blechschmidt Thank you very much, this is helpful. What calculation does the chirp function do? Is it just modifying the period of the sine wave?
Eike Blechschmidt
Eike Blechschmidt 2021 年 8 月 6 日
You can also do
edit chirp
and scroll downt to
function yvalue = calculateChirp(f0,f1,t1,p,t,phi,isComplex)
It shows quite clear how the chirp is calculated.

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by