MATLAB: Sinusoidal signal with variable instantaneous frequency

digital signal processingimage processingmathematicssignal processingstatistics

Below is a simple matlab code that generates a sinusoidal signal with user specified no of cycles. How do i change this such that each cycle has different instantaneous frequency? For example, if i have 10 cycles, then there should be 10 random frequencies in total where each cycle has different frequency.
clc
clear
f1=120;
fs=f1/60; %sampling frequency depends on f1
no_of_cycles=10;
f=no_of_cycles/60; %Frequency of sinusoid
duration=1;%%duration of the sinusoidal signal in minutes
A=1;
t=1/fs:1/fs:duration*no_of_cycles*1/f; %time index
y1=A*sin(2*pi*f*t);%%simulated sinusoidal signal

Best Answer

Hi Sowmia MR
1.
One way to answer your question is, without losing constant amplitude, which is a good quality of FM:
f1_range=120*[1:1/3:4]
f1=f1_range(randi([1 9],1,9))
A=1;
y1=0
for k=1:1:numel(f1)
y1c=A*sin(2*pi/f1(k)*[1:1:f1(k)]);
y1=[y1 y1c];
end
plot(y1)
.
2.
Another way would be constraining the amount of samples for each frequency to a constant value, that would be of 1 cycle of f0=120Hz
f0=120
f1_range=f0*[.7:.1:1.3]
f1=f1_range(randi([1 numel(f1_range)],1,numel(f1_range)))
A=1;
y1=0
for k=1:1:numel(f1)
y1c=A*sin(2*pi*f1(k)/f0*[0:1/f0:1]);
y1=[y1 y1c];
end
plot(y1)
.
3.
Note that now it's not 10 cycles but 7, 7*120 are the 840 samples shown above 2nd graph.
Recommended reading 'Telecommunication Systems' by Bruce Carlson
4.
Please not that f1_range is on purpose chosen 'not too wide'.
If so alias occurs, data loss, the output signal and plot may be meaningless.
5.
If you want to learn more about FM basics with MATLAB, please check my accepted answer to question in this link:
there's an explanation how to FM modulate a signal, with MATLAB and with SIMULINK
So, Sowmia MR
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG