am modulation and demodulation matlab

Discussion in 'Wireless & RF Design' started by Jon_Snow, Feb 27, 2013.

Thread Status:
Not open for further replies.
  1. Jon_Snow

    Thread Starter New Member

    Jan 15, 2013
    16
    0
    Hey guys I'm trying to build a script to modulate and demodulate an am frequency.

    I have my information frequency, and carrier frequency. I modulate the signal and add noise. After I do that I run it through a halfwave rectifier and low pass and high filter. I then use a convolution to remove the noise. I then write the file to a wave file and I should be able to replay file. At the end of all this I should get something similar to the original frequency, but all I'm getting is static.

    Here's my code.


    close all;
    clear all;
    fs = 50000;
    t = [0:1/fs:5];

    f_cut_off1 = 10000;
    f_cut_off2 = 10;
    f = 2000; %input frequency
    fc = 940e3; %carrier frequency

    k = length(t)


    input_sig = (0.2)*cos(2 * pi * f * t); %input signal

    wavwrite(input_sig,fs,32,'input_sig');

    carrier_sig = (0.5)*cos( 2 * pi * fc * t); %carrier signal

    wavwrite(carrier_sig,fs,32,'carrier_sig')

    mod_sig = input_sig .* carrier_sig + carrier_sig; %modulated signal

    wavwrite(mod_sig,fs,32,'mod_sig')
    %interval to randonize noise
    noise = rand(1, k); %random nosie
    scale = 2;
    new_mod = mod_sig + noise; % mod signal + noise

    wavwrite(new_mod,fs,32,'new_mod')

    subplot(321), plot(t, mod_sig)
    subplot(322), plot(t, new_mod)

    %Apply HW Rectifier
    for i = 1:k
    if new_mod(i) <= 0
    x(i) = 0;
    else
    x(i) = new_mod(i);
    end
    end

    wavwrite(x,fs,32,'hw_rect')

    subplot(323), plot(t, x)
    rc1 = 1 / (2 * pi * f_cut_off1);
    rc2 = 1 / (2 * pi * f_cut_off2);
    %Apply Low Pass Filter
    num2 = [0 1];
    den2 = [rc1 1];
    subplot(324), bode(num2, den2)

    sys2 = tf(num2, den2);

    lpf = lsim(sys2, x, t);




    %Apply High Pass Filter

    num1 = [rc2 0];
    den1 = [rc2 1];

    subplot(325), bode(num1, den1)
    sys1 = tf(num1, den1);

    hpf = lsim(sys1, lpf, t);

    vout = hpf;

    g = 20;
    h = (1 / g) * ones(1, g);

    y = conv(h ,vout);



    wavwrite(y,fs,32,'vout')



    Any ideas? I'm completely stuck.

    Thanks!
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    One thread is enough.
     
  3. Jon_Snow

    Thread Starter New Member

    Jan 15, 2013
    16
    0
    Sorry I just didn't know which section this should go in.
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
Loading...
Thread Status:
Not open for further replies.