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 Comments

What do you mean would require a sigma? You're making a sine wave with thousands of periods so that you can't see them unless you zoom way in. Not sure what you want. Do you want a longer period so you can see something more like a typical chirp signal?
Like a mathematical balanced equation with x(t) at the beginning
And obviously a function of sin
https://hal.archives-ouvertes.fr/hal-02504321/document See this link. Cheers

Sign in to comment.

 Accepted Answer

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 Comments

@David Kendal, in case you are wondering why I used
(eq.1)
We can write a sine wave with varying frequency as
(eq.2)
where is the phase angle, which is a funciton of time. The instantaneous frequency of a sinusoid, in radians per second, is
(eq.3)
We want a chirp rate (in Hz/sec) of . Since , this is equivalent to , i.e.
(eq.4).
Integrate both sides of eq.4 to get
(eq.5)
where C1 is a constant of integration. The initial condition is f(0)=f1, i.e. . It follows that to satify the initial condition. Therefore eq. 5 becomes
(eq.6)
Now replace the left hand side of eq.3 with the right hand side of eq.6:
, and integrate both sides to get
where C2 is a constant of integration. We assume phi=0 at t=0, therefore C2=0. Therefore we have
or (eq.7)
Combine eq.2 and eq.7:
(eq.7)
which is the same as eq. 1, when you recall that B=dfdt.
Thank you for this!
@David Kendal, you're wecome.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!