{"id":189900,"date":"2025-02-10T17:34:05","date_gmt":"2025-02-10T17:34:05","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=189900"},"modified":"2025-02-10T17:34:08","modified_gmt":"2025-02-10T17:34:08","slug":"add-a-random-normal-distribution-noise-into-the-signal","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/02\/10\/add-a-random-normal-distribution-noise-into-the-signal\/","title":{"rendered":"Add a random normal distribution noise into the signal"},"content":{"rendered":"\n<p>Add a random normal distribution noise into the signal in Problem 5 using NumPy and plot the FFT amplitude spectrum. What do you see? The signal with noise will be shown in the following test case. Test case:<\/p>\n\n\n\n<p>In [2]: np.random.seed(10)<br>x_noise<br>np.random.normal(0, 2. size len(x))<br>plt.figure(figsize (8.6))<br>plt.plot(t, x_noise, &#8220;r&#8221;)<br>plt.ylabel(&#8220;Amplitude&#8221;)<br>plt.xlabel(&#8220;Time (s)&#8221;)<br>plt.show()<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/learnexams.com\/blog\/wp-content\/uploads\/2025\/02\/image-251.png\" alt=\"\" class=\"wp-image-189901\"\/><\/figure>\n\n\n\n<p>Generate two signals: signal 1 is a sine wave with 5 Hz, amplitude 3, and phase shift 3, and signal 2 is a sine wave with 2 Hz, amplitude 2, and phase shift \u22122. Plot the signal for 2 s. Test cases:<\/p>\n\n\n\n<p>In [1]: sampling rate<br>sr 100<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">sampling interval<\/h1>\n\n\n\n<p>ts-1.0\/sr<br>t np.arange(0.2.ts)<br>freq-5.<br>x-3-np.sin(2-np.pl-freq-t + 3)<br>freq 2<br>x+2+np.sin(2-np.pi freq-t2)<br>plt.figure(figsize (8.6))<br>plt.plot(t, x. &#8220;r&#8221;)<br>plt.ylabel(&#8220;Amplitude&#8221;)<br>plt.xlabel(&#8220;Time (s)&#8221;)<br>plt.show()<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/learnexams.com\/blog\/wp-content\/uploads\/2025\/02\/image-252.png\" alt=\"\" class=\"wp-image-189902\"\/><\/figure>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-6-color\"><strong>The Correct Answer and Explanation is :<\/strong><\/mark><\/p>\n\n\n\n<p>To analyze the effect of adding random noise to a signal and observe its impact on the frequency spectrum, we can follow these steps using Python&#8217;s NumPy and Matplotlib libraries.<\/p>\n\n\n\n<p><strong>1. Generate the Original Signal:<\/strong><\/p>\n\n\n\n<p>We&#8217;ll create two sine waves with specified frequencies, amplitudes, and phase shifts, then combine them to form the original signal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\nimport matplotlib.pyplot as plt\n\n# Sampling rate and time vector\nsr = 100  # Sampling rate in Hz\nt = np.arange(0, 2, 1\/sr)  # Time vector from 0 to 2 seconds\n\n# Signal 1: 5 Hz sine wave with amplitude 3 and phase shift 3 radians\nfreq1 = 5\nx1 = 3 * np.sin(2 * np.pi * freq1 * t + 3)\n\n# Signal 2: 2 Hz sine wave with amplitude 2 and phase shift -2 radians\nfreq2 = 2\nx2 = 2 * np.sin(2 * np.pi * freq2 * t - 2)\n\n# Combined signal\nx = x1 + x2\n\n# Plot the original signal\nplt.figure(figsize=(8, 6))\nplt.plot(t, x, 'r')\nplt.title('Original Signal')\nplt.xlabel('Time (s)')\nplt.ylabel('Amplitude')\nplt.grid(True)\nplt.show()<\/code><\/pre>\n\n\n\n<p><strong>2. Add Random Normal Distribution Noise:<\/strong><\/p>\n\n\n\n<p>Next, we&#8217;ll add random noise with a mean of 0 and a standard deviation of 2 to the original signal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Set random seed for reproducibility\nnp.random.seed(10)\n\n# Generate random noise\nnoise = np.random.normal(0, 2, len(x))\n\n# Signal with added noise\nx_noise = x + noise\n\n# Plot the noisy signal\nplt.figure(figsize=(8, 6))\nplt.plot(t, x_noise, 'r')\nplt.title('Signal with Added Noise')\nplt.xlabel('Time (s)')\nplt.ylabel('Amplitude')\nplt.grid(True)\nplt.show()<\/code><\/pre>\n\n\n\n<p><strong>3. Compute and Plot the FFT Amplitude Spectrum:<\/strong><\/p>\n\n\n\n<p>We&#8217;ll compute the Fast Fourier Transform (FFT) of the noisy signal to analyze its frequency components.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Compute the FFT of the noisy signal\nX = np.fft.fft(x_noise)\nN = len(X)\nfrequencies = np.fft.fftfreq(N, 1\/sr)\n\n# Compute the amplitude spectrum (magnitude of the FFT)\namplitude_spectrum = np.abs(X)&#91;:N\/\/2]\nfrequencies = frequencies&#91;:N\/\/2]\n\n# Plot the amplitude spectrum\nplt.figure(figsize=(8, 6))\nplt.plot(frequencies, amplitude_spectrum)\nplt.title('FFT Amplitude Spectrum of Noisy Signal')\nplt.xlabel('Frequency (Hz)')\nplt.ylabel('Amplitude')\nplt.grid(True)\nplt.show()<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Original Signal:<\/strong> The combined signal consists of two sine waves with frequencies of 5 Hz and 2 Hz, amplitudes of 3 and 2, and phase shifts of 3 and -2 radians, respectively.<\/li>\n\n\n\n<li><strong>Added Noise:<\/strong> Random noise with a mean of 0 and a standard deviation of 2 is added to the original signal. This noise introduces random fluctuations across all frequencies.<\/li>\n\n\n\n<li><strong>FFT Analysis:<\/strong> The FFT converts the time-domain signal into the frequency domain, allowing us to observe the frequency components present in the signal. The amplitude spectrum represents the magnitude of each frequency component.<\/li>\n\n\n\n<li><strong>Observations:<\/strong> In the amplitude spectrum of the noisy signal, the peaks corresponding to the original signal&#8217;s frequencies (5 Hz and 2 Hz) are still present but may be less pronounced due to the added noise. Additionally, there is a broad spectrum of frequencies introduced by the random noise, resulting in a more complex frequency profile.<\/li>\n<\/ul>\n\n\n\n<p>This analysis demonstrates how adding random noise affects the frequency characteristics of a signal, making it more challenging to identify specific frequency components.<\/p>\n\n\n\n<p>For a visual demonstration of denoising data using FFT in Python, you might find the following video helpful:<\/p>\n\n\n\n<p>\ue200video\ue202Denoising Data with FFT [Python]\ue202turn0search5\ue201<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Add a random normal distribution noise into the signal in Problem 5 using NumPy and plot the FFT amplitude spectrum. What do you see? The signal with noise will be shown in the following test case. Test case: In [2]: np.random.seed(10)x_noisenp.random.normal(0, 2. size len(x))plt.figure(figsize (8.6))plt.plot(t, x_noise, &#8220;r&#8221;)plt.ylabel(&#8220;Amplitude&#8221;)plt.xlabel(&#8220;Time (s)&#8221;)plt.show() Generate two signals: signal 1 is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-189900","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/189900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=189900"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/189900\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=189900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=189900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=189900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}