# Plot the magnitude and phase by using Matlab

52 vues (au cours des 30 derniers jours)
Muhammad Rifqi Jafri Zain le 24 Juil 2021
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Yazan le 24 Juil 2021
Here is one way to get the spectrum.
clc, clear
% fundamental frequencies
f1 = 1/3;
f2 = 5/6;
% sampling frequency
fs = 50*max([f1, f2]);
% sampling period
Ts = 1/fs;
% Time span (5 periods)
T = 5*max([1/f1, 1/f2]);
% time axis
t = 0:Ts:T-Ts;
% frequency axis
f = -fs/2:fs/length(t):fs/2-fs/length(t);
% signal
x = 2 + cos(2*pi*f1*t) + 4*sin(2*pi*f2*t);
% fft
X = fftshift(fft(x));
% figure
fig = figure('Units', 'normalized', 'Position', [0.15 0.35 0.75 0.55]);
% plot signal in time
subplot(1, 3, 1), plot(t, x),
xlabel('Time (sec)'); ylabel('Amplitude');
title('Signal'); grid 'minor';
% plot fft magnitude
subplot(1, 3, 2), plot(f, abs(X)),
xlabel('Frequency (Hz)'), ylabel('Magnitude'),
title('Spectrum, magnitude'); grid 'minor';
% plot fft phase
subplot(1, 3, 3), plot(f, unwrap(angle(X))),
xlabel('Frequency (Hz)'); ylabel('Phase');
grid 'minor';
title('Spectrum, unwrapped phase');
##### 2 commentairesAfficher AucuneMasquer Aucune
Muhammad Rifqi Jafri Zain le 24 Juil 2021
i want magnitude and phase only can?
Yazan le 24 Juil 2021
The code is commented almost completely so that you can modify it easily. Just remove the first subplot! Any basic user should be able to do so.

Connectez-vous pour commenter.

Madhu Sri Harsha le 22 Oct 2022
Z1 = -1
Z2 = -2
Z3 = 0.6 + j1.05
Z4 = 0.6 - j1.05
P1 = -0.2
P2 = 0.3
P3 = 0.25 + j0.6
P4 = 0.25 - j0.6
1 Write an expression for H(z) and plot the poles and zeros.
2 Plot the magnitude and phase of H(z).
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Spectral Measurements dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by