Generate Frequency Spectrum
Version 1.0.0 (1.15 KB) by
Safwan Mahmoud
Can be used to generate a complex frequency spectrum from the amplitude and phase(angle) arrays.
Let's generated an amplitude and phase array of a 60Hz using a gaussian function
f = 0:1/10:100; % Time vector
f0 = 15; % Base frequency
f1 = 30; % Peak frequency
sigma = 1; % Standard deviation of the Gaussian
mag = f0 + (f1 - f0) * exp(-((f - 60).^2) / (2 * sigma^2));
angleArray = f;
subplot(211)
plot(f,mag)
xlabel('Frequency (Hz)');
ylabel('Amp');
title('Magnitude');
grid on;
subplot(212)
plot(f,angleArray)
xlabel('Frequency (Hz)');
ylabel('Angle');
title('Phase');
grid on;
Now Let's apply the Generate spectrum function
spec = genSpectrum(mag, angleArray);
clf
subplot(211)
plot(f,abs(spec))
xlabel('Frequency (Hz)');
ylabel('Amp');
title('Magnitude');
grid on;
subplot(212)
plot(f,angle(spec))
xlabel('Frequency (Hz)');
ylabel('Angle');
title('Phase');
grid on;
Note: the angle will look different without unwrapping it first.
Cite As
Safwan Mahmoud (2026). Generate Frequency Spectrum (https://www.mathworks.com/matlabcentral/fileexchange/169707-generate-frequency-spectrum), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2023b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
