File:Tastgrad-Spektrum.ogv

Original file(Ogg Theora video file, length 13 s, 1,600 × 900 pixels, 1.57 Mbps, file size: 2.39 MB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary edit

Description
Deutsch: Spektrum in Abhängigkeit vom Tastgrad.
Date
Source Own work
Author Mik81
Other versions

Licensing edit

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Source code edit

#! /bin/octave
% GNU Octave / MATLAB
% Benutzer:mik81 @ de.wikipedia.org



%
%
% Große Frage:
%   Welche "amplitude" haben die Spektren?
%
%



%
% Ermittle Signalform
%
 
function [square, realDutycycle] = waveform(dutycycle)
 
  global periods;
  global stepsPerPeriod;
    
  
  realDutycycle = 0;
  
  
  
  steps = periods*stepsPerPeriod;


  for period=0:1:periods-1
    for step=0:1:stepsPerPeriod-1
      if ( step >= dutycycle *stepsPerPeriod)
        square = [square, 0.];
        if ( realDutycycle == 0)
          realDutycycle = step/stepsPerPeriod
          dutycycle
        endif
      else
        if (period == 0 && step == 0)
          square = [+1.];
        else
          square = [square, +1.];
        endif
      endif
    endfor
  endfor
 
 
  dutycycleString = sprintf("%0.3f", dutycycle);
 
  plot((0:1:steps/(0.25*periods)-1)/stepsPerPeriod
      , square(1,1:steps/(0.25*periods)), [";Tastgrad: " , dutycycleString, ";"], "linewidth", 2);
  axis ([0, 0.25*periods, -0.2, +1.2]);
 
  axis ("nolabel");
  axis("labely", "ticxy");
%  xlabel ("");
  set(gca(), "linewidth", 1.5);


endfunction

%
% Berechne Spektrum
%


function [dft, envelop] = spektrum(square, realDutycycle)

  global periods;
  global stepsPerPeriod;
  global timebase;
  steps = periods*stepsPerPeriod;

  freqSteps = steps/2;
 
  %
  % Frequenz = freq*Samplerate*steps
  % n * Fenster
 
  for freq=0:1:freqSteps
    pad =  square .* sin(freq*2*pi*timebase/length(timebase));
    dft(1, freq+1) = sum( pad(1,:) );
    pad =  square .* cos(freq*2*pi*timebase/length(timebase));
    % cos^2 + sin^2
    dft( 1, freq+1) = dft(1, freq+1)^2 + sum( pad(1,:) )^2; 
 
  endfor
 
  dft = sqrt(dft);
 
  dft = dft/(periods*stepsPerPeriod);
  
  temp = 1/30; % gib nen sinnvollen Namen
 
  envelop = dft(1,1) * abs(sinc((0:temp:freqSteps)*realDutycycle));
  if(realDutycycle > 0.5)
    envelop2 = (1-dft(1,1)) * abs(sinc((0:temp:freqSteps)*(1-realDutycycle)));
  endif
 
  dftSelected = [dft(1,1)];
  for selected=periods+1:periods:freqSteps+1
    dftSelected = [dftSelected, dft(1,selected)];
  endfor
  
  dft = dftSelected;

 
  plot([0, (periods+1:periods:freqSteps+1)/periods-1/periods], dft(1, :), "or;Spektallinien;", "linewidth", 1.5);     
  hold("on");

  h = stem([0, (periods+1:periods:freqSteps+1)/periods-1/periods], dft(1, :), "r");
  set(h, "linewidth", 1.5);
  
  if(exist("envelop2", "var") != 1)
      plot((0:temp:freqSteps), envelop, ";Einhuellende;", "linewidth", 1.5);     

  else
    plot((0:temp:freqSteps), envelop, ";Einhuellende;", "linewidth", 0.5);     
    plot((0:temp:freqSteps), envelop2, "g;Invertierte Einhuellende;", "linewidth", 1.5);     
  endif

  hold("off");

  axis ([0, 20, 0, 1.1]);
  axis("labelxy", "ticxy", "on");
  xlabel ("Harmonische der Grundfrequenz");
  set(gca(), "linewidth", 1.5);
  %axis ("ticx");
  
endfunction

%
%
%  M  A  I  N
%
%

printf("mik81 @ de.wikipedia.org\n\n");
printf("Spectrum of rectengular waveform\n\n");

begin_cputime = cputime();

frames = 10; % Teilung
frames = 256; % 2^n

frames = frames-1; % Zaunpfahl

Dimensions = "-S1600,900";

global stepsPerPeriod = 512; % 2^n wegen FFT
global periods = 8; % 2^4
steps = periods*stepsPerPeriod;
global timebase = 0:1:steps-1;
size(timebase)
% dutycycle = 0.05;

mkdir("./png");
axis("labelxy", "ticxy", "on");
 
for count=1:1:frames % Hack: vermeide Tastgrad 1.00

  close();

  countString = sprintf("%03i", count);
  dutycycle = count/(frames+1);
 
 
  printf("\nCalculating waveform: %i\n", count);

  subplot(2,3,1, "align");
  [square, realDutycycle] = waveform(dutycycle);
   
%  print(["./png/waveform", countString, ".png"], "-dpng");

  %
  % DFT
  %
  
  printf("Calculating DFT: %i\n", count);

  subplot(1,3,2:3, "align");
  [dft, envelop] = spektrum(square, realDutycycle);

 
  
 
  print(["./png/spectrum", countString, ".png"], "-dpng", Dimensions);
 
 
endfor 


printf("Total cpu time: %f seconds\n", cputime()-begin_cputime);
printf("Finished\n");


% EOF

Script edit

#! /bin/bash
 
 
echo "Script of mik81 @ de.wikipedia.org"

framerate=5

name="spectrum"

octave pwm.m

mkdir yuv

rm yuv/*

png2yuv -j ./png/$name%03d.png -f $framerate -I p -b 1 > ./yuv/out.yuv

rm ./$name.ogv

./ffmpeg2theora-0.29.linux32.bin ./yuv/out.yuv -F $framerate -v 9 -o ./$name.ogv;

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current13:38, 27 July 201413 s, 1,600 × 900 (2.39 MB)Mik81 (talk | contribs)User created page with UploadWizard

The following page uses this file:

Transcode status

Update transcode status
Format Bitrate Download Status Encode time
VP9 720P 431 kbps Completed 11:33, 21 October 2018 14 s
Streaming 720p (VP9) Not ready Unknown status
VP9 480P 220 kbps Completed 11:33, 21 October 2018 10 s
Streaming 480p (VP9) Not ready Unknown status
VP9 360P 123 kbps Completed 11:33, 21 October 2018 7.0 s
Streaming 360p (VP9) Not ready Unknown status
VP9 240P 63 kbps Completed 11:33, 21 October 2018 6.0 s
Streaming 240p (VP9) 63 kbps Completed 11:18, 17 December 2023 1.0 s
WebM 360P 394 kbps Completed 13:38, 27 July 2014 8.0 s
Streaming 144p (MJPEG) 439 kbps Completed 04:05, 9 November 2023 1.0 s

File usage on other wikis

The following other wikis use this file:

Metadata