image thumbnail

Spectral Analysis with Matlab Implementation

by

 

11 Jun 2013 (Updated )

Spectral analysis including amplitude and phase spectrum as well as their graphical representation.

example2.m
clear, clc, close all

% signal parameters
fs = 44100;
T = 1;
N = round(T*fs);
t = (0:N-1)/fs;

% signal generation
x1 = sin(2*pi*1000*t);
x2 = sin(2*pi*5000*t);
x = x1 + x2 + 0.1*randn(1, N);

% spectral analysis
[Xamp, ~, freq] = spectrum(x, fs);

% plot
figure(1)
plot(freq/1000, Xamp, 'r') 
grid on
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlim([0 max(freq/1000)])
ylim([-90 max(Xamp)+10])
xlabel('Frequency, kHz') 
ylabel('Magnitude, dB')
title('Amplitude spectrum of the signal') 

Contact us