code correction : subplot in for + length problem
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I was wondering if it was possible to write the code with subplots as I did. The idea of the program is to display a low-pass filter on the same window, with the index response at the top and the frequency response at the bottom. We vary N and display the curves in different colors on the same graph (the same subplot), whether for RF or stem.
Added to this is an error during program execution :
Error using stem (line 43)
X must be same length as Y.
Error in filtrage (line 11)
stem(axe,formula);
But when I test the length with length I get the same size. I'll let you be the judge:
-----------------------------------------------------------------------------------
% Passe-Bas
figure
for N = [10,40,100]
subplot(2,1,1);
axe,formula = passe_bas(N);
stem(axe,formula);
subplot(2,1,2);
RF = abs(freqz(formula));
f = linspace(0,0.5,length(RF));
plot(f,RF);
end
function [axe,formula] = passe_bas(N)
v0 = 0.2;
n=-round(N/2):1:round(N/2);
axe = 0:1:length(n)-1;
formula=2*v0*sinc(2*v0*n);
end
-------------------------------------------------------------------------------------
Thanks for your answers.
댓글 수: 0
답변 (1개)
Chunru
2023년 10월 17일
figure
for N = [10,40,100]
subplot(2,1,1);
hold on
[axe,formula] = passe_bas(N);
% brackets above
stem(axe,formula);
subplot(2,1,2);
hold on
RF = abs(freqz(formula));
f = linspace(0,0.5,length(RF));
plot(f,RF);
end
function [axe,formula] = passe_bas(N)
v0 = 0.2;
n=-round(N/2):1:round(N/2);
axe = 0:1:length(n)-1;
formula=2*v0*sinc(2*v0*n);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!