Search This Blog

Showing posts with label frequency. Show all posts
Showing posts with label frequency. Show all posts

Monday, January 21, 2013

Amplitude spectrum of a signal using Fourier transform

signal တစ်ခုရဲ့ amplitude spectrum ကို Fourier transform သုံးပြီး ရှာတဲ့ MATLAB ဖန်ရှင်လေး တစ်ခု ရေးကြည့်ထားပါတယ်။ အဲဒီ ဖန်ရှင်ကို နမူနာ သုံးတဲ့ ပုံစံ ရယ်၊ ဖန်ရှင် ရေးထားတဲ့ ကုဒ်တွေ ရယ်ကို အောက်မှာ ဖော်ပြထားပါတယ်။ MATLAB မှာ ပါတဲ့ ဖန်ရှင် fft ကို သုံးတဲ့ ဟာ ကို လည်း နောက်ထပ် နမူနာ တစ်ခု ပြထားပါတယ်။ ဒီဟာလေးတွေက amplitude spectrum တို့၊ power spectrum တို့ ရှာချင်တဲ့ သူတွေ အတွက် အသုံးဝင်မယ်လို့ မျှော်လင့်ပါတယ်။
%Example MATLAB code to test function FX
Fs=100;
t=(0:1/Fs:1-1/Fs)';
x=2*cos(2*pi*5*t)+sin(2*pi*10*t);
[f a]=FX(x,Fs);
plot(f,a);

function [f a]=FX(x,fs)
%Calculates amplitude spectrum of a signal x using Fourier transform
%[f a]=FX(x,fs)
%Input: x=signal, fs = sampling rate
%Output: f = frequency axis, a = amplitude spectrum
%File name: FX.m
%Author: Yan Naing Aye
%Website: http://cool-emerald.blogspot.sg/

dT = 1/fs; 
N=length(x);
dF=1/(N*dT);
NF=fs/2;%Nyquist Freq
%You can always limit freq range for faster performance
%NF=20;
t=(0:dT:(N-1)*dT)';
f=(0:dF:NF)';
a=f;%initialize a
a(1)=mean(x);
for i=2 : length(a)
    b=(2*mean(x.*cos(2*pi*dF*(i-1)*t)));
    c=(2*mean(x.*sin(2*pi*dF*(i-1)*t)));
    a(i)=sqrt(b^2+c^2);
end

%MATLAB program to calculates amplitude spectrum of a signal x using fft
%Author: Yan Naing Aye
%Website: http://cool-emerald.blogspot.sg/

Fs=100;
t=(0:1/Fs:1-1/Fs)';
x=2*cos(2*pi*5*t)+sin(2*pi*10*t);
L=length(x);

A=2*abs(fft(x)/L);
A=A(1:Fs/2+1);
f = Fs/2*linspace(0,1,Fs/2+1);
plot(f,A);

Tuesday, May 25, 2010

Astable Multivibrator using Op-amp

မိတ်ဆွေ တစ်ယောက်က op-amp circuit တစ်ခုရဲ့ oscillation frequency ကို တွက်ထုတ်ဖို့ အကူ အညီ တောင်းလာ ပါတယ်။ တိုင်းကြည့်လို့ ရတဲ့ frequency က ၁၀၉ kHz ရှိတယ်လို့ ဆိုပါတယ်။ သူက ထွက်လာတဲ့ oscillation frequency နဲ့ သုံးထားတဲ့ passive component တွေရဲ့ ဆက်သွယ်မှု ကို တွက်ထုတ် ချင်တာ ပါ။ ဒီလို analog circuits တွေကို မတွေ့ ဖြစ်တာ တော်တော် ကြာနေ ပေမယ့် ကြည့်ပေးမယ် လို့ သဘောတူ လိုက်ပါတယ်။ ဒါနဲ့ သူက ဆားကစ် ပတ်လမ်း ပုံကို ဖုန်းနဲ့ ဓာတ်ပုံရိုက် ပြီး MMS နဲ့ ပို့ လိုက်ပါတယ်။ ကြည့် လိုက်တော့ သူ့ရဲ့ တည်ဆောက်ပုံ က ရိုးရှင်းပြီး တွေ့ နေကြ ပုံစံ မျိုး ဖြစ်နေတာနဲ့ frequency ကို တွက်ကြည့် ပြီး ဖုန်းနဲ့ ဓာတ်ပုံ ပြန်ရိုက်၊ အောက်က ပုံတွေကို သူဆီကို MMS နဲ့ ပြန် ပို့ လိုက်ပါတယ်။