How can I generate sinusoidal signal with a time-varying frequency?

조회 수: 25 (최근 30일)
인성 이
인성 이 2022년 8월 16일
편집: 인성 이 2022년 8월 16일
Hi. I want to generate time-varying frequency signal.
I have frequency data per every time sample.
For example, for a 1 second time duration signal with a sampling frequency of 100 Hz, I have 100 frequency values.
The picture above is showing the frequency data per time sample that I actually have. It is a signal of 0.85 seconds sampled at 100 kHz.
I want to get a spectrogram by making sound data from this value, but something goes wrong.
Down below is the code I made and the result. I'm not sure where I went wrong in the code.
clc;clear all;close all;
fs = 100e3; % 100kHz sampling frequency
ts = 1/fs;
Time = ts:ts:84986*ts; % 0.84986 sec
load('Freq.mat'); % 84.986 frequency value
Signal = cos(2*pi*Freq.*Time) + 1j*sin(2*pi*Freq.*Time); % generating signal
[s,ff,ttt] = spectrogram(y,1024,800,1024,fs);
s = abs(s);
%% ploting spectrogram of Signal
X = figure;
axes1 = axes('Parent',X);
imagesc(ttt,ff,s);
set(axes1,'YDir','normal');
axis([ttt(1) ttt(end) 4e3 17e3]);xlabel('sec');ylabel('Hz');
The above spectrogram figure is the result of the generated spectrogram. As you can see, the signal was generated a lot different from the frequency data I had.
Please help. Thanks.

채택된 답변

Chunru
Chunru 2022년 8월 16일
편집: Chunru 2022년 8월 16일
fs = 100e3; % 100kHz sampling frequency
ts = 1/fs;
Time = ts:ts:84986*ts; % 0.84986 sec
load('Freq.mat'); % 84.986 frequency value
figure;
plot(Time, Freq);
You need to integrate the instantaneous fre quency over time:
where is the time-varying phase and is the instantaneous frequency. The signal can be then expressed as:
phase = 2*pi*cumsum(Freq)/fs;
% Signal = cos(2*pi*Freq.*Time) + 1j*sin(2*pi*Freq.*Time); % generating signal
Signal = exp(1j*phase);
[s,ff,ttt] = spectrogram(Signal,1024,800,1024,fs);
s = abs(s);
%% ploting spectrogram of Signal
X = figure;
axes1 = axes('Parent',X);
imagesc(ttt,ff,s);
set(axes1,'YDir','normal');
axis([ttt(1) ttt(end) 4e3 17e3]);xlabel('sec');ylabel('Hz');
  댓글 수: 1
인성 이
인성 이 2022년 8월 16일
편집: 인성 이 2022년 8월 16일
Thank you so much for your kind reply. It really helped me a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by