Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Fourier, animazioni

Analisi, geometria, algebra, topologia...

Moderatori: Foto UtentePietroBaima, Foto UtenteIanero

5
voti

[1] Fourier, animazioni

Messaggioda Foto UtenteFedhman » 9 nov 2016, 18:58

Tanto per trafficare un po' coi video ho fatto questo su MATLAB:


Vi piace? Fareste qualche modifica? Non so se rallentare ancora lo stacco tra la decima armonica e le altre.
Se volete vedere qualche altra forma d'onda basta poco per riciclare il codice.
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

0
voti

[2] Re: Fourier, animazioni

Messaggioda Foto UtenteDanteCpp » 11 nov 2016, 14:29

Bellino, puoi condividere il codice?
Avatar utente
Foto UtenteDanteCpp
4.730 3 9 13
Master EY
Master EY
 
Messaggi: 1106
Iscritto il: 15 dic 2011, 18:51

4
voti

[3] Re: Fourier, animazioni

Messaggioda Foto UtenteFedhman » 11 nov 2016, 19:48

DanteCpp ha scritto:Bellino, puoi condividere il codice?


Questa è la versione grezza, non l'ho ancora messo a posto

Codice: Seleziona tutto
format long; clc; clf; clear all;
x = -1.5 : 1e-5 : 1.5;

sum = 0;
loops = 1;
F(loops) = struct('cdata',[], 'colormap',[]);
i = 1; %conta i frame

h = gcf; % Current figure handle
set(h,'Resize','on');
assi = gca;
set(h,'PaperPositionMode','manual');
set(h,'PaperPosition',[0 0 9 6]);
set(h,'PaperUnits','centimeters');
set(h,'PaperSize',[15 9]); % IEEE columnwidth = 9cm
set(h,'Position',[100 -100 1920 1080]);

end_n = 400;
arm = 1; %conta le armoniche
for n = 1 : 2 : end_n
    sum = sum + (1/n)*sin(n.*pi.*x);
    f = (4/pi) * sum;
    hold on
    grid on
   
    subplot(2,1,1);
    hold on
   grid on
    curve = plot(x, f, 'Color', 'k', 'LineWidth', 1);
    axis([-0.5 1.5 -1.3 1.3]);
    xticks(-0.5 : 0.25 : 1.5);
    set(gca, 'FontSize', 15);
    yticks([-1.3 -1 -0.5 0 0.5 1 1.3])
    textOnImage = text(-0.4, 0.25, ['Harmonics: ', num2str(arm)],...
       'FontWeight', 'bold', 'FontSize', 20);
    formulaOnImage = text(-0.4, 0.75, 'n odd,   $$ \frac{4}{\pi} \sum_{n = 1}^{200}{\frac{1}{n}sin(n \pi x)} $$',...
       'Interpreter', 'latex', 'FontSize', 60,...
       'FontWeight', 'bold', 'FontSize', 20);
    pos = get(gca, 'Position');
    pos(1) = 0.05;
    pos(2) = 0.55;
    pos(3) = 0.9;
    pos(4) = 0.40;
    set(gca, 'Position', pos);
   
    subplot(2,1,2);
    hold on
   grid on
    curve = plot(x, f, 'Color', 'k', 'LineWidth', 1.7);
    axis([0.92 1 0.8 1.2]);
    set(gca, 'FontSize', 15);
    pos2 = get(gca, 'Position');
    pos2(1) = 0.05;
    pos2(2) = 0.05;
    pos2(3) = 0.9;
    pos2(4) = 0.40;
    set(gca, 'Position', pos2);
   
    hold off
    h = gcf;
    F(i) = getframe(h);
    i = i+1;
   
    %a 30 fps cattura 2 secondi dell'inizio
    if arm == 1
        for a = 1 : 1 : 60
            F(i) = getframe(h);
            i = i+1;
        end
    end
    %a 30 fps cattura 1 secondo della seconda armonica
    if arm == 2
        for a = 1 : 1 : 30
            F(i) = getframe(h);
            i = i+1;
        end
    end
    %a 30 fps cattura 0.5 secondi della terza armonica
    if arm == 3
        for a = 1 : 1 : 15
            F(i) = getframe(h);
            i = i+1;
        end
    end
    %a 30 fps cattura 0.33 secondi delle armoniche dalla 4 alla 10
    if arm == 4 || arm == 5 || arm == 6 ||...
            arm == 7 || arm == 8 || arm == 9 || arm == 10
        for a = 1 : 1 : 10
            F(i) = getframe(h);
            i = i+1;
        end
    end
    arm = arm+1;
    delete(curve)
    delete(textOnImage)
end
i = i-1;
arm = arm-1;
    subplot(2,1,1);
    hold on
   grid on
    curve = plot(x, f, 'Color', 'k', 'LineWidth', 1);
    axis([-0.5 1.5 -1.3 1.3]);
    set(gca, 'FontSize', 15);
    xticks(-0.5 : 0.25 : 1.5);
    yticks([-1.3 -1 -0.5 0 0.5 1 1.3])
    textOnImage = text(-0.4, 0.25, ['Harmonics: ', num2str(arm)],...
       'FontWeight', 'bold', 'FontSize', 20);
    formulaOnImage = text(-0.4, 0.75, 'n odd,   $$ \frac{4}{\pi} \sum_{n = 1}^{200}{\frac{1}{n}sin(n \pi x)} $$',...
       'Interpreter', 'latex', 'FontSize', 60,...
       'FontWeight', 'bold', 'FontSize', 20);
    pos = get(gca, 'Position');
    pos(1) = 0.05;
    pos(2) = 0.55;
    pos(3) = 0.9;
    pos(4) = 0.40;
    set(gca, 'Position', pos);
   
    subplot(2,1,2);
    hold on
   grid on
    curve = plot(x, f, 'Color', 'k', 'LineWidth', 1.7);
    axis([0.92 1 0.8 1.2]);
    set(gca, 'FontSize', 15);
    pos2 = get(gca, 'Position');
    pos2(1) = 0.05;
    pos2(2) = 0.05;
    pos2(3) = 0.9;
    pos2(4) = 0.40;
    set(gca, 'Position', pos2);
i = i+1;

h = gcf;
F(i) = getframe(h);
%a 30 fps cattura 3 secondi della fine
i = i+1;
for a = 1 : 1 : 90
    F(i) = getframe(h);
    i = i+1;
end

V = VideoWriter('C:\Users\Amministratore\Desktop\AAA\beta6');
V.Quality = 100;
V.FrameRate = 30;
open(V);
writeVideo(V,F)
close(V);
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

0
voti

[4] Re: Fourier, animazioni

Messaggioda Foto UtenteFedhman » 12 nov 2016, 16:02

Una versione più semplice, onda a dente di sega senza video:

Codice: Seleziona tutto
clc; clf; clear all;

end_arm = 40; %Quante armoniche sommare
linea = 2; %spessore della linea dei grafici.
%--------
arm = 1; %conta le armoniche
%Aumentare la risoluzione del vettore x
%per osservare gli effetti delle frequenze
%più alte.
x = 0 : 1e-5 : 2;
sum = 0;
a0 = 1;
an = 0;
bn = -1/(pi*arm);

hold on
grid on
for arm = 1 : 1 : end_arm
    %Aggiorna la serie
    a0 = 1;
    an = 0;
    bn = -1/(pi*arm);
    sum = sum + an*cos(2*pi*arm*x) +bn*sin(2*pi*arm*x);
    f = a0/2 +sum;
   
    %Disegna in nero la prima armonica
    if arm == 1 && arm ~= end_arm
        plot(x,f, 'Color', 'k', 'LineWidth', linea);
    end
    %Disegna in blu la terza armonica
    if arm == 3 && arm ~= end_arm
        plot(x,f, 'Color', 'b', 'LineWidth', linea);
    end
    %Disegna in rosso l'ultima armonica (end_arm)
    if arm == end_arm
        plot(x,f, 'Color', 'r', 'LineWidth', linea);
    end
end
formula = ...
    ['$$ \frac{1}{2} +\sum_{n = 1}^{', num2str(end_arm),'}'...
     '{\frac{-1}{\pi n}sin(2 n \pi x)} $$'];
x_formula = 0.2;
y_formula = 1.1;
formulaOnImage = text(x_formula, y_formula, formula,...
   'Interpreter', 'latex', 'FontSize', 60, ...
   'FontWeight', 'bold', 'FontSize', 20);
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

4
voti

[5] Re: Fourier, animazioni

Messaggioda Foto UtenteFedhman » 12 nov 2016, 16:49

Sovrapponendo le armoniche vengono fuori disegni molto belli

untitled.jpg
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

4
voti

[6] Re: Fourier, animazioni

Messaggioda Foto UtenteFedhman » 12 nov 2016, 19:03

Con 330 armoniche, da 0.494 a 0.5, periodo dell'onda 1:
Untitled-4.jpg

Particolare:
Pattern.jpg

Codice: Seleziona tutto
clc; clf; clear all;
end_arm = 330; %Quante armoniche sommare
linea = 0.3; %spessore della linea dei grafici.
xAsseMin = 0.494; xAsseMax = 0.5;
yAsseMin = 0.494; yAsseMax = 0.5;
%--------
arm = 1; %conta le armoniche
%Aumentare la risoluzione del vettore x
%per osservare gli effetti delle frequenze
%più alte.
x = xAsseMin : 1e-7 : xAsseMax;
sum = 0;
a0 = 1;
an = 0;
bn = -1/(pi*arm);
hold on %sovrapponi le armoniche
for arm = 1 : 1 : end_arm
    %Aggiorna la serie
    a0 = 1;
    an = 0;
    bn = -1/(pi*arm);
    sum = sum + an*cos(2*pi*arm*x) +bn*sin(2*pi*arm*x);
    f = a0/2 +sum;
    %Disegna l'armonica in nero
    plot(x,f,'Color','k','LineWidth',linea);
end
axis([xAsseMin xAsseMax yAsseMin yAsseMax]); %aggiusta gli assi
set(gca,'visible','off') %elimina gli assi
%Elimina i bordi attorno alla figura:
pos = get(gca, 'Position');
pos(1) = 0;
pos(2) = 0;
pos(3) = 1;
pos(4) = 1;
set(gca, 'Position', pos);
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

3
voti

[7] Re: Fourier, animazioni

Messaggioda Foto UtenteIanero » 13 nov 2016, 0:45



:shock:
Avatar utente
Foto UtenteIanero
8.069 5 8 11
Master EY
Master EY
 
Messaggi: 4320
Iscritto il: 21 mar 2012, 15:47

0
voti

[8] Re: Fourier, animazioni

Messaggioda Foto UtenteFedhman » 13 nov 2016, 1:46

Sono molto belle! Le avevo viste tempo fa
I don't fight weather - Woodrow W. Smith
Avatar utente
Foto UtenteFedhman
5.195 2 9 13
Master
Master
 
Messaggi: 483
Iscritto il: 4 giu 2013, 14:05
Località: Augusta Taurinorum

1
voti

[9] Re: Fourier, animazioni

Messaggioda Foto Utentesebago » 13 nov 2016, 9:15

Foto UtenteIanero, peccato aver solo un voto. Eccezionale!
Sebastiano
________________________________________________________________
"Eo bos issettaìa, avanzade e non timedas / sas ben'ennidas siedas, rundinas, a domo mia" (P. Mossa)
Avatar utente
Foto Utentesebago
16,7k 4 10 13
G.Master EY
G.Master EY
 
Messaggi: 2196
Iscritto il: 1 apr 2005, 19:59
Località: Orune (NU)

1
voti

[10] Re: Fourier, animazioni

Messaggioda Foto UtenteIanero » 13 nov 2016, 14:16

Dai, allora facciamo che mi ricarichi la postepay :mrgreen:
:shock:
Avatar utente
Foto UtenteIanero
8.069 5 8 11
Master EY
Master EY
 
Messaggi: 4320
Iscritto il: 21 mar 2012, 15:47


Torna a Matematica generale

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti