Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Цифр_фильтры.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
1.06 Mб
Скачать

Текст программы дискретного преобразования Фурье

uses graph, crt;

type aa= array[0..4096] of real;

var

i,j,n,n1,m,Gd,Gm,x0,xm,x1,y0,ym,y1,xx,yy : integer;

c,c1,max,min,a1,a2 : real;

w,jj : longint;

tt : string;

s,x,a,b,z :^aa;

{================ Markov ===================}

procedure Markov;

var ss : real;

ii,i2,k : integer;

begin randomize; ss:=0; k:=1;

for ii:=1 to M do z^[ii]:=random-0.5;

- 121 -

for ii:=1 to M do ss:=ss+z^[ii];

for i2:=0 to N do begin x^[i2]:=ss/M;

ss:=ss-z^[k]; z^[k]:=random-0.5; ss:=ss+z^[k];

if k<M then inc(k) else k:=1; end;

end;

{---------------------------------------}

begin new(s); new(x); new(a); new(b); new(z);

w:=1; M:=30; N:=1024;

x0:=50; xm:=600; c1:=(xm-x0)/N;

gotoxy(10,1);write('N = ',N:5);gotoxy(50,1);

if readkey<>#13 then readln(n);

gotoxy(10,2);write('M = ',M:5);gotoxy(50,2);

if readkey<>#13 then readln(m);

Gd:=EGA; GM:=EGAHI; InitGraph(Gd,Gm,''); setbkcolor(15);

For i:=0 to N div 2 do s^[i]:=1e-30;

repeat

if odd(w) then

begin SetVisualPage(0); SetActivePage(1) end else

begin SetVisualPage(1); SetActivePage(0);end;

clearviewport; setcolor(1);

{=========== Noise =================}

y0:=5; ym:=80; y1:=y0+(ym-y0) div 2;

outtextxy(GetMaxX-10,(y0+ym) div 2,'1');

line(x0,y1,xm+20,y1); line(x0,y0,x0,ym);

Markov;

{********************************************************}

Max:=1e-18 ; for i:=0 to N do

if Max<abs(x^[i]) then Max:=abs(x^[i]);

c:=(ym-y1)/max; moveto(x0,y1-round(c*x^[1]));

For i:=1 to N do lineto(x0+round(i*c1),y1-round(c*x^[i]));

{======================= PSD ==========================}

y0:=110; ym:=310; y1:=y0+(ym-y0) div 2;

outtextxy(GetMaxX-10,y1,'2');

{------------- DFT -------------------------------}

for i:=1 to n div 2 do begin

a^[i]:=0 ; b^[i]:=0; a1:=2*pi*i/n;

for j:=1 to n-1 do begin a2:=a1*j;

a^[i]:=a^[i]+x^[j]*cos(a2);

b^[i]:=b^[i]+x^[j]*sin(a2); end; end;

{----------------------------------------------------}

- 122 -

n1:=n div 2;Max:=1e-30;Min:=1e30;

for i:=1 to N1 do s^[i]:=s^[i]+a^[i]*a^[i]+b^[i]*b^[i];

for i:=2 to N1 do begin

if Max<s^[i] then Max:=s^[i];

if Min>s^[i] then Min:=s^[i]; end;

str((max/w):10:3,tt);outtextxy(10,getmaxy-10,'So = '+tt);

{--------------- Graphic -----------------------------}

jj:=1; setlinestyle(1,1,1);

For i:=0 to 3 do begin

xx:=x0+round((xm-x0)*i*ln(10)/ln(N1-1));

if xx<=xm then begin line(xx,y0,xx,ym);

str(jj:4,tt); outtextxy(xx+i*5-27,ym+10,tt); end;

jj:=jj*10; end;

c:=(ym-y0)/(ln(Max/Min));

{--------- Vertical -------------------}

jj:=1000; For i:=0 to 8 do begin

yy:=y0+round(c*i*ln(10));

if yy<=ym then begin

line(x0,yy,xm,yy); outtextxy(x0-37,yy,'10');

str(-i,tt);outtextxy(x0-20,yy-4,tt);end;

jj:=jj div 10; end;

setlinestyle(0,0,1); rectangle(x0-3,y0-3,xm+3,ym+3);

{----------- Plot ----------------------}

moveto(x0,ym-round(c*ln(s^[2]/min)));

for i:=3 to N1-1 do begin

yy:=ym-round(c*ln(s^[i]/Min));

xx:=x0+round((Xm-x0)*ln(i-1)/ln(N1-1));

lineto(xx,yy); end;

{----------------------------------------}

str(w:10,tt);outtextxy(550,1,tt);

if w<100000 then inc(w) else w:=1;

until keypressed; closegraph; end.