Equation for Matlab Code

4 ビュー (過去 30 日間)
David Kendal
David Kendal 2022 年 5 月 25 日
コメント済み: William Rose 2022 年 5 月 26 日
I have coded a swept sine signal using a for loop, I am aware that the equation would require a sigma for this.
in terms of x(t)=...
Could anyone help with placing this code into a mathmatical equation?
Many thanks
T=5; %size of window
fs=44100; %sampling frequency
df=1/T; %frequency res
dt=1/fs; %time resolution
t=(0:+dt:T-dt); %time vector
df_t=500; %swept rate (Hz/seconds)
% pre-allocate size of t:
sweptsin = zeros(size(t));
for i=1:+1:length(t)
%i=i+1;
if(i==1) %initialise f and t.
f=20; ti=0;
else
ti=ti+dt; %time increment
f=f+df_t*dt; %freq increment
end
w=2*pi*f; %omega
sweptsin(i)=sin(w*ti); %swept sine wave
end
  4 件のコメント
David Kendal
David Kendal 2022 年 5 月 26 日
And obviously a function of sin
David Kendal
David Kendal 2022 年 5 月 26 日
https://hal.archives-ouvertes.fr/hal-02504321/document See this link. Cheers

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

採用された回答

William Rose
William Rose 2022 年 5 月 26 日
Suppose you want a signal that starts at 20 Hz and goes up to 10000 Hz at a rate of 500 Hz/sec, and you want a sampling rate of 44.1 kHz:
% Define constants
fs=44100;
f1=20; f2=10000;
dfdt=500;
%Compute other constants
dt=1/fs;
T=(f2-f1)/dfdt;
%Create signal
t=0:dt:T;
x=sin(2*pi*(f1+dfdt*t/2).*t);
%Display results
subplot(311), plot(t,x,'-r'); title('Entire signal');
subplot(312), plot(t,x,'-r'); xlim([0,1/f1]); title('Start');
subplot(313), plot(t,x,'-r.'); xlim([T-1/f2,T]); title('End'); xlabel('Time (s)');
Try it. Good luck.
  3 件のコメント
David Kendal
David Kendal 2022 年 5 月 26 日
Thank you for this!
William Rose
William Rose 2022 年 5 月 26 日
@David Kendal, you're wecome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by