NEED HELP with fir1

5 ビュー (過去 30 日間)
Justin tran
Justin tran 2022 年 4 月 29 日
コメント済み: Walter Roberson 2022 年 4 月 29 日
clc;
clear all;
f1 = 100;
f2 = 300;
f3 = 800;
fs = 5000;
m = (0.3*f1)/(f2/2);
M = rand(8/m);
N = M-1;
b = fir1(N,25*f2/(fs/2));
fig(1)
[h,f]= freqz(b,1,512);
plot(f*fs /(2*pi), 20*log10(abs(h)))
xlabel('frequency/Hz'); ylabel('/db');
title('Gain response of band pass filter');
axis [0 0.1 -22];
subplot [3 1 2];
Fs = fft (s,4096);
Afs=abs(Fs);
f = (0:255)*fs/4096;
plot(f,Afs(1:256));
xlabel('Frequency/Hz');ylabel('Amplitude')
title('Frequency domain diagram before filtering')
figure(3)
sF =fft(s,4096);
sf =filter(b,1,5);
subplot [3 1 3];
plot(t,sf)
xlabel('/s');
ylabel('Amplitude')
Afsf = abs(Fsf);
f=(0:255)*fs/4096;
plot(Afsf(1:256))
xlabel('Frequency/Hz');
ylabel('Amplitude')
need help with fir1
  2 件のコメント
John D'Errico
John D'Errico 2022 年 4 月 29 日
編集済み: John D'Errico 2022 年 4 月 29 日
When you have a question, is there a good reason why you would post a PICTURE of your code? Instead, all you needed to do was to paste in the text itself, complete with the error message. At least you included that.
But by posting only a picture of your code, we cannot now copy that into MATLAB, to show you what you did wrong. We need to retype it from scratch. In fact though, it is actually easier to just paste in text, so you did this the hard way for yourself, and you decreased the fraction of people who might be willing to help you.
Is there a good, valid reason why you want to make it more difficult for someone to help you?
Justin tran
Justin tran 2022 年 4 月 29 日
Sorry about that. I pasted the code in text for you to use. My apologies

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

回答 (1 件)

Paul
Paul 2022 年 4 月 29 日
編集済み: Paul 2022 年 4 月 29 日
Hi Justin,
Executing the top part of the code ...
f1 = 100;
f2 = 300;
f3 = 800;
fs = 5000;
m = (0.3*f1)/(f2/2);
M = rand(8/m);
N = M-1;
For fir1 to work, N must be an integer scalar. It's not a scalar, and the elements of N are not integers.
size(N)
ans = 1×2
40 40
N(1,1)
ans = -0.5760
For fir1 to work, the second argument has to be between 0 and 1. It isn't.
25*f2/(fs/2)
ans = 3
%b = fir1(N,25*f2/(fs/2));
Can you provide more insight into what you're trying to accomplish with this code?
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 29 日
Note that rand() with a single parameter returns a square matrix, not a vector.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by