numSamples = 250;
t = linspace(0,50,numSamples);
x = sin(2*pi*100*t) + 0.7*cos(2*pi*500*t);
xn = x + 5.*randn(size(t));

回答 (1 件)

Star Strider
Star Strider 2021 年 5 月 20 日

1 投票

I bellieve ‘NumSamples’ should be larger.
Try this —
Fs = 5000; % <- ADDED
Fn = Fs/2; % <- ADDED
numSamples = 250*Fs; % <- CHANGED
t = linspace(0,50,numSamples);
x = sin(2*pi*100*t) + 0.7*cos(2*pi*500*t);
xn = x + 5.*randn(size(t));
originalSpectrum = fft(x);
noisySpectrum = fft(xn);
Fv = linspace(0, 1, fix(numel(t)/2)+1)*Fn; % One-Sided Fourier Transform Frequency Vector
Iv = 1:numel(Fv); % Corresponding Index Vector
figure
subplot(4, 1, 1);
plot(Fv, abs(originalSpectrum(Iv))*2, 'b-', 'LineWidth', 2);
grid on;
xlabel('t');
ylabel('x');
subplot(4, 1, 2);
plot(Fv, abs(noisySpectrum(Iv))*2, 'b-', 'LineWidth', 2);
dee = designfilt('lowpassfir', 'PassbandFrequency', 500, ...
'StopbandFrequency', 600, ...
'PassbandRipple', 1, 'StopbandAttenuation', 100, ...
'SampleRate', 5000);
dataOut = filter(dee,xn);
subplot(4, 1, 3);
plot(dataOut);
trfcn = fft(dataOut)./noisySpectrum;
subplot(4,1,4) % <- ADDED
plot(Fv, abs(trfcn(Iv)))
title('Transfer Function Of Filter')
I did not change anything of significance, just added some tweaks to make it a bit easier to understand.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 5 月 20 日

編集済み:

2021 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by