Unexpected MATLAB expression- can you help?

10 views (last 30 days)
I'm testing out the below code but I keep on getting this error: Error: File: program1.m Line: 1 Column: 8 Unexpected MATLAB expression. How do I fix this problem?
%(Image Enhancement)
image=imread('thumb.jpg');
function [final]=fftenhance(image,f) I = 255-double(image);
[w,h] = size(I);
%out = I;
w1=floor(w/32)*32; h1=floor(h/32)*32;
inner = zeros(w1,h1);
for i=1:32:w1
for j=1:32:h1
a=i+31;
b=j+31;
F=fft2( I(i:a,j:b) ); factor=abs(F).^f;
block = abs(ifft2(F.*factor)); larv=max(block(:));
if larv==0
larv=1; end;
block= block./larv;
inner(i:a,j:b) = block; end;
end;
final=inner*255;
final=histeq(uint8(final));

Accepted Answer

Stephen23
Stephen23 on 8 Apr 2015
Edited: Stephen23 on 9 Apr 2015
The first line of your code above has a commented-out line for the first line, so there must be something that you are not showing us which is causing this error message.
Nonetheless, here are a few tips for getting your code working:
  • Do not use the variable name image, as this is the name of a very useful inbuilt function image.
  • It is an error to write both a script and a function in one file, which is what you are trying to do here. The first code line image=imread('thumb.jpg');, without a preceding function declaration, tells MATLAB that this is a script. Then you follow this with a function declaration, thus making both a script and a function in one file. It is not possible to do both in one file: either the whole file must be one script (no functions) or the file can consist only of functions.
  • Do not use i and j as variable names, as these are the names of the inbuilt imaginary unit.
  5 Comments
rahul hanot
rahul hanot on 2 Nov 2016
fftehance fuction is having 2 argument one is image and wht is the 2nd arrugument f can anyone plz tellme the value of f

Sign in to comment.

More Answers (1)

Daniel Quiteque
Daniel Quiteque on 4 Jul 2023
Hello people!
Please, can some of you help me?
aim trying to code this script, but alwau=ys give me a wrong.
% Demonstration of BPSK tx/rx chain (waveform simulation)
clearvars ; clc; clear all
N=100000;%Number of symbols to transmit
EbN0dB = -4:2:10; % Eb/N0 range in dB for simulation
L=16;%oversampling factor,L=Tb/Ts(Tb=bit period,Ts=sampling period)
%if a carrier is used, use L = Fs/Fc, where Fs >> 2xFc
Fc=800; %carrier frequency
Fs=L*Fc;%sampling frequency
EbN0lin = 10.^(EbN0dB/10); %converting dB values to linear scale
BER = zeros(length(EbN0dB),1); %for SER values for each Eb/N0
ak = rand(N,1)>0.5; %random symbols from 0's and 1's
[s_bb,t]= bpsk_mod(ak,L); %BPSK modulation(waveform) - baseband
s = s_bb.*cos(2*pi*Fc*t/Fs); %with carrier
%Waveforms at the transmitter
subplot(2,2,1);plot(t,s_bb);%baseband wfm zoomed to first 10 bits
xlabel('t(s)');
ylabel('s_{bb}(t)-baseband');
xlim([0,10*L]);
subplot(2,2,2);plot(t,s); %transmitted wfm zoomed to first 10 bits
xlabel('t(s)'); ylabel('s(t)-with carrier');xlim([0,10*L]);
%signal constellation at transmitter
subplot(2,2,3);plot(real(s_bb),imag(s_bb),'o');
xlim([-1.5 1.5]); ylim([-1.5 1.5]);
for i=1:length(EbN0dB),
Eb=L*sum(abs(s).2)/length(s); %signal energy
N0= Eb/EbN0lin(i); %Find the noise spectral density
n = sqrt(N0/2)*randn(1,length(s));%computed noise
r = s + n;%received signal with noise
r_bb = r.*cos(2*pi*Fc*t/Fs);%recovered baseband signal
ak_cap = bpsk_demod(r_bb,L);%baseband correlation demodulator
BER(i) = sum(ak=ak_cap)/N;%Symbol Error Rate Computation
%Received signal waveform zoomed to first 10 bits
subplot(2,2,4);plot(t,r);%received signal (with noise)
xlabel('t(s)'); ylabel('r(t)');xlim([0,10*L]);
pause;%wait for keypress
end
theoreticalBER = 0.5*erfc(sqrt(EbN0lin));%Theoretical bit error rate
figure;semilogy(EbN0dB,BER,'k*'); %simulated BER
hold on;semilogy(EbN0dB,theoreticalBER,'r-');
xlabel('E_b/N_0 (dB)'); ylabel('Probability of Bit Error - P_b');
legend('Simulated', 'Theoretical');grid on;
title(['Probability of Bit Error for BPSK modulation']);
  1 Comment
Steven Lord
Steven Lord on 4 Jul 2023
Since this doesn't seem related to the original question, you should ask this as a separate question using the Ask link near the top of this page.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!