<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Simon chauveau</title>
    <description>The latest articles on DEV Community by Simon chauveau (@simon_chauveau_27459e6bb5).</description>
    <link>https://dev.to/simon_chauveau_27459e6bb5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3488805%2F6688704e-442c-430e-88a4-0f17253ed44b.png</url>
      <title>DEV Community: Simon chauveau</title>
      <link>https://dev.to/simon_chauveau_27459e6bb5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simon_chauveau_27459e6bb5"/>
    <language>en</language>
    <item>
      <title>From Analog to Digital: Signal Simulation</title>
      <dc:creator>Simon chauveau</dc:creator>
      <pubDate>Tue, 09 Sep 2025 09:07:08 +0000</pubDate>
      <link>https://dev.to/simon_chauveau_27459e6bb5/from-analog-to-digital-signal-simulation-1hm0</link>
      <guid>https://dev.to/simon_chauveau_27459e6bb5/from-analog-to-digital-signal-simulation-1hm0</guid>
      <description>&lt;p&gt;Ever wondered how sound—like your voice or music—is transformed into digital data that can be stored on a computer or phone? In this post, we’ll explore how it works using a simple MATLAB simulation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Simple simulation
&lt;/h2&gt;




&lt;p&gt;&lt;strong&gt;Step 1 : Creation of Analog Signal&lt;/strong&gt;&lt;br&gt;
First, we create a sine wave (like a pure tone) at 100 Hz:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t = 0:0.0001:0.01;       % very fine step (continuous-like time)
f = 100;                 % frequency = 100 Hz
x_analog = sin(2*pi*f*t);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let’s visualize it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;figure;
plot(t, x_analog, 'LineWidth', 1.5);
title('Analog Signal (Sine Wave)');
xlabel('Time (s)'); ylabel('Amplitude');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffam2ab85jhf5ryt1o8mi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffam2ab85jhf5ryt1o8mi.png" alt="Analog Signal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This waveform represents our original sound.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Step 2 : Sampling the Signal&lt;/strong&gt;&lt;br&gt;
Sampling is like taking snapshots of the signal at regular intervals. The higher the sampling frequency, the better the quality.&lt;/p&gt;

&lt;p&gt;I tested three sampling frequencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;150 Hz : Too slow&lt;/li&gt;
&lt;li&gt;200 Hz : Just enough (Nyquist rate)&lt;/li&gt;
&lt;li&gt;1000 Hz : Good&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this example, we use 1000 Hz:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fs = 1000;               % Sampling frequency = 1 kHz
Ts = 1/Fs;               % Sampling period
n = 0:Ts:0.01;           % Discrete sample points
x_sampled = sin(2*pi*f*n);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Visualizing the sampled signal:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;figure;
stem(n, x_sampled, 'filled');
title('Sampled Signal');
xlabel('Time (s)'); ylabel('Amplitude');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9n099hxsgequpp89etu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9n099hxsgequpp89etu6.png" alt="Signal Sample"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Step 3 : Quantization&lt;/strong&gt; &lt;br&gt;
Quantization rounds each sample to the nearest level. More levels = better detail.&lt;/p&gt;

&lt;p&gt;I tested:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;3 bits : 8 levels&lt;/li&gt;
&lt;li&gt;4 bits : 16 levels&lt;/li&gt;
&lt;li&gt;6 bits : 64 levels&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s the 4-bit version:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bits = 4;                           % Number of bits
levels = 2^bits;                    % Quantization levels
x_min = min(x_sampled);
x_max = max(x_sampled);
q_step = (x_max - x_min)/levels;    % Step size

x_index = round((x_sampled - x_min)/q_step); % Map samples to indices
x_quantized = x_index*q_step + x_min;        % Map back to amplitude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Visualizing the quantized signal:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;figure;
stem(n, x_quantized, 'filled');
title(['Quantized Signal (' num2str(bits) '-bit)']);
xlabel('Time (s)'); ylabel('Amplitude');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyn8tmgdqe1c81i3v8l9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyn8tmgdqe1c81i3v8l9k.png" alt="Signal quantized"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Step 4 : Encoding (Binary)&lt;/strong&gt;&lt;br&gt;
Now we convert each quantized value into binary:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;binary_codes = dec2bin(x_index, bits); % Convert indices to binary words
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To display the first 10 samples:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;disp('--- First 10 encoded samples ---');
disp(binary_codes(1:10));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;strong&gt;Step 5 : Digital Stream&lt;/strong&gt;&lt;br&gt;
Finally, we combine all binary codes into one bitstream:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bitstream = reshape(binary_codes.',1,[]); % Concatenate into one string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Display the first 40 bits:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;disp('--- First 40 bits of the stream ---');
disp(bitstream(1:40));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fainqy2r3q3lck9zoacx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fainqy2r3q3lck9zoacx2.png" alt="Text Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This bitstream is what computers and phones use to store and process sound.&lt;/p&gt;


&lt;h2&gt;
  
  
  GitHub
&lt;/h2&gt;

&lt;p&gt;You can find the full MATLAB code and result images on my GitHub repository:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/CSimon-278" rel="noopener noreferrer"&gt;
        CSimon-278
      &lt;/a&gt; / &lt;a href="https://github.com/CSimon-278/MathAlgo-Assinment1" rel="noopener noreferrer"&gt;
        MathAlgo-Assinment1
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;🎧 Analog to Digital Signal Simulation in MATLAB&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;This project demonstrates how an analog signal (like sound) is transformed into a digital signal that can be stored and processed by computers and phones. Using MATLAB, we simulate each step of the process: &lt;strong&gt;signal creation&lt;/strong&gt;, &lt;strong&gt;sampling&lt;/strong&gt;, &lt;strong&gt;quantization&lt;/strong&gt;, &lt;strong&gt;binary encoding&lt;/strong&gt;, and &lt;strong&gt;bitstream generation&lt;/strong&gt;.&lt;/p&gt;




&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;📌 What You'll Learn&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;How analog signals are represented in MATLAB&lt;/li&gt;
&lt;li&gt;The importance of sampling frequency (Nyquist theorem)&lt;/li&gt;
&lt;li&gt;How quantization affects signal quality&lt;/li&gt;
&lt;li&gt;How binary encoding creates a digital bitstream&lt;/li&gt;
&lt;li&gt;Visual comparisons of signal fidelity at different settings&lt;/li&gt;
&lt;/ul&gt;




&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;🧪 Simulation Steps&lt;/h2&gt;
&lt;/div&gt;


&lt;ol&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Analog Signal Creation&lt;/strong&gt;&lt;br&gt;
Generate a 100 Hz sine wave to represent a pure tone.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sampling&lt;/strong&gt;&lt;br&gt;
Sample the signal at different frequencies (150 Hz, 200 Hz, 1000 Hz) to observe aliasing and clarity.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Quantization&lt;/strong&gt;&lt;br&gt;
Apply different bit depths (3, 4, 6 bits) to see how resolution affects signal accuracy.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Binary Encoding&lt;/strong&gt;&lt;br&gt;
Convert quantized values…&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/CSimon-278/MathAlgo-Assinment1" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>matlab</category>
      <category>github</category>
      <category>simulation</category>
    </item>
  </channel>
</rss>
