フィルターのクリア

Error (( vector must be the same length))

2 ビュー (過去 30 日間)
Melika Eft
Melika Eft 2023 年 3 月 11 日
コメント済み: Melika Eft 2023 年 3 月 11 日
Hello I have this code and it gives that error at plot(t,x_bp)could you please help me thank you indeed
% Generate a lowpass signal fs = 1000; % sampling frequency (Hz) t = 0:1/fs:1; % time vector (s) f1 = 10; % frequency of the signal (Hz) x = sin(2*pi*f1*t); % lowpass signal
% Perform FFT and IFFT X = fft(x); X_bp = [zeros(1,100), X(101:401), zeros(1,499)]; % create bandpass frequency domain signal x_bp = ifft(X_bp);
% Create a bandpass filter fc = [5 15]; % bandpass cutoff frequencies (Hz) order = 50; % filter order b = fir1(order, fc/(fs/2)); % FIR filter coefficients
% Apply the bandpass filter x_bp_filt = filtfilt(b, 1, x_bp);
% Plot the results subplot(2,2,1); plot(t, x); title('Lowpass Signal'); xlabel('Time (s)'); ylabel('Amplitude');
subplot(2,2,2); plot(t, x_bp); title('Bandpass Signal (Frequency Domain)'); xlabel('Time (s)'); ylabel('Amplitude');
subplot(2,2,3:4); freqz(b); title('Filter Frequency Response');

採用された回答

aakash dewangan
aakash dewangan 2023 年 3 月 11 日
length of t and x_bp are not same. Theymust have same length to plot the graph using plot command.
You may use maximum available points to plot by modifying your code as
% Generate a lowpass signal
fs = 1000; % sampling frequency (Hz)
t = 0:1/fs:1; % time vector (s)
f1 = 10; % frequency of the signal (Hz)
x = sin(2*pi*f1*t); % lowpass signal
% Perform FFT and IFFT
X = fft(x);
X_bp = [zeros(1,100), X(101:401), zeros(1,499)]; % create bandpass frequency domain signal
x_bp = ifft(X_bp); % Create a bandpass filter
fc = [5 15]; % bandpass cutoff frequencies (Hz)
order = 50; % filter order
b = fir1(order, fc/(fs/2)); % FIR filter coefficients
% Apply the bandpass filter
x_bp_filt = filtfilt(b, 1, x_bp);
% Plot the results
subplot(2,2,1); plot(t, x); title('Lowpass Signal'); xlabel('Time (s)'); ylabel('Amplitude');
subplot(2,2,2); plot(t(1:900), x_bp(1:900)); title('Bandpass Signal (Frequency Domain)'); xlabel('Time (s)'); ylabel('Amplitude');
subplot(2,2,3:4); freqz(b); title('Filter Frequency Response');
  1 件のコメント
Melika Eft
Melika Eft 2023 年 3 月 11 日
Thanks for your attention it was very helpful

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFrequency Transformations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by