In MATLAB create a sine wave with slow varying frequency. The average freqeuncy is 20hz. The slow frequency is 1Hz. The [f min, fmax] = [15, 25]Hz. Plot the waveform, power spectrum, and spectrogram.
MATLAB code is given below followed by the plots.
The code is in bold letters.
clc;
close all;
clear all;
% Sqweep from 15 Hz to 25 Hz
Fs = 1000;
Ts = 1/Fs;
t = 0:Ts:2;
x = chirp(t,15,2,25);
figure;plot(t,x);xlabel('Time(s)');ylabel('Amplitude');
xlim([-0.1 2.1]);ylim([-1.1 1.1]);grid;
title('sweep of frequencies 15 Hz to 25 Hz');
% Spectrum
X = fft(x);
L = length(X);
P2 = abs(X/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure;
plot(f,P1);grid;
title('Single-Sided Amplitude Spectrum Chirp')
xlabel('f (Hz)');xlim([0 50]);
ylabel('Magnitude')
% Spectrogram
F = 0:.1:100;
[y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis');
figure;surf(t,f,10*log10(abs(p)),'EdgeColor','none');
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time');title('Spectrogram');
ylabel('Frequency (Hz)');
Get Answers For Free
Most questions answered within 1 hours.