{"id":2046,"date":"2024-04-09T20:06:42","date_gmt":"2024-04-09T20:06:42","guid":{"rendered":"https:\/\/enjoypowers.com\/?p=2046"},"modified":"2026-05-25T11:53:55","modified_gmt":"2026-05-25T11:53:55","slug":"python-demonstrates-working-principle-ahf","status":"publish","type":"post","link":"http:\/\/enjoypowers.com\/vi\/python-demonstrates-working-principle-ahf\/","title":{"rendered":"\u0110o\u1ea1n m\u00e3 Python minh h\u1ecda nguy\u00ean l\u00fd ho\u1ea1t \u0111\u1ed9ng c\u1ee7a b\u1ed9 l\u1ecdc h\u00e0i ch\u1ee7 \u0111\u1ed9ng (AHF)."},"content":{"rendered":"<h3>Understanding Active Harmonic Filter (AHF) Operation<\/h3>\n<p>The Python code demonstrates the working principle of an <a href=\"http:\/\/enjoypowers.com\/power-quality\/sinl-pro-series\/\">Active Harmonic Filter<\/a> (AHF), a device used to mitigate harmonic distortions in electrical systems. By analyzing current waveforms and frequency spectra, the code showcases the AHF&#8217;s ability to reduce harmonic content and improve power quality.<\/p>\n<h3>Code Overview:<\/h3>\n<ul>\n<li>The code reads harmonic parameters from a text file and generates harmonic waveforms.<\/li>\n<li>It calculates Total Harmonic Distortion (THD) and plots current waveforms, frequency spectra, and AHF output.<\/li>\n<li>The plots illustrate the reduction of harmonic distortions by the AHF, ensuring smoother current waveforms and improved system performance.<\/li>\n<\/ul>\n<h3>Benefits of AHF:<\/h3>\n<ul>\n<li>Reduces harmonic distortions in electrical systems.<\/li>\n<li>Improves power quality and system reliability.<\/li>\n<li>Enhances the efficiency of sensitive equipment.<\/li>\n<\/ul>\n<div style=\"border: 2px solid #000; padding: 20px; background-color: #f0f0f0;\">\n<h3>Active Harmonic Filter (AHF) Python code:<\/h3>\n<div>\n<pre>import numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# Read harmonic parameters from a text file\r\ndef read_harmonic_parameters(file_path):\r\n    try:\r\n        with open(file_path, 'r') as file:\r\n            lines = file.readlines()\r\n            harmonic_parameters = [list(map(float, line.strip().split())) for line in lines]\r\n        return harmonic_parameters\r\n    except Exception as e:\r\n        print(f\"Error reading harmonic parameters: {e}\")\r\n        return None\r\n\r\n# Read harmonic parameters\r\nfile_path = 'harmonic_parameters.txt'\r\nharmonic_parameters = read_harmonic_parameters(file_path)\r\n\r\nif harmonic_parameters:\r\n    # Parse harmonic parameters\r\n    harmonic_multipliers, harmonic_amplitudes = zip(*harmonic_parameters)\r\n\r\n    # Initial current parameters\r\n    fundamental_frequency = 50\r\n    display_time = 0.05\r\n    sampling_frequency = 10000\r\n    sampling_points = int(sampling_frequency * display_time)\r\n    time = np.linspace(0, display_time, sampling_points, endpoint=False)\r\n    fundamental_amplitude = 100\r\n\r\n    # Convert harmonic multipliers to actual frequency values\r\n    harmonic_frequencies = np.array(harmonic_multipliers) * fundamental_frequency\r\n\r\n    # Generate current waveforms for fundamental and harmonics\r\n    fundamental_waveform = fundamental_amplitude * np.sin(2 * np.pi * fundamental_frequency * time)\r\n    harmonic_waveforms = [amp * np.sin(2 * np.pi * freq * time) for freq, amp in zip(harmonic_frequencies, harmonic_amplitudes)]\r\n\r\n    # Total current waveform is the sum of fundamental and harmonics\r\n    total_current_waveform = fundamental_waveform + np.sum(harmonic_waveforms, axis=0)\r\n\r\n    # Calculate THD\r\n    fundamental_rms = np.sqrt(np.mean(fundamental_waveform**2))\r\n    harmonic_rms_values = [np.sqrt(np.mean(harmonic_waveform**2)) for harmonic_waveform in harmonic_waveforms]\r\n    thd_percent = (np.sqrt(np.sum(np.array(harmonic_rms_values)**2)) \/ fundamental_rms) * 100\r\n\r\n    # Calculate the sum of harmonic currents excluding the fundamental\r\n    harmonic_current_sum = np.sum(harmonic_waveforms, axis=0)\r\n\r\n    # Calculate the negative of harmonic current sum\r\n    negative_harmonic_current_sum = -harmonic_current_sum\r\n\r\n    # Plot current waveforms and annotate THDi value\r\n    plt.subplot(4, 1, 1)\r\n    plt.plot(time, total_current_waveform, label='Total Current')\r\n    # plt.plot(time, fundamental_waveform, label='Fundamental')\r\n\r\n    plt.title(f'Current Waveforms (THD={thd_percent:.2f}%)')\r\n    plt.xlabel('Time (s)')\r\n    plt.ylabel('Amplitude')\r\n    plt.legend()\r\n    plt.grid(True)\r\n\r\n    # Plot fundamental and harmonic currents in the second subplot\r\n    plt.subplot(4, 1, 2)\r\n    plt.plot(time, fundamental_waveform, label='Fundamental')\r\n    plt.plot(time, harmonic_current_sum, label='Harmonic Current Sum (Excluding Fundamental)')\r\n\r\n    plt.title('Fundamental and Harmonic Currents')\r\n    plt.xlabel('Time (s)')\r\n    plt.ylabel('Amplitude')\r\n    plt.legend()\r\n    plt.grid(True)\r\n\r\n    # Plot a bar chart of amplitudes within the frequency range\r\n    plt.subplot(4, 1, 3)\r\n    plt.bar(harmonic_frequencies, harmonic_amplitudes, width=8, align='center', label='Harmonics')\r\n    plt.bar(fundamental_frequency, fundamental_amplitude, width=8, align='center', color='red', label='Fundamental')\r\n\r\n    plt.title('Frequency Spectrum')\r\n    plt.xlabel('Frequency (Hz)')\r\n    plt.ylabel('Amplitude (A)')\r\n    plt.legend()\r\n    plt.grid(True)\r\n\r\n    # Plot the negative of harmonic current sum\r\n    plt.subplot(4, 1, 4)\r\n    plt.plot(time, negative_harmonic_current_sum, label='Negative Harmonic Current Sum')\r\n\r\n    plt.title('Active Harmonic Filter Output Current')\r\n    plt.xlabel('Time (s)')\r\n    plt.ylabel('Amplitude')\r\n    plt.legend()\r\n    plt.grid(True)\r\n\r\n    plt.tight_layout()\r\n    plt.show()\r\nelse:\r\n    print(\"Failed to read harmonic parameters from the file.\")<\/pre>\n<\/div>\n<\/div>\n<h3>Python Running Result<\/h3>\n<figure id=\"attachment_2049\" aria-describedby=\"caption-attachment-2049\" style=\"width: 601px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-2049\" src=\"http:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF.png\" alt=\"Python demonstrates the working principle of an Active Harmonic Filter (AHF)\" width=\"601\" height=\"298\" srcset=\"https:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF.png 2338w, https:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF-768x381.png 768w, https:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF-1536x762.png 1536w, https:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF-2048x1016.png 2048w, https:\/\/enjoypowers.com\/wp-content\/uploads\/2024\/04\/Python-demonstrates-the-working-principle-of-an-Active-Harmonic-Filter-AHF-600x298.png 600w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><figcaption id=\"caption-attachment-2049\" class=\"wp-caption-text\">Python demonstrates the working principle of an Active Harmonic Filter (AHF)<\/figcaption><\/figure>\n<h3>Python demonstration of\u00a0 harmonics video<\/h3>\n<div id=\"top-row\" class=\"style-scope ytd-watch-metadata\">\n<div id=\"owner\" class=\"item style-scope ytd-watch-metadata\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Understanding Active Harmonic Filter (AHF) Operation The Python code demonstrates the working principle of an Active Harmonic Filter (AHF), a device used to mitigate harmonic distortions in electrical systems. By analyzing current waveforms and frequency spectra, the code showcases the AHF&#8217;s ability to reduce harmonic content and improve power quality. Code Overview: The code reads [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[322],"tags":[],"class_list":["post-2046","post","type-post","status-publish","format-standard","hentry","category-powerquality"],"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/posts\/2046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/comments?post=2046"}],"version-history":[{"count":9,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/posts\/2046\/revisions"}],"predecessor-version":[{"id":7580,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/posts\/2046\/revisions\/7580"}],"wp:attachment":[{"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/media?parent=2046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/categories?post=2046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoypowers.com\/vi\/wp-json\/wp\/v2\/tags?post=2046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}