필터 지우기
필터 지우기

why am i getting error in making trapezoidal wave form ?

조회 수: 2 (최근 30일)
ajeet verma
ajeet verma 2017년 8월 4일
댓글: ajeet verma 2017년 8월 9일
i am trying to create trapezoidal wave form but it is not working. please help code: %% FIRST TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s1= @(x) (imx+imn).*(0<=x & x<=T/6) +(imx+imn*(2-6*x/T)).*(T/6<=x & x<=T/3)+(imx).*(T/3<=x & x<=2*T/3)+(imx+imn(6*x/T-4)).*(2*T/3<=x & x<=5*T/6); x = linspace(0, 20); I1 = s1(x); figure(1) plot(x,I1) %% SECOND TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s2= @(x) (imx+imn*(6*x/T)).*(0<=x & x<=T/6) +(imx+imn).*(T/6<=x & x<=T/2)+(imx+imn*(4-6*x/T)).*(T/2<=x & x<=2*T/3)+(imx).*(2*T/3<=x & x<=T); x = linspace(0,20); I2 = s2(x); figure(1) plot(x,I2) %% % THIRD TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s3= @(x) (imx).*(0<=x & x<=T/3) +(imx+imn*(6*x/T-2)).*(T/3<=x & x<=T/2)+(imx+imn).*(T/2<=x & x<=5*T/6)+(imx+imn(6-6*x/t)).*(5*T/6<=x & x<=T); x = linspace(0,20); I3 = s3(x); figure(1) plot(x,I3) please find attachment

채택된 답변

Reza Teimoori
Reza Teimoori 2017년 8월 4일
When posting a question including codes, use the proper code format to properly shape your question.
At multiple instances you defined equations similar to:
imn(6*x/T)
while it should be:
imn*(6*x/T)
There was a whole bunch of other typos too. Also, you did not accurately define the limits of 'x' for pretty much all the segments of the waves. Some times if you pay attenuation to the details of the errors MATLAB provides, you can debug your code a lot faster than asking on MATLABAnswers! Any who, here is the correct version of the code you are looking for. Hope it helps!
%%FIRST TRAPEZOIDAL WAVE FORM
clc; clear all;
imx=8;
imn=2;
T = 20;
s1= @(x) (imx+imn).*((0<=x & x<T/6) | (x>=5*T/6 & x<=T)) ...
+(imx+imn*(2-6*x/T)).*(T/6<=x & x<T/3)...
+(imx).*(T/3<=x & x<2*T/3)...
+(imx+imn*(6*x/T-4)).*(2*T/3<=x & x<5*T/6);
x = linspace(0, 20,500);
I1 = s1(x);
figure(1)
plot(x,I1)
ylim([.9*imx 1.1*(imx+imn)])
%%SECOND TRAPEZOIDAL WAVE FORM
clc; clear all;
imx=8;
imn=2;
T = 20;
s2= @(x) (imx+imn*(6*x/T)).*(0<=x & x<T/6) ...
+(imx+imn).*(T/6<=x & x<T/2)...
+(imx+imn*(4-6*x/T)).*(T/2<=x & x<2*T/3)...
+(imx).*(2*T/3<=x & x<=T);
x = linspace(0,20,500);
I2 = s2(x);
figure(2)
plot(x,I2)
ylim([.9*imx 1.1*(imx+imn)])
THIRD TRAPEZOIDAL WAVE FORM
clc;
clear all;
imx=8;
imn=2;
T = 20;
s3= @(x) (imx).*(0<=x & x<T/3) ...
+(imx+imn*(6*x/T-2)).*(T/3<=x & x<T/2)...
+(imx+imn).*(T/2<=x & x<5*T/6)...
+(imx+imn*(6-6*x/T)).*(5*T/6<=x & x<=T);
x = linspace(0,20,500);
I3 = s3(x);
figure(3)
plot(x,I3)
ylim([.9*imx 1.1*(imx+imn)])
  댓글 수: 1
ajeet verma
ajeet verma 2017년 8월 9일
i want to create color fringe pattern from the combination of these three wave i am trying but something being wrong. so please help my code is here %% trapezoidal color fringes (vertical) clc; clear all; f1=10; % No. of vertical fringes f2=0; % No. of horizontal fringes m=1000; n=1000; a1 = zeros(m,n) ; a2 = zeros(m,n) ; a3 = zeros(m,n) ; % trapezoidal fringe imx=8; imn=2; T = 20; s1= @(x) (imx+imn).*((0<=x & x<=T/6)|(x>=5*T/6 & x<=T))... +(imx+imn*(2-6*x/T)).*(T/6<=x & x<=T/3)... +(imx).*(T/3<=x & x<=2*T/3)... +(imx+imn*(6*x/T-4)).*(2*T/3<=x & x<=5*T/6); s2= @(x) (imx+imn*(6*x/T)).*(0<=x & x<=T/6)... +(imx+imn).*(T/6<=x & x<=T/2)... +(imx+imn*(4-6*x/T)).*(T/2<=x & x<=2*T/3)... +(imx).*(2*T/3<=x & x<=T); s3= @(x) (imx).*(0<=x & x<=T/3)... +(imx+imn*(6*x/T-2)).*(T/3<=x & x<=T/2)... +(imx+imn).*(T/2<=x & x<=5*T/6)... +(imx+imn*(6-6*x/T)).*(5*T/6<=x & x<=T); x = linspace(0,20,50); X = repmat(x, 1000, 20); I1 = s1(X); I2 = s2(X); I3 = s3(X); % figure(1) % subplot(131),imshow(I1,[]) % subplot(132),imshow(I2,[]) % subplot(133),imshow(I3,[]) a1=exp(1i*I1); a2=exp(1i*I2); a3=exp(1i*I3);
subplot(222),imshow(a1,[]),impixelinfo; subplot(223),imshow(a2,[]),impixelinfo; subplot(224),imshow(a3,[]),impixelinfo;
Color=zeros(m,n,3); Color(:,:,1)=a1; Color(:,:,2)=a2; Color(:,:,3)=a3; figure(2) imshow(Color,[]),title('vertical fringes'),impixelinfo;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by