NEED HELP with fir1

조회 수: 4 (최근 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 CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by