WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Signalanalyse mit 2d Plots und FFT, IFFT, Leistungsspektrum

 

brummfritz
Forum-Anfänger

Forum-Anfänger


Beiträge: 21
Anmeldedatum: 01.09.16
Wohnort: Düsseldorf
Version: Matlab R2015b
     Beitrag Verfasst am: 06.07.2017, 11:53     Titel: Signalanalyse mit 2d Plots und FFT, IFFT, Leistungsspektrum
  Antworten mit Zitat      
Ein Script zur Signalanalyse und hoffentlich fehlerfrei.

SCILAB ist das Beste!

Code:
mclose('all');
clear;
xdel();
z=struct('wa',0,'ft',0,'ftl',0,'ftr',0,'st1',0,'st2',0,'lz',0,'g',0,'da',0,'pf',0,'re',0,'sf',0,'pfda',0,'info',0,'vs',1,'h1',0,'f1',0,'h2',0,'f2',0,'h3',0,'f3',0,'h3b',0,'f3b',0,'h4',0,'f4',0,'po',0,'fi',0);
/////////////////////////////////////////////////////////////////////////////
function [z]=neudatei(z)
//////////////////////////////////////////////////////////////////////////////
// WAV Datei auswählen   D:\Mdaten\Testsignale/100Hz-03A_g.wav
[z.da,z.pf]=uigetfile('*.wav','D:\Mdaten');    //WAV Datei wählen
if isequal(z.da,'');    //Ist eine Date gewählt?
    else
z.pfda=z.pf+'\'+z.da;  //Vollständigen Pfad erstellen
z.info = wavread(z.pfda,'info');  //WAV Info`s laden
disp('//////////////////////////////////////////////////////////')
disp('WAV-Datei: '+z.pfda); //Ausgabe vollständiger Pfad
disp('Kanäle: '+string(z.info(2)));   //Ausgabe Anzahl der Kanäle
disp('Samplerate: '+string(z.info(3)));   //Ausgabe Samplerate
disp('Dateilänge : '+string(z.info(8)));    //Ausgabe Dateilänge
disp('Laufzeit : '+string(z.info(8)/z.info(3))+' Sekunden');    //Laufzeit in Sek.
disp('//////////////////////////////////////////////////////////')
z.lz=floor(z.info(8)/z.info(3)); // lauzeit in sekunden
z.sf=z.info(3); //Samplerate der Audiodatei
set(u6,'string',z.pfda);
//
set(u11, 'min',1);
set(u11,'max',z.lz);
//
if z.f1==0 then
else
delete(z.f1);
delete(z.f2);
delete(z.f3);
delete(z.f3b);
delete(z.f4);
end
//
z.po=u11.value;
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
if z.po<1 then
u11.value=1;
z.po=u11.value;
end
if z.po>z.lz then
u11.value=z.lz;
z.po=u11.value;
end
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
z.st2=z.po*z.sf;
z.st1=z.st2-z.sf+1;
[z]=rechenwerk(z);
[z]=linkeseite(z);
[z]=mitteseite(z);
[z]=rechteseite(z);
[z]=untenseite(z);
end
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=rechenwerk(z)// rechenwerk
//// FFT brechnen
z.wa=wavread(z.pfda,[z.st1 z.st2]);
z.wa=z.wa(1,:);
z.wa=z.wa*z.vs;// verstärkung
z.ft=fft(z.wa,-1,'nonsymmetric'); //Die FFT wird berechnen
z.ft=z.ft/z.sf;
z.g=abs(z.ft(1));
z.ftr=z.ft;
z.ft=abs(z.ft(2:z.sf));
// powerspektrum
z.ftl=z.ft
z.ftl=abs(z.ft.* conj(z.ft));   //Powerspektrum der FFT berechnen
// rücktransformation
y=z.ftr;
y(1)=0;
y(z.fo+2:z.sf)=0;
z.re=fft(y,1)*z.sf*2;//
// normieren
z.g=z.g*1000;// normieren
z.ft=z.ft*2000;// normieren
z.ftl=z.ftl*4000;// normieren
////
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=linkeseite(z)
sca(z.h1)
s=z.wa*z.vs;
plot(s,'magenta','thickness',1);
z.f1=gce();
z.h1.visible = "on";
z.h1.axes_visible = ["on","on","on"];
z.h1.axes_reverse = ["off","off","off"];
z.h1.auto_ticks = ["off","off","off"];

z.h1.grid = [1,1];
z.h1.grid_thickness = [1,1];
z.h1.grid_style = [1,1];
z.h1.grid_position = "background";

z.h1.title.font_size=2;
z.h1.title.text="WAV Signal";
z.h1.x_label.font_size=2;
z.h1.x_label.text="Zeit in Millisekunden";
z.h1.x_label.visible="on";
z.h1.y_label.font_size=2;
z.h1.y_label.text="Amplitude";
z.h1.y_label.visible="on";

z.h1.auto_scale="off";
// zeitachse
z.h1.x_ticks=tlist(['locations','labels'],[1,4800,9600,14400,19200,24000,28800,33600,38400,43200,48000],["0","100","200","300","400","500","600","700","800","900","1000"]);
// amplitudenachse
z.h1.y_ticks=tlist(['locations','labels'],[-1,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1],["-1","-0.9","-0.8","-0.7","-0.6","-0.5","-0.4","-0.3","-0.2","-0.1","0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"]);

z.h1.sub_tics=[9,9,9];

z.h1.box = "back_half";
z.h1.background = -2;
z.h1.tight_limits = ["on","on"];
z.h1.cube_scaling = "on";
z.h1.isoview = "off";
// mit den folgenden einstellungen der drei achsen kann die Anzeige angepasst werden
/////////////////////////////////////////////////////////////////////////////
zh=z.h1.data_bounds;
zh(1,2)=-1;
zh(2,2)=1;
zh(1,1)=1;
zh(2,1)=z.sf;
z.h1.data_bounds =zh;
z.h1.tag='Links';
//z.so=zi.so-1;
//
////////////////////////
endfunction
//////////////////////////////////////////////////////////////////////
function [z]=mitteseite(z)
sca(z.h2);
bar(0,z.g,1,'green');
z.f2=gce();
z.h2.visible = "on";
z.h2.axes_visible = ["on","on","on"];
z.h2.axes_reverse = ["off","off","off"];
z.h2.auto_ticks = ["off","off","off"];

z.h2.grid = [1,1];
z.h2.grid_thickness = [1,1];
z.h2.grid_style = [1,1];
z.h2.grid_position = "background";
z.h2.title.font_size=2;
z.h2.title.text="DC";
z.h2.x_label.font_size=2;
//zi.h4.x_label.text="";
//zi.h4.x_label.visible="on";
z.h2.y_label.font_size=2;
z.h2.y_label.text="Amplitude";
z.h2.y_label.visible="on";

z.h2.auto_scale="off";
// zeitachse
//zi.h4.x_ticks=tlist(['locations','labels'],[0],['0']);
// amplitudenachse
z.h2.y_ticks=tlist(['locations','labels'],[0,100,200,300,400,500,600,700,800,900,1000],["0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"]);
z.h2.sub_tics=[9,0,0];

z.h2.box = "back_half";
z.h2.background = -2;
z.h2.tight_limits = ["on","on"];
z.h2.cube_scaling = "off";
z.h2.isoview = "off";
// mit den folgenden einstellungen der drei achsen kann die Anzeige angepasst werden
/////////////////////////////////////////////////////////////////////////////
zh=z.h2.data_bounds;
zh(1,2)=0;
zh(2,2)=1000;
zh(1,1)=-0.1;
zh(2,1)=0.1;
z.h2.data_bounds =zh;
z.h2.tag='Mitte';
//
////////////////////////
endfunction
//////////////////////////////////////////////////////////////////////
function [z]=rechteseite(z)
sca(z.h3)
v=z.ft(1:500);
w=z.ftl(1:500);
plot(v,'blue','thickness',2);
z.f3=gce()
plot(w,'red','thickness',2);
z.f3b=gce()
//////////////////////
z.h3.visible = "on";
z.h3.axes_visible = ["on","on","on"];
z.h3.axes_reverse = ["off","off","off"];
z.h3.auto_ticks = ["off","off","off"];

z.h3.grid = [1,1];
z.h3.grid_thickness = [1,1];
z.h3.grid_style = [1,1];
z.h3.grid_position = "background";

z.h3.title.font_size=2;
z.h3.title.text="FFT (blau) & FFT-Leistung (rot)";
z.h3.x_label.font_size=2;
z.h3.x_label.text="Frequenz";
z.h3.x_label.visible="on";
z.h3.y_label.font_size=2;
z.h3.y_label.text="Amplitude";
z.h3.y_label.visible="on";

z.h3.auto_scale="off";
// frequenzaschse
z.h3.x_ticks=tlist(['locations','labels'],[0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480,490,500],["0","10","20","30","40","50","60","70","80","90","100","110","120","130","140","150","160","170","180","190","200","210","220","230","240","250","260","270","280","290","300","310","320","330","340","350","360","370","380","390","400","410","420","430","440","450","460","470","480","490","500"]);
// amplitudenachse
z.h3.y_ticks=tlist(['locations','labels'],[1,100,200,300,400,500,600,700,800,900,1000],["0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"]);

z.h3.sub_tics=[9,9,9];

z.h3.box = "back_half";
z.h3.background = -2;
z.h3.tight_limits = ["off","off"];
z.h3.cube_scaling = "on";
z.h3.isoview = "off";
// mit den folgenden einstellungen der drei achsen kann die Anzeige angepasst werden
/////////////////////////////////////////////////////////////////////////////
zh=z.h3.data_bounds;
zh(1,2)=0;
zh(2,2)=1000;
zh(1,1)=0;
zh(2,1)=250;
z.h3.data_bounds =zh;
z.h3.tag='Rechts';
///////////////////////////////////////////////////////////////////////
endfunction
///////////////////////////////////////////////////////////////////////
function [z]=untenseite(z)
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
z.h4.visible = "on";
z.h4.axes_visible = ["on","on","on"];
z.h4.axes_reverse = ["off","off","off"];
z.h4.auto_ticks = ["off","off","off"];

z.h4.grid = [1,1];
z.h4.grid_thickness = [1,1];
z.h4.grid_style = [1,1];
z.h4.grid_position = "background";

z.h4.title.font_size=2;
z.h4.title.text="Inverse FFT mit F-Max";
z.h4.x_label.font_size=2;
z.h4.x_label.text="Zeit in Millisekunden";
z.h4.x_label.visible="on";
z.h4.y_label.font_size=2;
z.h4.y_label.text="Amplitude";
z.h4.y_label.visible="on";

z.h4.auto_scale="off";
// zeitachse
z.h4.x_ticks=tlist(['locations','labels'],[1,4800,9600,14400,19200,24000,28800,33600,38400,43200,48000],["0","100","200","300","400","500","600","700","800","900","1000"]);
// amplitudenachse
z.h4.y_ticks=tlist(['locations','labels'],[-1,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1],["-1","-0.9","-0.8","-0.7","-0.6","-0.5","-0.4","-0.3","-0.2","-0.1","0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"]);


z.h4.sub_tics=[9,9,9];

z.h4.box = "back_half";
z.h4.background = -2;
z.h4.tight_limits = ["on","on"];
z.h4.cube_scaling = "on";
z.h4.isoview = "off";
// mit den folgenden einstellungen der drei achsen kann die Anzeige angepasst werden
/////////////////////////////////////////////////////////////////////////////
zh=z.h4.data_bounds;
zh(1,2)=-1;
zh(2,2)=1;
zh(1,1)=1;
zh(2,1)=z.sf;
z.h4.data_bounds =zh;
z.h4.tag='Unten';
//
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=links(z)
if z.po<=1 then
else
if z.f1==0 then
else
delete(z.f1);
delete(z.f2);
delete(z.f3);
delete(z.f3b);
delete(z.f4);
end
z.po=z.po-1;
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
z.st1=z.st1-z.sf;
z.st2=z.st2-z.sf;
[z]=rechenwerk(z);
// linkeseite
sca(z.h1)
s=z.wa*z.vs;
plot(s,'magenta','thickness',1);
z.f1=gce();
//mitteseite;
sca(z.h2);
bar(0,z.g,1,'green');
z.f2=gce();
// rechteseite        
sca(z.h3);
v=z.ft(1:500);
w=z.ftl(1:500);
plot(v,'blue','thickness',2);
z.f3=gce();
plot(w,'red','thickness',2);
z.f3b=gce();
//untenseite
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
end
endfunction
//////////////////////////////////////////////////////////////////////////////
function [z]=rechts(z)
if z.po>=z.lz then
else
if z.f1==0 then
else
delete(z.f1);
delete(z.f2);
delete(z.f3);
delete(z.f3b);
delete(z.f4);
end
z.po=z.po+1;
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
z.st1=z.st1+z.sf;
z.st2=z.st2+z.sf;
[z]=rechenwerk(z);
// linkeseite
sca(z.h1)
s=z.wa*z.vs;
plot(s,'magenta','thickness',1);
z.f1=gce();
//mitteseite;
sca(z.h2);
bar(0,z.g,1,'green');
z.f2=gce();
// rechteseite        
sca(z.h3);
v=z.ft(1:500);
w=z.ftl(1:500);
plot(v,'blue','thickness',2);
z.f3=gce();
plot(w,'red','thickness',2);
z.f3b=gce();
//untenseite
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
end
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=verst(z)
if z.f1==0 then
else
delete(z.f1);
delete(z.f2);
delete(z.f3);
delete(z.f3b);
delete(z.f4);
end
z.vs=u7.value;
[z]=rechenwerk(z);
// linkeseite
sca(z.h1)
s=z.wa*z.vs;
plot(s,'magenta','thickness',1);
z.f1=gce();
//mitteseite;
sca(z.h2);
bar(0,z.g,1,'green');
z.f2=gce();
// rechteseite        
sca(z.h3);
v=z.ft(1:500);
w=z.ftl(1:500);
plot(v,'blue','thickness',2);
z.f3=gce();
plot(w,'red','thickness',2);
z.f3b=gce();
//untenseite
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
//////////////////////
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=fober(z)
if z.f4==0 then
else
delete(z.f4);
//
z.fo=u9.value;    
if z.fo > 250 then
    u9.value=250;
    z.fo=u9.value;
end
if z.fo < 1 then
    u9.value=250;
    z.fo=u9.value;
end
//
y=z.ftr;
y(1)=0;
y(z.fo+2:z.sf)=0;
z.re=fft(y,1)*z.sf*2;//
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
end
endfunction
/////////////////////////////////////////////////////////////////////////////
function [z]=position(z)
z.po=u11.value;
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
if z.po<1 then
u11.value=1;
z.po=u11.value;
end
if z.po>z.lz then
u11.value=z.lz;
z.po=u11.value;
end

if z.f1==0 then
else
delete(z.f1);
delete(z.f2);
delete(z.f3);
delete(z.f3b);
delete(z.f4);
end
set(u3,'string',string(z.po)+'. Sek. von '+string(z.lz));
//z.st1=z.po*z.sf;
z.st2=z.po*z.sf;
z.st1=z.st2-z.sf+1;
[z]=rechenwerk(z);
// linkeseite
sca(z.h1)
s=z.wa*z.vs;
plot(s,'magenta','thickness',1);
z.f1=gce();
//mitteseite;
sca(z.h2);
bar(0,z.g,1,'green');
z.f2=gce();
// rechteseite        
sca(z.h3);
v=z.ft(1:500);
w=z.ftl(1:500);
plot(v,'blue','thickness',2);
z.f3=gce();
plot(w,'red','thickness',2);
z.f3b=gce();
//untenseite
sca(z.h4);
v=z.re;
plot(v,'red','thickness',1);
z.f4=gce();
   
endfunction
/////////////////////////////////////////////////////////////////////////////
// start
z.vs=1;
z.fo=250;
z.po=0;
//
z.fi=figure('position',[10,10,1400,900]);
z.fi.background= 33;
z.fi.color_map = jetcolormap(1000); //Colormap festlegen
z.fi.visible = "on";
z.fi.figure_name="Signalanalyse";
z.fi.BackgroundColor=[1 1 1];
//z.tag='Formular';
// controls
u1=uicontrol(z.fi,"style","pushbutton", 'position', [1000 50 60 30],'string','Neu','callback','[z]=neudatei(z)');

u3=uicontrol(z.fi,"style","text",'HorizontalAlignment','center' ,'position', [1135 95 95 30],'string','0. Sek.');

u5=uicontrol(z.fi,"style","pushbutton", 'position', [1300 50 60 30],'string','Exit','callback','close');
u6=uicontrol(z.fi,"style","text",'HorizontalAlignment','left' ,'position', [100 5 1200 30],'string','');
u7=uicontrol(z.fi,"style","spinner", 'position', [1150 205 50 40],'HorizontalAlignment','center','VerticalAlignment','middle','min',1,'max',10,'SliderStep',[1,10],'Title_position','top','callback','[z]=verst(z)');
u8=uicontrol(z.fi,"style","text",'HorizontalAlignment','left' ,'position', [1145 250 60 20],'string','Verstärkung');
u9=uicontrol(z.fi,"style","spinner", 'position', [650 205 50 40],'HorizontalAlignment','center','VerticalAlignment','middle','min',1,'max',250,'SliderStep',[1,10],'Title_position','top','callback','[z]=fober(z)');
u9.value=250;

u10=uicontrol(z.fi,"style","text",'HorizontalAlignment','left' ,'position', [645 250 60 20],'string','F max (Hz)');

u11=uicontrol(z.fi,"style","spinner", 'position', [1135 50 100 40],'HorizontalAlignment','center','VerticalAlignment','middle','min',1,'max',1,'SliderStep',[1,10],'Title_position','top','callback','[z]=position(z)');

/////////////////////////////////
//
//
z.h1 = newaxes();
z.h1.axes_bounds = [0,0,0.5,0.5];
//
z.h2 = newaxes();
z.h2.axes_bounds = [0.495,0,0.02,0.5];
//
z.h3 = newaxes();
z.h3.axes_bounds = [0.5,0,0.5,0.5];
//
z.h4 = newaxes();
z.h4.axes_bounds = [0,0.5,0.5,0.5];
//

 
Private Nachricht senden Benutzer-Profile anzeigen


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.