Skip to content

Instantly share code, notes, and snippets.

Martin Vincent Bloedorn MartinBloedorn

Block or report user

Report or block MartinBloedorn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View thdf.m
function [thd, p0, l0] = thdf( P1, f, varargin )
%thdf Computes the total harmonic distortion to the fundamental.
% Fundamental is the first harmonic peak that's larger than 2% than
% the largest harmonic in the supplied frequency spectrum.
%
% thd = thdf( P1, f )
%
% P1 Single-sided amplitude spectrum of the signal.
% f Frequency span of P1.
% thd Total harmonic distortion.
View spwm.m
function [ y, r, c ] = spwm( f1, fc, varargin )
%SPWM Generates sine-wave modulated bipolar PWM.
% Will produce the closest possible to a single period of f1.
% [ y, t, c ] = spwm( f1, fc, varargin )
%
% f1 Base harmonic frequency.
% fc Carrier frequency.
% 'NSamples' [100] Samples per 1/fc period.
% 'Method' ['left'] 'left', 'right' or 'center'.
% 'ModIndex' [1] Modulation index.
View sfft.m
function [ P1, f ] = ssfft( X, Fs )
%ssfft Computes the single-sided amplitude spectrum of a signal.
% https://www.mathworks.com/help/matlab/ref/fft.html
% [ P1, f ] = ssfft( X, Fs )
%
% X Input signal.
% Fs Sampling frequency.
% P1 Single-sided Amplitude Spectrum.
% f Frequency range.
%
View knight.c
#include <stdio.h>
#include <stdlib.h>
int sgn(int x) {
return (x >= 0 ? 1 : -1);
}
int main(int argc, char * argv[]) {
if(argc != 3) {
printf("ERROR: Supply X and Y target position!\n");
You can’t perform that action at this time.