how can I plot frequency spectrum and impulse response with hold on?

38 ビュー (過去 30 日間)
studentmatlaber
studentmatlaber 2021 年 11 月 30 日
コメント済み: Star Strider 2021 年 12 月 15 日
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.

採用された回答

Star Strider
Star Strider 2021 年 11 月 30 日
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 件のコメント
studentmatlaber
studentmatlaber 2021 年 12 月 15 日
"to divide the entire signal magnitude by the maximum magnitude" It didn't come to life as a code in my head.
f_radsec = Fv2 * pi / Fn; %Hz to rad/sample
fvtool(b,1) %impulse response
hold on
ydb = mag2db(abs(X)); %amplitude to magnitude (dB)
plot(f_radsec, ydb);
What do i need to add? Thank you very much for your time.
Star Strider
Star Strider 2021 年 12 月 15 日
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.
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by