how can I plot frequency spectrum and impulse response with hold on?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
studentmatlaber
le 30 Nov 2021
Commenté : Star Strider
le 15 Déc 2021
Hi. I passed the signals in the time domain to the frequency domain and plotted the spectrum:
L = length(Ti{i,j}); % Length Of Time & Signal Vectors
Ts = mean(diff(Tt)); % Sampling Interval
Fs{i,j} = 1/Ts; % Sampling Frequency
Fn = Fs{i,j}/2; % Nyquist Frequency
X = fftshift(fft(x)/L);
Fv2 = linspace(-Fn, Fn, L);
plot(Fv2, abs(X));
grid;
xlabel('Frequency (Hz)');
ylabel('Amplitude');
Then I designed a low pass filter and plotted the impulse response of the filter:
[n, fo, ao, w] = firpmord ([0.09 0.7], [1 0], [0.001 0.01], Fs{i,j});
b = firpm (n, fo, ao, w);
filtered_signal{i,j} = filtfilt(b,1,nonoffset{i,j});
fvtool(b,1)
I want to plot the graph of the signal in the frequency domain and the graph of the impulse response. But I need to convert frequency to normalized frequency and convert amplitude to dB. How can I do these? I would be very happy if you show me a way.
0 commentaires
Réponse acceptée
Star Strider
le 30 Nov 2021
Use freqz instead of fvtool to plot the transfer function of the filter, and specify the sampling frequency of the signal in the freqz call so that the frequency is plotted as actual frequency, not normalised frequency. It will be necessary to plot the phase angle of ‘X’ as well as the amplitude in the appropriate plots, since freqz produces subplot plots. Note that only the ‘positive’ half of ‘X’ will need to be plotted because the freqz transfer function only depicts the ‘positive’ half of its Fourier transform.
.
8 commentaires
Star Strider
le 15 Déc 2021
As always, my pleasure!
I’m thinking something like this —
XdB0 = @(X) mag2db(abs(X) / max(abs(X)));
w = 0:0.1:pi;
X = 1./sort(randn(32,1) + 1j*randn(32,1));
figure
semilogx(w, mag2db(abs(X)))
hold on
semilogx(w, XdB0(X))
hold off
grid
xlabel('Frequency (rad/s)')
ylabel('Magnitude (dB)')
legend('Original','Normallised To 0 dB', 'Location','best')
The normalisation is not absolutely necessary, however using it plots everything with the same maximum 0 dB reference.
.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!