Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Simple Scrambler on MatLab.

  1. Jun 13, 2010 #1

    I'm trying to build a simple scrambler using matlab, as show on the picture below:

    [PLAIN]http://img94.imageshack.us/img94/1381/blocks.jpg [Broken]

    Its not in english, but I think anyone can understand it. The first filter is a high pass filter and the second is a low pass.
    The idea is simple: if the input is m(t) the output is y(t), and if you input y(t) you recover m(t) as the output.

    What I have tried to do is this (ill past the matlab code below): Import an wave file into matlab, multiply it by cos(2pifct), do a Fourier transform, filter it by "zeroing" the high frequency elements, do an Inverse Fourrier transform, multiply it by cos[2pi(fc+W)t], do a Fourrier transform, aply the second filter and finally do an Inverse Fourrier transform.

    Here are the first lines on my code. Its already broken at this point because S1 is nothing but zeroes.

    %--- Reads the wave and adds the channels, so I end up mono
    [M1 FS NBITS] = wavread('3333.wav');
    m= M1(:,1) + M1(:,2);
    kk=size(m) ; k=kk(1);

    t=(0:(k-1))/FS; % A vector with the instants of time when there
    % was sampling

    fc = 500000; %-- I chose fc 500 KHz.
    A = 1; %-- I chose A 1.

    %-- Multiply m(t) by cos(2pifct), as show on the block diagram.
    s1 = m'.*(1*cos(2*pi*fc*t));

    %-- S1 is the Fourrier transform of s1.
    S1= fft(s1);

    %--- Calculates the size of s1
    tt = size(s1); t=tt(2);

    w=[(-t/2)+1 : t/2]; %-- Auxiliar vetor, to help calculate Freqs

    Freqs = w' * (FS/t); % Each element of Freqs contains a frequency
    % corresponding to an elemento of S1, that is,
    % the signal has amplitude S1(i) with
    % frequency Freqs(i) for any i.

    % Finds frequencies lower than fc and greater than -fc
    Freqs1 = find( Freqs >= -fc & Freqs <=fc );

    %Filters the high frequencies

    s2 = ifft(S1); % Inverse Fourier transform of S1

    %--- Segundo multiplicador, A.cos[2pi(fc+W)t]
    s3 = s2'.*(1*cos(2*pi*(fc + t/2)*t));

    Ill stop here because it doesnt matter anyway, the problem is earlier on.
    Thanks for the help, any suggestions are appreciated, even if it means ill have to throw this code away and start from scratch.
    Last edited by a moderator: May 4, 2017
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted