This code demonstrates how to plot the time-frequency distribution of a chirped signal in MATLAB using the 'spectrogram' function.

%% Generate a chirped signal
fs = 1000; % Sampling frequency
t = 0:1/fs:2; % Time vector
f0 = 100; % Starting frequency
f1 = 500; % Ending frequency
x = chirp(t, f0, 2, f1);

%% Compute the spectrogram
win = hamming(256); % Window function
overlap = 128; % Overlap between windows
nfft = 512; % FFT size
[S, F, T] = spectrogram(x, win, noverlap, nfft, fs);

%% Plot the spectrogram
figure;
imagesc(T, F, abs(S));
axis xy; % Flip the y-axis
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Time-frequency distribution of a chirped signal');
colorbar;

The code first generates a chirped signal with a starting frequency of 100 Hz and an ending frequency of 500 Hz. It then calculates the spectrogram using a Hamming window, an overlap of 128 samples, and an FFT size of 512. Finally, it displays the spectrogram with time on the x-axis, frequency on the y-axis, and color representing the magnitude. This visualization clearly shows the linear frequency shift from low to high frequencies over time, characteristic of a chirped signal.

MATLAB Spectrogram: Visualizing Time-Frequency Distribution of Chirped Signals

原文地址: https://www.cveoy.top/t/topic/nk0C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录