Skip to content

Instantly share code, notes, and snippets.

@gorbatschow
gorbatschow / unit_spectrum_et4.m
Created December 2, 2021 22:34
Matlab etude demonstrates window function effect on multi-tone signal
% Spectral analysis etudes
% This etude demonstrates window function effect on multi-tone signal
% - Try to change wtype variable to see the effect
% code by [email protected]
clear
% PARAMETERS
% -------------------------------------------------------------------------
@gorbatschow
gorbatschow / unit_spectrum_et3.m
Created December 2, 2021 22:33
Matlab etude demonstrates window function effect on single-tone signal
% Spectral analysis etudes
% This etude demonstrates window function effect on single-tone signal
% code by [email protected]
clear
% PARAMETERS
% -------------------------------------------------------------------------
% Sample rate (Hz)
@gorbatschow
gorbatschow / unit_spectrum_et2.m
Created December 2, 2021 22:32
Matlab etude demonstrates spectrum amplitude error when frequency is not a product of DF by integer
% Spectral analysis etudes
% This etude demonstrates spectrum amplitude error when frequency is not a
% product of df by integer
% - Try to change f1 variable to see wrong amplitude on spectrum
% - Try to change NFFT variable to see zero-padding effect.
% code by [email protected]
clear
% PARAMETERS
@gorbatschow
gorbatschow / unit_spectrum_et1.m
Created December 2, 2021 22:31
MATLAB etude demonstrates spectrum for multitone signal with different amplitudes
% Spectral analysis etudes
% This etude demonstrates spectrum for multitone signal with different
% amplitudes.
% code by [email protected]
clear
% PARAMETERS
% -------------------------------------------------------------------------
@gorbatschow
gorbatschow / RuntimeImage.h
Created November 18, 2021 20:17
ImGui + GLFW An example of runtime image generation
// An example of runtime image generation using Dear ImGui & GLFW
// c++ code by [email protected]
// Usage:
// RuntimeImage m_image;
// m_image.setSize(50, 50);
// m_image.setColor(255, 0, 255, 255);
// m_image.updateTexture();
// ImGui::Image((void*)(intptr_t)m_image.textureId(), m_image.imageSize());
#pragma once
@gorbatschow
gorbatschow / InterpolateLin.h
Last active November 8, 2021 16:57
Linear interpolation C++
// Linear interpolation procedure
// c++ code by [email protected]
// SEE
// http://www.cplusplus.com/forum/general/216928/
template<typename T>
inline T InterpolateLin(const T* data_x, const T* data_y, size_t data_length, T x, size_t& i)
{
if (x >= data_x[data_length - 2]) i = data_length - 2;
else while (x > data_x[i + 1]) i++;
@gorbatschow
gorbatschow / DownsampleLTTB.h
Last active October 30, 2024 14:38
Largest-Triangle-Three-Buckets Downsampling C++
// Largest-Triangle-Three-Buckets algorithm
// SEE
// https://github.com/sveinn-steinarsson/flot-downsample
// https://www.base.is/flot/
// c++ port by [email protected]
template<typename T>
inline void DownsampleLTTB(const T* data_x, const T* data_y, size_t data_length,
T* sampled_x, T* sampled_y, size_t threshold)
{